Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83573 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65834 invoked from network); 23 Feb 2015 14:15:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Feb 2015 14:15:33 -0000 Authentication-Results: pb1.pair.com header.from=php@tutteli.ch; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=php@tutteli.ch; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain tutteli.ch designates 80.74.154.78 as permitted sender) X-PHP-List-Original-Sender: php@tutteli.ch X-Host-Fingerprint: 80.74.154.78 ns73.kreativmedia.ch Linux 2.6 Received: from [80.74.154.78] ([80.74.154.78:42594] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 40/71-01128-3063BE45 for ; Mon, 23 Feb 2015 09:15:32 -0500 Received: (qmail 4588 invoked from network); 23 Feb 2015 15:15:27 +0100 Received: from cm135-167.liwest.at (HELO RoLaptop) (81.10.135.167) by ns73.kreativmedia.ch with ESMTPSA (AES256-SHA encrypted, authenticated); 23 Feb 2015 15:15:27 +0100 To: "'Anthony Ferrara'" Cc: "'PHP internals'" References: <2e4694f9805ee81ea0b2c79eab06c2d6@mail.gmail.com> <54EA5EDA.8010605@gmail.com> <54EA6A99.5010609@gmail.com> <54EA7F15.9030606@gmail.com> <54EA891B.6030405@gmail.com> <09b9ee836c04b1750614a91bd39a5bed@mail.gmail.com> <54EA97A2.4010701@gmail.com> <003901d04f42$8ec315d0$ac494170$@tutteli.ch> In-Reply-To: Date: Mon, 23 Feb 2015 15:15:26 +0100 Message-ID: <005801d04f73$2c59a450$850cecf0$@tutteli.ch> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQIDXD7ehmaYKzbAddTs7O1sB4MzmgIw+OLdAe4e2iYCibfnDQEmdWqtAiDZcfAB4cR2SQJXxpD6Ais01rQBOuFyBwIXH55kAgBLRkUB7WPLqpvbhOUg Content-Language: de-ch Subject: AW: [PHP-DEV] JIT (was RE: [PHP-DEV] Coercive Scalar Type Hints RFC) From: php@tutteli.ch ("Robert Stoll") Heya Anthony, > -----Urspr=C3=BCngliche Nachricht----- > Von: Anthony Ferrara [mailto:ircmaxell@gmail.com] > Gesendet: Montag, 23. Februar 2015 14:53 > An: Robert Stoll > Cc: PHP internals > Betreff: Re: [PHP-DEV] JIT (was RE: [PHP-DEV] Coercive Scalar Type = Hints RFC) >=20 > Robert, >=20 > On Mon, Feb 23, 2015 at 3:27 AM, Robert Stoll wrote: > > Hey all, > > > > tl;dr > > > > Just one point which JIT/AOT people should consider when dealing = with PHP. PHP is highly dynamic and there are enough > use cases which makes it impossible for a static analyser to infer = types accurately without using a top type like mixed. > > How would you deal with variable function calls, variable variables, = reflection, dynamic includes etc. > > > > Your inferred types would simply be wrong without using mixed. > > Consider the following > > > > function foo(int $a){} > > $a =3D 1; //can be int for sure right? > > $b =3D "a"; > > $$b =3D "h"; //oh no, your generated code would crash foo($a); > > > > Maybe I am wrong and there is a possibility, if so, please let me = know, would be interesting to know. >=20 > This very specific example is easy to type. The reason is that we can = use constant propagation to know that $$b is really $a > at compile time. Hence we can reduce it to: >=20 > $a =3D "h"; > foo($a); [Robert Stoll]=20 Sure, "a" was just an example to illustrate the problem. I figured it = would not be necessary to say that the value of $b can be completely = unknown by the static analyser -> could come from user input, from a = database, from unserialising code etc. (but probably that is what you = meant with "this isn't the general case" below). Assuming statically that $a is int or $b is string is erroneous in this = context. Another problem to illustrate that a top type or at least some form of = union type is required: function foo($x, $y, $z){ $a =3D 1; if($x){ $a =3D "1"; } If($y > 10){ $a =3D []; } If($z->foo() < 100){ $a =3D new Exception(); } echo $a; return $a; } How do you want to type $a without using a union type? >=20 > And hence know **at compile time** that's an error. >=20 > This isn't the general case, but we can error in that case (from a = static analysis perspective at least) and say "this code is too > dynamic". In strict mode at least. [Robert Stoll]=20 If you go and implement a more conservative type system than the actual = dynamic type system of PHP well then... you can do whatever you want of = course. But if you do not just want to support just a limited set of PHP then = you will need to include dynamic checks in many places. Or do you think = that is not true? > Anthony