Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82979 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81718 invoked from network); 17 Feb 2015 16:25:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Feb 2015 16:25:26 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.173 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.173 mail-vc0-f173.google.com Received: from [209.85.220.173] ([209.85.220.173:48904] helo=mail-vc0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CC/A2-19463-57B63E45 for ; Tue, 17 Feb 2015 11:25:26 -0500 Received: by mail-vc0-f173.google.com with SMTP id hy4so12952775vcb.4 for ; Tue, 17 Feb 2015 08:25:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=/gOpo48I45n4zY4yduwDrAm/RqC6sZ2v7mq/QklTXIo=; b=gkYcJXn5MU4Fz+i673rwVsKPhPn38mRYGGVRxVZ749fOukHnaGChKmT0/Oxxbw1miO 8BOCHOTZGV1P6emEboA1tvXbo41V6mALv6SSoWw3Puck8DvCdkaXiWmU7ijTFQk3eUZw 0bW2INp0JDuKc0diEoe5vw/+WAMf6fO1d27yEKn4sb/gqLqlxa0eCcnzk9CZIVGVvQC5 3PLPUojo5yZ0Zi9iMnjEaRxuy5/CCRIhbq03m8JcDcPnyPRHTBN0iNl9b5OZhWtLZANH UnKfuk5oZw2dobRik/u0XBOHPPNW7bpLOnaBEL5rruTBnVKnBfLUEH2xBVIqDORofkqR iofw== X-Gm-Message-State: ALoCoQltx767nvP37002IS71n0CUX8aQr5x8AbdUAeALpwW2pPMn3a884wFrP1GmwYaXpAyvv2XeBNxGkEQNuCj13Ilf6DcqQfu5tpI/tW9H25pgamisXwG2OE5SFhpURTdVObpW8xvp4VWTzQjPuOW4QTEHHlANjA== MIME-Version: 1.0 X-Received: by 10.52.103.75 with SMTP id fu11mr16356844vdb.5.1424190322611; Tue, 17 Feb 2015 08:25:22 -0800 (PST) Received: by 10.52.74.73 with HTTP; Tue, 17 Feb 2015 08:25:22 -0800 (PST) In-Reply-To: References: Date: Tue, 17 Feb 2015 20:25:22 +0400 Message-ID: To: Nikita Popov 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=047d7b86d99045af20050f4b2654 Subject: Re: [PHP-DEV] Annotations in PHP7 From: dmitry@zend.com (Dmitry Stogov) --047d7b86d99045af20050f4b2654 Content-Type: text/plain; charset=UTF-8 On Tue, Feb 17, 2015 at 5:06 PM, Nikita Popov wrote: > 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 > I think yes, However, Alexander thinks differently https://wiki.php.net/rfc/parser-extension-api Of course this is not for 7.0 Thanks. Dmitry. --047d7b86d99045af20050f4b2654--