> -----Original Message----- > From: Anthony Ferrara [mailto:ircmax...@gmail.com] > Sent: Monday, February 23, 2015 3:02 AM > To: Zeev Suraski > Cc: PHP internals > Subject: Re: [PHP-DEV] JIT (was RE: [PHP-DEV] Coercive Scalar Type Hints > RFC) > > Zeev, > > > I think we are indeed getting somewhere, I hope. > > If I understand correctly, effectively the flow you're talking about > > in your example is this: > > > > 1. The developers tries to run the program. > > 2. It fails because the static analyzer detects float being fed to an > > int. > > 3. The user changes the code to convert the input to int. > > 4. You can now optimize the whole flow better, since you know for a > > fact it's an int. > > > > Did I describe that correctly? > > Partially. > > The static analysis and compilation would be pure AOT. So the errors would > be told to the user when they try to analyze the program, not run it. > Similar > to HHVM's hh_client.
How about that then: 1. The developers runs a static analyzer on the program. 2. It fails because the static analyzer detects float being fed to an int. 3. The user changes the code to convert the input to int. 4. You can now optimize the whole flow better, since you know for a fact it's an int. Is that an accurate flow? > However, there could be a "runtime compiler" which compiles in PHP's > compile flow (leveraging opcache, etc). In that case, if the type > assertion > isn't stable, the function wouldn't be compiled (the external analyzer > would > error, here it just doesn't compile). Then the code would be run under the > Zend engine (and error when called). Got you. Is it fair to say that if we got to that case, it no longer matters what type of type hints we have? > >> With strict typing at the foo() call site, it tells you that $input > >> has to be an int or float (respectively between the snippets). > > > > I'm not following. > > Are you saying that because foo() expects an int or float > > respectively, $input has to be int or float? What if $input is really > > a string? Or a MySQL connection? > > So think of it as a graph. When you start the type analysis, there's one > edge > between $input and foo() with type mixed. Looking at foo's argument, you > can say that the type of that graph edge must be int. > Therefore it becomes an int. Then, when you look at $input, you see that > it > can be other things, and therefore there are unstable states which can > error > at runtime. So when you say it 'must be an int', what you mean is that you assume it needs to be an int, and attempt to either prove that or refute that. Is that correct? If you manage to prove it - you can generate optimal code. If you manage to refute that - the static analyzer will emit an error. If you can't determine - you defer to runtime. Is that correct? For now only focusing on these two parts so that we can make some progress; May come back to others later... Thanks, Zeev -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php