Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:39475 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98055 invoked from network); 30 Jul 2008 18:23:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Jul 2008 18:23:31 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 212.25.124.163 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 212.25.124.163 il-gw1.zend.com Windows 2000 SP4, XP SP1 Received: from [212.25.124.163] ([212.25.124.163:31085] helo=il-gw1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9A/2E-60483-391B0984 for ; Wed, 30 Jul 2008 14:23:16 -0400 Received: from ws.home ([10.1.1.1]) by il-gw1.zend.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 30 Jul 2008 21:23:53 +0300 Message-ID: <4890B18E.7000500@zend.com> Date: Wed, 30 Jul 2008 22:23:10 +0400 User-Agent: Thunderbird 2.0.0.14 (X11/20080501) MIME-Version: 1.0 To: Matt Wilmas CC: internals@lists.php.net, Nuno Lopes References: <013e01c8f257$1e1bbcf0$0201a8c0@pc1> In-Reply-To: <013e01c8f257$1e1bbcf0$0201a8c0@pc1> X-Enigmail-Version: 0.95.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 30 Jul 2008 18:23:53.0247 (UTC) FILETIME=[6BB772F0:01C8F271] Subject: Re: [PATCH] Constant expr folding (again), and other things From: dmitry@zend.com (Dmitry Stogov) Hi Matt, does the following code work with your patch? It would be hard to explain why some of constant expression work, but others don't. Anyway, it's too late for this patches. 5.3 is going to be frozen. Thanks. Dmitry. Matt Wilmas wrote: > Hi Dmitry, all, > > I was going to send this patch as a companion one to go with the > compile-time constant substitution change (Nuno sent a message about this > [1] last Sep. with a patch [2]), BUT I also realized that some different, > inconsistent behavior is possible because of that change. > > First, the folding optimization part, which I don't know if you'll want to > use (though it seems pretty simple/safe to apply at any time), does the same > thing as Nuno's patch, but with a different implementation. This is even > more of an optimization when combined with constant substitution, for ORing > function flags, etc. > > At the time, one of the objections (?) was that it didn't allow the same > constant expressions to initialize static variables and class > members/constants. (Though I don't see much relation: hidden, internal > optimization vs. actual syntax change/enhancement.) So I also added support > for arithmetic, bitwise, and concatenation operators (not logical or > comparison) in that context. Anyway, should be fairly simple to > understand... :-) > > Now, the different, inconsistent behavior that's possible after the constant > substitution change. This code, for example: > > function foo() { > static $a = -PHP_INT_MAX; > } > > Would have previously given "Unsupported operand types". Now it can work > because the value of PHP_INT_MAX may be substituted first. Fine, good; > except that it won't be substituted if it's in a namespace or > ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION is set, and then the error occurs. > > I thought the best solution was to disallow constants in a "static_scalar" > expression (e.g. only literals). This shouldn't break anything unless > someone was using - or + signs on TRUE/FALSE/NULL. :-O That will cause a > parse error with my changes. Also: > > function foo() { > static $a = -'abc'; // 0 > static $b = +'abc'; // abc > $c = +'abc'; // 0 > } > > So I made the static_scalar unary + operator "do something" and behave like > the regular one. Again, shouldn't break anything unless someone was > applying + to literal strings or arrays! > > Full patch with constant folding, etc. > http://realplain.com/php/const_folding.diff > http://realplain.com/php/const_folding_5_3.diff > > -OR-, basic patch only containing the fix for signed static scalars, and > only an optimization to save the opcode for unary - and + applied to a > constant value (e.g. negative numbers, primarily): > http://realplain.com/php/signed_expr_tweaks.diff > http://realplain.com/php/signed_expr_tweaks_5_3.diff > > > Thoughts...? Thanks, > Matt > > > [1] http://marc.info/?l=php-internals&m=118925033731019&w=2 > [2] http://web.ist.utl.pt/nuno.lopes/zend_constant_folding.txt >