Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91946 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82923 invoked from network); 25 Mar 2016 12:46:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Mar 2016 12:46:36 -0000 Authentication-Results: pb1.pair.com header.from=mtkocak@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=mtkocak@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.42 as permitted sender) X-PHP-List-Original-Sender: mtkocak@gmail.com X-Host-Fingerprint: 74.125.82.42 mail-wm0-f42.google.com Received: from [74.125.82.42] ([74.125.82.42:38538] helo=mail-wm0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 38/31-10214-B2335F65 for ; Fri, 25 Mar 2016 07:46:35 -0500 Received: by mail-wm0-f42.google.com with SMTP id l68so21912932wml.1 for ; Fri, 25 Mar 2016 05:46:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:subject:from:in-reply-to:date:cc:message-id:references :to; bh=b1Lj/tNuo3prxkvmLI6dk/Y8cdeAER+oTkEy2fwz1hA=; b=JMl8PQHyT4lt7wvmvR28al7J3tTkgeAeEWUGB5kiJnvWlaRl+j5FRZE1Y6xIJuIUig y4FXsDv5OjN0YxZB1g/+Qz2ZtIB9XRi1rjW8rAfa2C+f/SN8JSrqpS51JFD3qthDpSbW S75hwWe5IpCYTFVh2zdGc9xV4nYo2/lgO8KClGGHdGjevdZlXsT3El66i3oRzCrMpLKb UrUNUE9cmO9UR7bEamhBhQXXXYUnh2Lk5/Ip+aWWfgvZslbKPHSJe6xt56MP3tCVk6lr L9nuXPirm496sKZJ4acpXSsvSB2Yxo4QLoJoyaVIP4F9tvwRyqWWyxMdbjIDcDHBlbuR W3KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :message-id:references:to; bh=b1Lj/tNuo3prxkvmLI6dk/Y8cdeAER+oTkEy2fwz1hA=; b=JCzf4G0d8Lz7MsM8rWyrGbYhkKcVQvVGLfci5ZWV+7bMowGrKujF3cPZh0zvsmjqsp 61MCfuyK1LbK2a31H+hxR1o52rryVX4ICOpo4zn42OlaKIup3bl0jN5ORA+/k1FIdRSn VnIQdh+PXpU2TJJn5a1Mr63jTmtSXY6hkeGyU7mSLbo+C7eAVBlBblOOcdooC5BmjhBR u4seIKNkAAgMzuB8sjQ7FNMjRNEK5aMXk+ijpeCXYfgjDrtjWdJ5CAO1FQJQ2kbM1gOA AEGsDWPq1gA/hWzVvAJWTGDOQsCajpDJy1tY+v8SdbTAl8qiMiYDDBmbySwQaeAn4JwE v7lQ== X-Gm-Message-State: AD7BkJIv5UbOTY3bkLI4jgwvIqSX2uI9Ynt8ydJYK0i+Ha79dyPyrobOKuSJzo61SMoAnA== X-Received: by 10.28.210.73 with SMTP id j70mr15264113wmg.8.1458909991833; Fri, 25 Mar 2016 05:46:31 -0700 (PDT) Received: from [10.2.1.130] ([81.0.202.234]) by smtp.gmail.com with ESMTPSA id j18sm3040033wmd.2.2016.03.25.05.46.30 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 25 Mar 2016 05:46:30 -0700 (PDT) Content-Type: multipart/alternative; boundary="Apple-Mail=_5C34D0CD-3D2F-4E30-AB26-E46ACA5C8D26" Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) In-Reply-To: Date: Fri, 25 Mar 2016 13:46:29 +0100 Cc: PHP internals Message-ID: <7C805132-E4B3-482A-8B4D-8E949C06639F@gmail.com> References: <9399032E-5BAA-4ABF-81AD-13716790D8DB@gmail.com> To: Nikita Popov X-Mailer: Apple Mail (2.3124) Subject: Re: [PHP-DEV] Combine ??= and ?:= assignment operator rfc's. From: mtkocak@gmail.com (Midori Kocak) --Apple-Mail=_5C34D0CD-3D2F-4E30-AB26-E46ACA5C8D26 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 h= ttp://www.rubyinside.com/what-rubys-double-pipe-or-equals-really-does-5488= .html = > On 25 Mar 2016, at 13:42, Nikita Popov wrote: >=20 > On Fri, Mar 25, 2016 at 11:59 AM, Midori Kocak > wrote: > Hi Everyone, >=20 > I think it's better idea to combine those two assignment operator = RFC=E2=80=99s. So I am going to close the current one and open ??=3D = with ?:=3D > What do you think? And we have to find better names. >=20 > Wishes, > Midori Kocak >=20 > I'd prefer to keep them separate, or at least keep their votes = separate. The ??=3D operator vote is currently unanimous at 24:0, while = the ?:=3D vote was closed at something like 9:2, so there clearly are = differences of opinion regarding these two operators. >=20 > I'll use this chance for some comments on the proposal. I can see the = general usefulness of ??=3D, but right now the RFC is severely = underspecified and I'm uncomfortable voting on it in it's current form = as so much will depend on the final implementation. So, what do I mean = by underspecified? >=20 > The only statement the RFC essentially makes is that $a ??=3D $b will = be the same as $a =3D $a ?? $b, for variable-expression $a and = expression $b. This statement, while a good high-level illustration, = does not explain the exact behavior of this operator. >=20 > For example, consider the expression $a[print 'X'] ??=3D $b. A simple = desugaring into $a[print 'X'] =3D $a[print 'X'] ?? $b will result in 'X' = being printed twice. However, this is not how all other existing = compound assignment operators behave: They will print X only once, as = the LHS is only evaluated once. I assume that ??=3D would behave the = same way. >=20 > However, with ??=3D the problem becomes more complicated. Let us = assume that $a is an ArrayAccess object and consider the expression = $a[0] ??=3D $b. Let us further assume that $x =3D $a->offsetGet(0) is = non-null. Will $a[0] ??=3D $b result in a call to $a->offsetSet(0, $x)? = This is what would normally happen with a compound assignment operator = and what would be implied by the desugaring $a[0] =3D $a[0] ?? $b. = However this assignment is not really necessary, as we're just = reassigning the same value. So, does the call happen or not? Is the = proper desugaring maybe if (!isset($a[0])) $a[0] =3D $b? >=20 > Let us now assume that $a is a recursive ArrayAccess object with = by-reference offsetGet() and consider the expression $a[0][1] ??=3D = expr. For a normal compound assignment operator, this would issue the = call sequence >=20 > $b =3D expr; > $x =3D& $a->offsetGet(0); > $y =3D $x->offsetGet(1); > $y OP=3D $b; > $x->offsetSet(1, $y); >=20 > Note that we only issue one offsetSet() at the end. We do not refetch = $x via $a->offsetGet(0). How would the same work with the ??=3D = operator? As the RHS is evaluated lazily, it is my opinion that only = performing the offsetSet() call without refetching $x beforehand would = violate PHP's indirection memory model. Additionally as ??=3D has to = fetch offsets in BP_VAR_IS mode, we likely wouldn't be able to write = them without refetching anymore. >=20 > So, what would be the desugared call sequence for $a[0][1] ??=3D expr? = Something like this? >=20 > if (!$a->offsetHas(0)) { > goto assign; > } > $x =3D $a->offsetGet(0); > if (x =3D=3D=3D null) { > goto assign; > } > if (!$x->offsetHas(0)) { > goto assign; > } > $y =3D $x->offsetGet(0); > if ($y =3D=3D=3D null) { > goto assign; > } > goto done; > assign: > $b =3D expr; > $x =3D& $a->offsetGet(0); > $x->offsetSet(1, $b); > done: >=20 > That would be some first thoughts on the issue, though I'm sure there = are more subtleties involved. I'd like to see the exact behavior of ??=3D = (and ?:=3D) specified. >=20 > I'm also pretty sure that writing a patch for this will not be = entirely easy. The combination of execute-once LHS side-effects and lazy = RHS execution does not translate well to PHP's VM constraints. >=20 > Regards, > Nikita --Apple-Mail=_5C34D0CD-3D2F-4E30-AB26-E46ACA5C8D26--