Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107208 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 98803 invoked from network); 18 Sep 2019 17:33:08 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 18 Sep 2019 17:33:08 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id F2F1C2CCC1E for ; Wed, 18 Sep 2019 08:10:32 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS24940 88.99.0.0/16 X-Spam-Virus: No Received: from mx.zeyos.com (mx.zeyos.com [88.99.153.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Wed, 18 Sep 2019 08:10:32 -0700 (PDT) Received: from mx.zeyos.com (localhost [127.0.0.1]) by mx.zeyos.com (Postfix) with ESMTP id D79495FB1A for ; Wed, 18 Sep 2019 17:10:30 +0200 (CEST) Authentication-Results: mx.zeyos.com (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=zeyos.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=zeyos.com; h= content-transfer-encoding:content-type:content-type:mime-version :to:from:from:subject:subject:date:date; s=dkim; t=1568819430; x=1569683431; bh=kXfm5rwg8FJjhhq9+Kd5blQdTkUfEhkXS8f6w/Alvjk=; b= cKQJC13QfJA+WDT2xZ6XplHNMmGYtlQsVmOOnJJs2H2bxk28KyrdViwBaujcF7rC xqmDOCGELrcOYZT2wpTaKxFQ0C5tepCvi32EZD4fmn9TyTjs3xk5LtYZ+MC37xU1 4MF1C2ZWfArIqo2mAPZJ6/BiidCagier+QPcryKVIqc= X-Virus-Scanned: Debian amavisd-new at mx.zeyos.com Received: from mx.zeyos.com ([127.0.0.1]) by mx.zeyos.com (mx.zeyos.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id JiDuo-8yCJdH for ; Wed, 18 Sep 2019 17:10:30 +0200 (CEST) Received: from cloud.zeyos.com (unknown [81.171.8.203]) by mx.zeyos.com (Postfix) with ESMTPSA id 724175FB13; Wed, 18 Sep 2019 17:10:30 +0200 (CEST) Date: Wed, 18 Sep 2019 17:10:30 +0200 To: Dmitry Stogov Cc: PHP Internals , Nikita Popov MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20190918151030.D79495FB1A@mx.zeyos.com> X-Envelope-From: Subject: Constant propagation inside same compilation unit From: ben.coutu@zeyos.com (Benjamin Coutu) Hello,=0A=0ADuring performance testing of the (awesome) PHP 7.4 preloading = feature I stumbled upon a lost opportunity I'd like to point out (though th= is has nothing to do with preloading per se).=0A=0APlease consider the foll= owing snippet:=0A=0Aconst TEST =3D 14;=0A=0Afunction d() {=0A echo TEST;= =0A}=0A=0AThe function "d" yields the following opcodes:=0A=0A#0 FETCH_CONS= TANT "TEST" ~0=0A#1 ECHO ~0=0A#2 RETURN<-1> null=0A=0Ameaning, that the con= stant "TEST" does not propagate into the function, though both, the constan= t and the function, are defined in the same file.=0A=0ASame goes for this k= ind of snippet:=0A=0Aclass D {=0A=09const C =3D TEST;=0A=0A=09public functi= on d() {=0A=09=09echo self::C;=0A=09}=0A}=0A=0AHere the method "d" yields t= he following opcodes:=0A=0A#0 FETCH_CLASS_CONSTANT "C" ~0=0A#1 ECHO ~0=0A#2= RETURN<-1> null=0A=0AInterestingly enough, class constants propagate as on= e would expect:=0A=0Aclass D {=0A=09const C =3D 14;=0A=0A=09public function= d() {=0A=09=09echo self::C;=0A=09}=0A}=0A=0A#0 ECHO 14=0A#1 RETURN<-1> nul= l=0A=0AI don't see why constants defined in the same file couldn't propagat= e throughout the same compilation unit during compile time, as they can nev= er have a different value (locally in that particular defining file) at run= time.=0AIs this just an oversight or is there some deeper reasoning behind = this that I'm simply missing?=0A=0AIn terms of preloading this would be par= ticularly beneficial, cause one cloud then include/require files that defin= e global constants before compiling files that contain those constants, the= reby propagating their values throughout the code base during preloading. T= hat would eliminate a lot of the runtime cost of (not so truly constant) co= nstants.=0A=0APlease let me know your thoughts.=0A=0ACheers,=0A=0ABen=0A=0A= -- =0A=0ABenjamin Coutu=0Aben.coutu@zeyos.com