Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83081 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60387 invoked from network); 18 Feb 2015 15:17:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Feb 2015 15:17:55 -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.169 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.212.169 mail-wi0-f169.google.com Received: from [209.85.212.169] ([209.85.212.169:54899] helo=mail-wi0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B1/B0-56339-12DA4E45 for ; Wed, 18 Feb 2015 10:17:54 -0500 Received: by mail-wi0-f169.google.com with SMTP id em10so39657913wid.0 for ; Wed, 18 Feb 2015 07:17:50 -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=3+f/ZfK3L9fYpHvlvtcMZYZDW0x/4swoSu4rxw1cy8Y=; b=0ElXSFEhZRxoV7PlHjtUMClTJvejqDu6kW3Sabg/9jXw7B4avTGusDFAJ2DfNOKSzv tP46y0Fp3pHnxIVkoSIXHPNLYofFyxglFxnq+3MXELyGWHb69sff2GKkQtWmAnfCc15V /T1/WWldj7XctU4mSVXkJJKb1V2HiJcZ6KqZN4UUmIORc7jurOc2cIpogh9+a9LmgQ1Q VZh3SxD2rTuIiciTi+LkQJj0am/coRB+Cnj90tlGXDnAZYFGAjrJzBZVZsYi/v9gVAQF ztIvtaX41Q/C2atli0I+/kWu9NFUJ1BvDCym3fsy23cQcu2BDU9scumRi5T6InqUm1Eq 5TVA== MIME-Version: 1.0 X-Received: by 10.180.21.133 with SMTP id v5mr4196562wie.27.1424272669929; Wed, 18 Feb 2015 07:17:49 -0800 (PST) Received: by 10.27.10.168 with HTTP; Wed, 18 Feb 2015 07:17:49 -0800 (PST) In-Reply-To: <54E4AA80.6050205@rodas.me> References: <54E4AA80.6050205@rodas.me> Date: Wed, 18 Feb 2015 16:17:49 +0100 Message-ID: To: Cesar Rodas Cc: PHP internals Content-Type: multipart/alternative; boundary=047d7b87477c8df5aa050f5e5270 Subject: Re: [PHP-DEV] [RFC][Discussion] Parser extension API From: nikita.ppv@gmail.com (Nikita Popov) --047d7b87477c8df5aa050f5e5270 Content-Type: text/plain; charset=UTF-8 On Wed, Feb 18, 2015 at 4:06 PM, Cesar Rodas wrote: > > On 18/02/15 15:59, Nikita Popov wrote: > > On Wed, Feb 18, 2015 at 7:22 AM, Dmitry Stogov wrote: > > > >> Hi, > >> > >> On Tue, Feb 17, 2015 at 2:46 PM, Alexander Lisachenko < > >> lisachenko.it@gmail.com> wrote: > >> > >>> Hello, internals! > >>> > >>> I want to introduce a RFC for providing a userland API for accessing an > >>> Abstract Syntax Tree of the source code and to provide userland parser > >>> hooks for source code modification: > >>> https://wiki.php.net/rfc/parser-extension-api > >>> > >>> Thanks! > >>> > >> The first part, describing https://github.com/nikic/php-ast , looks > fine. > >> I see no problems including this extension into PHP-7.0 core > distribution. > >> May be even making it required (like ext/reflection). > >> > >> Nikita, what do you think? > >> > >> The second part looks very interesting, however it has some uncovered > >> questions. > >> - API for AST modification > >> - AST validation (someone may insert "break" node in "parameter-list"). > >> > >> If you have enough experience, I would suggest you to try writing an > >> external extension that would implement this idea. > >> If you'll need some modification in PHP core (e.g adding callbacks), we > >> may consider including them in PHP-7.0. > >> > >> Thanks. Dmitry. > >> > > I agree with Dmitry. > > > > Exporting the AST to userland in PHP 7.0 would be nice. With Dmitry's > work > > on assertions we even have a pretty printer for it, which allows us to > > convert the AST back to PHP code. > > In this matter, how would it be? It'd be awesome if function expects an > AST tree object instead of a value: > > function doQuery($table, *$where) { > $where = convert_ast_toSqlWhere($where); > } > > doQuery("foobar", $col1 = "something" AND $col2 == $col3); > > Or at least `ast()`, although both would be nice to have. > The problem here is that in most cases we do not actually know what function will be called at compile time. A very simple example would be to replace doQuery() with $db->query() and already we don't know what it is that we're actually calling and whether or not it needs an AST. However this does not apply to just methods, it's an issue with nearly all calls. As such PHP cannot know at compile time whether it should issue a normal call with evaluated arguments or whether it needs to preserve the AST and pass that. Just keeping the AST around for all calls would be too expensive (it's a pretty big memory hog). So rather than having this as a modifier in the function signature, it would have to be a modifier in the call syntax. E.g. rust uses foo!() syntax for macros. Nikita --047d7b87477c8df5aa050f5e5270--