Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83570 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59417 invoked from network); 23 Feb 2015 13:52:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Feb 2015 13:52:35 -0000 Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.46 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.215.46 mail-la0-f46.google.com Received: from [209.85.215.46] ([209.85.215.46:45447] helo=mail-la0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8D/30-01128-2A03BE45 for ; Mon, 23 Feb 2015 08:52:34 -0500 Received: by labge10 with SMTP id ge10so18359350lab.12 for ; Mon, 23 Feb 2015 05:52:31 -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=G8nWQ3cokQSBetzM2jJmZsUiXthmPXFBaqlirigjlgQ=; b=ibFF4IioudEPeILSW27ZIIqrr0LK0y1jq5u3GPdHPTTCisC79k38n2LeKjInRLvbWD x1YOPguHQ9gWD7Rdh6D/eYLnL+So7UT3nrwsJ40HW1IsDEZy56CGMdgIi6g3IVN4XT56 yndGuWBjsNEvmODZ0iFWtTkkkq24RiNcUhDz0ekulHMjoOjy/HsE/kaSIAGvOfa4Qj2r VjJj3O7BiTdMGEfXHDXejlNlHELCgi1HrwOHfEksOXCcEKHrbXAMSVkTKWig/hqsvh5c 8TnAvKI5tfXlP0uwvmosGdakj5YInHLT2PuOYVFSFn+Um4F3QC7BTQRga9Rot9+9bzfV rBNw== MIME-Version: 1.0 X-Received: by 10.112.110.231 with SMTP id id7mr9923027lbb.28.1424699551273; Mon, 23 Feb 2015 05:52:31 -0800 (PST) Received: by 10.25.43.9 with HTTP; Mon, 23 Feb 2015 05:52:31 -0800 (PST) In-Reply-To: <003901d04f42$8ec315d0$ac494170$@tutteli.ch> References: <2e4694f9805ee81ea0b2c79eab06c2d6@mail.gmail.com> <54EA5EDA.8010605@gmail.com> <54EA6A99.5010609@gmail.com> <54EA7F15.9030606@gmail.com> <54EA891B.6030405@gmail.com> <09b9ee836c04b1750614a91bd39a5bed@mail.gmail.com> <54EA97A2.4010701@gmail.com> <003901d04f42$8ec315d0$ac494170$@tutteli.ch> Date: Mon, 23 Feb 2015 08:52:31 -0500 Message-ID: To: Robert Stoll Cc: 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) Robert, On Mon, Feb 23, 2015 at 3:27 AM, Robert Stoll wrote: > Hey all, > > tl;dr > > Just one point which JIT/AOT people should consider when dealing with PHP. PHP is highly dynamic and there are enough use cases which makes it impossible for a static analyser to infer types accurately without using a top type like mixed. > How would you deal with variable function calls, variable variables, reflection, dynamic includes etc. > > Your inferred types would simply be wrong without using mixed. Consider the following > > function foo(int $a){} > $a = 1; //can be int for sure right? > $b = "a"; > $$b = "h"; //oh no, your generated code would crash > foo($a); > > Maybe I am wrong and there is a possibility, if so, please let me know, would be interesting to know. This very specific example is easy to type. The reason is that we can use constant propagation to know that $$b is really $a at compile time. Hence we can reduce it to: $a = "h"; foo($a); And hence know **at compile time** that's an error. This isn't the general case, but we can error in that case (from a static analysis perspective at least) and say "this code is too dynamic". In strict mode at least. Anthony