Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118141 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 1317 invoked from network); 30 Jun 2022 14:38:24 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Jun 2022 14:38:24 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EDF5F180546 for ; Thu, 30 Jun 2022 09:29:56 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 30 Jun 2022 09:29:56 -0700 (PDT) Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-2ef5380669cso184487847b3.9 for ; Thu, 30 Jun 2022 09:29:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3AIHTANWlDeU9/Fafe1sH+t0xD7Jwgurbr8eWBLsBU8=; b=GoKT47gKeQeOh9WKPsA8/CKG3XrVOOkDacsIP6mqnOOUt+PeMbG8HZ4SSOtSR2SLvx QVtFMUOSCl2Tjtw1Wb1Rxn+zn2tmJUbkmC1GY9qboRjzJ+fDMv8wh0SvpmCMW91J/yAh qru9qB+5Bib3fgra8mp2BJm1ygscPf8xq3E87cCcX7d+50PFRY3AzBnmnaLo0zKVe0Nn 41LJThZT7J+3djmrtSSMNS3GDO15OpUuZeiELv7x7FvhPPHrjVbWCwa+zrkEa8vkTL7w UO1DiQIIiCgXp5mvhlhenu7j1mLLndbNixIBvqHUwTKPAqKoebcJZ58NcmQPJqsfudNH V2nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3AIHTANWlDeU9/Fafe1sH+t0xD7Jwgurbr8eWBLsBU8=; b=4cWtY09QklAzm0son8KLYTv9EjjEX5Gb3exNTWTdXPF058uFQF4mBz1/eXORlza8j5 mfDy4lMf4pEscFZWRnr7GKsQq/u8a5EQXrUM0+zfaeiQOIJra2qxYWW5sJlsNkY40p35 ssBxUfsRa0OQg5dAZ/TE1jw9nBzD2v2M/dxA60IpOk951P7s75OGmHWB+G8UVIkgYHBl pzDFb2X1bNGvowZBRhPl8vET6nMvmh4rF6h1sCKxWy6oCJi1dSVOmV5Ygf27WxNYcShv 86hkDktq2QEIdZCLnuPHTxzyzMp/R57OwemD3b75q6W0Wbc1gGrZ0Rdx2mrqu4p7s9ge sYBg== X-Gm-Message-State: AJIora+CvAb9JxpeKg7qr/cFYOMvIMidmiYpzw7zfJu0nfMfJ/u6CE0S QlaXEfN3T11PyJCr61u7CelCjhKgXkE34PRLLA== X-Google-Smtp-Source: AGRyM1vP0EBoJ90F3acBlqUORrFTmdOgqL7BdVZedpvpbIwTBNmEJtDLz0j56Y7ux2JUiVtqzJZaJGbZxv2Ylf+bz1c= X-Received: by 2002:a81:1d43:0:b0:318:638d:2ca with SMTP id d64-20020a811d43000000b00318638d02camr11965433ywd.135.1656606596084; Thu, 30 Jun 2022 09:29:56 -0700 (PDT) MIME-Version: 1.0 References: <2b35605f-8da8-46b1-aec3-00bd1bfe47fd@www.fastmail.com> <7513519.rnE6jSC6OK@arnaud-t490> In-Reply-To: <7513519.rnE6jSC6OK@arnaud-t490> Date: Thu, 30 Jun 2022 18:29:44 +0200 Message-ID: To: Arnaud Le Blanc Cc: internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] Short Closures 2, aka auto-capture take 3 From: guilliam.xavier@gmail.com (Guilliam Xavier) On Thu, Jun 30, 2022 at 5:57 PM Arnaud Le Blanc wrote: > > Hi, > > On jeudi 30 juin 2022 16:18:44 CEST Robert Landers wrote: > > Are > > optimizations going to be applied to single-line arrow functions (I > > didn't see that in the RFC, but I admittedly didn't look that hard and > > I vaguely remember reading something about it in one of these > > threads)? If so, it will probably change some behaviors in existing > > applications if they were relying on it. Perhaps static analysis tools > > can detect this and inform the developer. > > It is not planned to change the behavior of arrow functions in this RFC. This > optimization is less important for arrow functions because they don't usually > assign variables. Ah? Sorry, I had interpreted https://github.com/php/php-src/pull/8330/files#diff-85701127596aca0e597bd7961b5d59cdde4f6bb3e2a109a22be859ab7568b4d2R7318-R7320 as "capture the *minimal* set of variables for *both* arrow functions and short closures", but I was wrong? I don't see a test like this: ```php class C { public function __destruct() { echo 'destructed', PHP_EOL; } } $x = new C(); $fn = fn ($a, $b) => (($x = $a ** 2) + ($y = $b ** 2)) * ($x - $y); echo '- unsetting $x', PHP_EOL; unset($x); echo '- calling $fn', PHP_EOL; var_dump($fn(3, 2)); echo '- unsetting $fn', PHP_EOL; unset($fn); echo '- DONE.', PHP_EOL; ``` with current output (https://3v4l.org/ve3BL#v8.1.7): ``` - unsetting $x - calling $fn int(65) - unsetting $fn destructed - DONE. ``` where the optimization would make the "destructed" line move up to just after "- unsetting $x" -- Guilliam Xavier