Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82960 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14127 invoked from network); 17 Feb 2015 14:06:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Feb 2015 14:06:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.182 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.212.182 mail-wi0-f182.google.com Received: from [209.85.212.182] ([209.85.212.182:45638] helo=mail-wi0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 71/05-19463-8DA43E45 for ; Tue, 17 Feb 2015 09:06:17 -0500 Received: by mail-wi0-f182.google.com with SMTP id l15so32929365wiw.3 for ; Tue, 17 Feb 2015 06:06:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=+b4n/Ibl1Gk9bOqCJ11FbiiBPkyrwHICDmgnE487xLw=; b=KA3VwfJG1kQIvNKt7XQBNeQirqrMd50UTEi+Oll4bDm2hoYPE7uz53/eaEDHxt6CpP 4gNA7DhjVnlyowzr+tYkodu0in8NxHkheBXAER2qSNrGU25Nz9mgyVfXh4x/shCqyUe2 BR3j2gygSkU4oTdKeBnnNiXUiCnReArUdGTa9VkpjUz2Z7IRjq3GFY96cZQZ5RVEbE5y F0WcSebEaqk1IiKvpwzbFMod5kKTg6AViWWoWEg/IA5f+auvG+IQ+ahHDFVS20KN4G2O EtnNTkJ2ed3AW7fNSL3yHR86MI6iZcYgsT7mpyhWKFzg9oeMq80P/aTOvAZSx3T66D5n biyA== MIME-Version: 1.0 X-Received: by 10.194.71.175 with SMTP id w15mr55673411wju.16.1424181972566; Tue, 17 Feb 2015 06:06:12 -0800 (PST) Received: by 10.27.10.168 with HTTP; Tue, 17 Feb 2015 06:06:12 -0800 (PST) In-Reply-To: References: Date: Tue, 17 Feb 2015 15:06:12 +0100 Message-ID: To: Dmitry Stogov Cc: Benjamin Eberlei , PHP Internals , Guilherme Blanco , Pierrick CHARRON , Alexander Lisachenko , Pierre Joye , Zeev Suraski , Andi Gutmans , Joe Watkins , Yasuo Ohgaki , Sebastian Bergmann , Stanislav Malyshev , Rasmus Lerdorf Content-Type: multipart/alternative; boundary=047d7bfcf00092091a050f493424 Subject: Re: [PHP-DEV] Annotations in PHP7 From: nikita.ppv@gmail.com (Nikita Popov) --047d7bfcf00092091a050f493424 Content-Type: text/plain; charset=UTF-8 On Mon, Feb 16, 2015 at 10:15 PM, Dmitry Stogov wrote: > Hi Nikita, > > On Tue, Feb 17, 2015 at 12:07 AM, Nikita Popov > wrote: > >> On Mon, Feb 16, 2015 at 10:02 PM, Dmitry Stogov wrote: >> >>> >>> >>> On Mon, Feb 16, 2015 at 11:05 PM, Benjamin Eberlei >>> wrote: >>> >>>> >>>> >>>> On Mon, Feb 16, 2015 at 12:07 PM, Dmitry Stogov >>>> wrote: >>>> >>>>> hi, >>>>> >>>>> During discussion of different ways of implementing "Design by >>>>> Contract" we >>>>> got an idea of using annotations. >>>>> >>>>> BTW: annotations are useful by their own and may be used for different >>>>> purposes. Support for annotations was proposed long time ago: >>>>> >>>>> https://wiki.php.net/rfc/annotations >>>>> https://wiki.php.net/rfc/annotations-in-docblock >>>>> https://wiki.php.net/rfc/reflection_doccomment_annotations >>>>> >>>>> HHVM already implemented similar concept >>>>> >>>>> http://docs.hhvm.com/manual/en/hack.attributes.php >>>>> >>>>> I made a quick and dirty PoC that shows how we may implement >>>>> annotations in >>>>> PHP7 and how powerful they may be : >>>>> https://gist.github.com/dstogov/dbf2a8f46e43719bd2c2 >>>> >>>> >>>> How about not exposing the AST, and then the userland can pass context >>>> to a method $reflection->getAnnotation($name, $context); >>>> >>>> https://gist.github.com/beberlei/0dc36d4412b8e3454912 >>>> >>>> That way AST is not exposed to userland. >>>> >>> >>> Your example handles just particular use-case. >>> I would like to provide a general solution. >>> >>> Thanks. Dmitry. >>> >> >> Could you provide some more info on how you would imagine this to be used >> for the DbC use case? As far as I see, this would require injecting code >> into the method body based on the annotations. Does that mean that >> annotations handlers will get the chance to modify the AST of the method >> itself during compilation? Or how is this supposed to be realized? >> > > In general, it must be possible to plug into compilation process using > zend_ast_process() callback and modify function AST, inserting constraints > validation in proper places. > But for now, I'm thinking only about metadata syntax and representation. I > just showed, how it can be used to represent DbC constraints. > I don't think we need user-level interface to modify AST. > To make sure I got it right: The AST-based annotations are only there to allow handling by PHP extensions (or the engine itself), while evaluated annotations are there for use by userland code? Nikita --047d7bfcf00092091a050f493424--