Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83504 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84641 invoked from network); 22 Feb 2015 23:13:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Feb 2015 23:13:25 -0000 Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.48 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.215.48 mail-la0-f48.google.com Received: from [209.85.215.48] ([209.85.215.48:46959] helo=mail-la0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7A/3C-18531-4926AE45 for ; Sun, 22 Feb 2015 18:13:25 -0500 Received: by lams18 with SMTP id s18so15317172lam.13 for ; Sun, 22 Feb 2015 15:13:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=5gAZ512i2Pf/XwvbpQk8tx3dBYGXiTZX2fFRqC0Ab38=; b=loZLhdgLsxquPVLPDjf+9QsfQqaj7b1rD0Ft3bqyvxKe627QYWahtm9LNrt540Jikx 9uvY7BBh1nnfx+mXL3wu/qeolKZA2EuTQpfCITS3ol+rImIkr202JkG0qWcLDnCT+FHO G0foIz78gR0JckqzstHdCTH9VdF4QLmpeCNegrXNzdInvawgN/R6w2rKz34Npqdt9WdV h8LQcYa+L227orQw1Nq6gCTyQHV1RpAh7YN3OVr97KnMQF1orbuZeJ+GDRMkRLlLm1xW ykpetXZghAdcaP1+RjpcfX27xmlYlT4AzicfmmEZm9uG3+s8or1OZf7y+7NcvHhACNVT 6xbQ== MIME-Version: 1.0 X-Received: by 10.112.139.136 with SMTP id qy8mr7455264lbb.38.1424646801989; Sun, 22 Feb 2015 15:13:21 -0800 (PST) Received: by 10.25.43.9 with HTTP; Sun, 22 Feb 2015 15:13:21 -0800 (PST) In-Reply-To: <54EA5EDA.8010605@gmail.com> References: <2e4694f9805ee81ea0b2c79eab06c2d6@mail.gmail.com> <54EA5EDA.8010605@gmail.com> Date: Sun, 22 Feb 2015 18:13:21 -0500 Message-ID: To: Stanislav Malyshev Cc: Zeev Suraski , Jefferson Gonzalez , PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] JIT (was RE: [PHP-DEV] Coercive Scalar Type Hints RFC) From: ircmaxell@gmail.com (Anthony Ferrara) Stas, >>> -- Can the code generated for a strict type hint can somehow be optimized > significantly better than the code generated for a dynamic/coercive type > hint. >> And me, who wrote an AOT compiler that does **exactly** this, claim > > Sorry, did exactly what? Here a bit more explanation would help. Optimized statically typed PHP functions. Or more specifically function calls inside of compiled code are treated strictly (so trying to pass a float to an int typed function would error at compile time). The outer function call (from non-compiled PHP) is parsed using ZPP rules, but once it's inside it's strict. https://github.com/google/recki-ct/blob/master/doc/0_introduction.md https://github.com/google/recki-ct/blob/master/doc/2_basic_operation.md >> However, since test_strict() is compiled, there's no reason to >> dispatch back up to PHP functions for strict_foo(). In fact, that >> would be exceedingly slow. So instead, we'd compile strict_foo() as a >> C function, and do a native function call to it. Never having to check >> types because they are passed on the C stack. > > Doesn't that assume strict_foo() is always called with the right type of > arguments? What exactly ensures that it does in fact happen? Shouldn't > you have the type check _somewhere_ to be able to claim this happens? > test_foo() doesn't do any checks, so what ensures $x is of the right > type for C? And if the check is there, how is it better? Yes it does check the types, but at compile time. My AOT compiler backend has no concept of a "mixed" or ZVAL type. All types are determined at compile time, and in the very few cases it can't it will error. The type inference engine attempts to determine specifically using all available information (prior context, current context, future context) to determine what the type is. It does also detect type changes (via assignment) and is able to correctly generate code based on that as well. >> And note that this can only work with strict types since you can do >> the necessary type inference and reconstruction (both forward from a >> function call, and backwards before it). > > I don't get the backwards part - I think you claimed it last time we > discussed it but I haven't seen your answer explaining why it's OK to > just ignore cases when the variable is of the wrong type. Right now, it > looks like you claim that if somebody has a call strict_foo($x) and > strict_foo() accepts integers, that magically makes $x integer and you > can generate code everywhere (not only inside strict_foo but outside) > assuming $x is integer without actually needing a check. I don't see how > this can work. Ok, let's take another example: