Re: JIT (was RE: [PHP-DEV] Coercive Scalar Type Hints RFC)

From: Date: Mon, 23 Feb 2015 13:52:31 +0000
Subject: Re: JIT (was RE: [PHP-DEV] Coercive Scalar Type Hints RFC)
References: 1 2 3 4 5 6 7 8 9 10 11 12  Groups: php.internals 
Request: Send a blank email to internals+get-83570@lists.php.net to get a copy of this message
Robert, On Mon, Feb 23, 2015 at 3:27 AM, Robert Stoll <php@tutteli.ch> 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 = 1; //can be int for sure right? > $b = "a"; > $$b = "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. 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: $a = "h"; foo($a); And hence know **at compile time** that's an error. 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. Anthony

« previous php.internals (#83570) next »