Zeev,
>> 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? Yes. At least for what I was talking about in this thread. >> 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? Once you get to the end, no. Recki-CT proves that. The difference though is the journey. The static analyzer can reason about far more code with strict types than it can without (due to the limited number of possibilities presented at each call). So this leaves the dilema: compiled code that behaves slightly differently (what Recki does) or whether it always behaves the same. >> 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? Basically yes. Anthony -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php