> -----Original Message----- > From: Pavel Kouřil [mailto:pajou...@gmail.com] > Sent: Monday, February 23, 2015 11:49 AM > To: Joe Watkins > Cc: Zeev Suraski; PHP internals > Subject: Re: [PHP-DEV] JIT (was RE: [PHP-DEV] Coercive Scalar Type Hints > RFC) > > On Mon, Feb 23, 2015 at 10:28 AM, Joe Watkins <pthre...@pthreads.org> > wrote: > > Zeev, > > > >> If you can infer the type with confidence, you can do away with > >> coercion > > code altogether. > > > > Maybe I'm ignorant of something, but isn't the only way you can begin > > to infer the type with real confidence is by having strict typed > > parameters ? > > > > This sounds like the kind of strict mode we're talking about, where no > > coercion is necessary because inference is so reliable given a good > > starting place (function entry with strictly typed parameters). > > > >> If you can't, then you're not obligated to generate optimized paths > >> for > > every possible input - you can just defer to the relevant coerce() > > function. > > > > If the parameters aren't strict but are typed then you need to travel > > coercion code paths somewhere, optimized inline, calling an API > > function, it makes no real difference. > > > > I guess we are hedging our bets that having to travel those paths will > > suck away so much performance, that it will make all of the effort > > required to make any of this a reality seem, somehow ... wasted. > > > >> JIT might end up being about making PHP viable for more CPU-bound use > > cases ... > > > > This is probably quite realistic. > > > > In case anyone is reading and thinks I'm using any of this to justify > > dual mode, I'm not doing that. The original RFC justified it well > > enough, I just happen to disagree with some of the assertions made in > > this thread and or RFC. > > > > Hello, > > if I understand the issue correctly, not even strongly typed parameters > won't > help you infer types of variables with real confidence? > > Imagine this piece of code: > function foo(int $x) { $x = fnThatReturnsRandomScalarType(); return $x; }
Absolutely correct. On the flip side, you can very often infer type without any type hints at all. In reality we'd have to rely on that quite heavily, since code is not only about - or even mostly about - function arguments. There are local variables, function arguments can be reassigned and change type (as you illustrated), etc. For example, from bench.php: function simplecall() { for ($i = 0; $i < 1000000; $i++) strlen("hallo"); } You can infer with full confidence that $i is an int without having any type hint information for it. This is actually a remarkably common case. Zeev -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php