Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83508 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92038 invoked from network); 22 Feb 2015 23:47:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Feb 2015 23:47:44 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.180 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.192.180 mail-pd0-f180.google.com Received: from [209.85.192.180] ([209.85.192.180:38527] helo=mail-pd0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6C/AD-18531-E9A6AE45 for ; Sun, 22 Feb 2015 18:47:44 -0500 Received: by pdbfp1 with SMTP id fp1so21180421pdb.5 for ; Sun, 22 Feb 2015 15:47:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=DE/8Dy9F2W7wVYMHjq0gCSQ4vjfrstHE9WRluUNYsYQ=; b=tydj+bfOgFHxl0KTm83jOg9AYb6Zt4M6XnZSJDZ+Iu/22Watzjq1JKfUvUpIIIEo+J Zndj4Yv2/SoDGITnGCSHJAID8Gi6E9XwQEWxwAY1zZH0/+m2XvQzQJVuZjU3GUnsH+VW uWAV913voDyOu2IOak51FUqQrE6u4ULt65M9HEpXPbxtvGdggHCr7QrZcg8/9pOPbnyn kyAUzz1EQTJRg/DdW9h58hU17gqX6jrT5iUCM2DrIQ+pyO7NxN1M9Rue0buTZSSOg3G3 5oWMwlEd/OMLr49UFPh8Qk7xfxHy/oYNX0umu0N+5VewMhUCSgeOi8vZ8kGKhTrXEPDj R/ow== X-Received: by 10.70.127.196 with SMTP id ni4mr14496061pdb.29.1424648858827; Sun, 22 Feb 2015 15:47:38 -0800 (PST) Received: from [192.168.2.145] (108-66-6-48.lightspeed.sntcca.sbcglobal.net. [108.66.6.48]) by mx.google.com with ESMTPSA id ot6sm27650210pdb.28.2015.02.22.15.47.37 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Feb 2015 15:47:38 -0800 (PST) Message-ID: <54EA6A99.5010609@gmail.com> Date: Sun, 22 Feb 2015 15:47:37 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Anthony Ferrara CC: Zeev Suraski , Jefferson Gonzalez , PHP internals References: <2e4694f9805ee81ea0b2c79eab06c2d6@mail.gmail.com> <54EA5EDA.8010605@gmail.com> In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] JIT (was RE: [PHP-DEV] Coercive Scalar Type Hints RFC) From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > You can tell because you know the function foo expects an integer. So > you can infer that $x will have to have the type integer due to the > future requirement. Which means the expression "$something / 2" must > also be an integer. We know that's not the case, so we can raise an > error here. OK, so your claim is that the compiler with strict typing can detect some situations which the dynamic one can not and reject some of the code. Without going too much into details, I agree with this, this is an obvious difference between strict and dynamic. However, this is not a performance advantage, obviously - since you are comparing running code with non-running one - your model just accepts less code. Obviously, this works if non-accepted code was wrong - and doesn't work if it was not. But we talked about running code, I thought. > At that point the developer has the choice to explicitly cast or put > in a floor() or one of a number of options. That's exactly what I claim would be the defect of the strict model - people would start putting excessive casts ensuring there would be cases where information is lost. For example, assume we knew $something is even: function bar(int $something): int { assert($something %2 == 0); $x = $something / 2; return foo($x); } Now everything is fine (ignoring the typing for a second), right? We're dealing with integers, /2 always divides evenly, all is great. Now we introduce strictness, so we'd need to say something like: function bar(int $something): int { assert($something %2 == 0); $x = $something / 2; return foo((int)$x); } Now assume somebody messed up on the routine code reformatting merge and the code somehow ended up like: function bar(int $something): int { $x = $something / 2; return foo((int)$x); } Do you see what the problem is? Now we lost the check for $something being even, but we would never know about it since type system forced us to insert (int) (which we didn't need) and thus disabled the controls for the bug of $something not being even (which we did need). But more important question is - with (int) the coercive model can use this information too, so what's the difference from strict model on that code? There seems to be none. > Without strict typing this code is always stable, but you still need > to generate full type assertions in a compiled version of foo() and > use ZVALs for $x, hence reducing the effect of the optimization > significantly. Wait, you said "this code is invalid" so no code will be generated. Did you mean code after introducing (int)? Then strict has no advantage anymore as we can derive the info from (int) anyway. Otherwise, I can't see how you can avoid generating typechecks in foo() unless the only place it can ever be called from is bar() - but I don't see how you can ensure that in PHP, and if you could, I don't see why weak model could not make the same conclusions on the same code. So far the only "advantage" I've seen seems to be that your compiler would reject code that looks suspicious to it and thus force the programmer to coerce the variables into the types manually - by (int) or floor() - something that the coercive model would do for you automatically. Once coerced, the same code would have the same type info (and thus same potential optimizations) in both models. I don't think it is a gain in general, and I don't think forcing people to modify their code qualifies as "JIT performance gain". -- Stas Malyshev smalyshev@gmail.com