Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122258 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 6467 invoked from network); 25 Jan 2024 18:08:31 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Jan 2024 18:08:31 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1706206155; bh=W4jZ6OfpIhnbBzDC/FXU++734QODJ+ijcYUAoOLHBIQ=; h=References:In-Reply-To:From:Date:Subject:To:From; b=nSuqlDzV5Esq5N7g7c2VAuM1x5sKbOP2STTcscI1t2NamUHd9p4xfg92CmNJffgd4 Ckh7Wvo49KIK1OY/IQ3378np53UMtRBWfSkH+Jb8yB0KJRPXJ2FUluK7gTVceOvsn0 CV6ExwYJaTSHHnQOZhIEopA4wIzfcmcyx2G5BjCn1tyeYLvsQgYsWHiv1cgb8bQDiP +SXH/lBZVMPu7jEVkI0ZQhnhWCEKwfqC03tgEzSHTEbZxBLmQVGM1DETg68J0kTJxN XIrxBzD+5e+oo06we76iqSkRYIXyxc6wGhksOwrQmyRhSZ8IVuLDvAVe08bzcNWLLb owS+chdAMclDw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0BBAD18005A for ; Thu, 25 Jan 2024 10:09:15 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-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,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-oa1-f41.google.com (mail-oa1-f41.google.com [209.85.160.41]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 25 Jan 2024 10:09:14 -0800 (PST) Received: by mail-oa1-f41.google.com with SMTP id 586e51a60fabf-203ae9903a6so3194271fac.0 for ; Thu, 25 Jan 2024 10:08:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706206109; x=1706810909; darn=lists.php.net; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=NmySkKti3A1UgPq1iTRboWY+dM+Pfdfrcq0p6Clfm1g=; b=F0bZWQl53V2C9VcowEwLZ61jTiOISPGhlcQ/lTRbrz5qYZA7DyrbbnNSkLBQJdA2Ov mbfpzo9t+qw99er7vvGzy7MNotWWV1r9CZgP4r0DStLnhZWCeu2QUWKrPIfwsJ49Kj1h mziHuFcZrC6OJ/0cqlxKS2ToRGwn/51gj9Tt4uWUmtZWLuKo9rWPE/BmjrmkFKq+dn7u 2io/MzRxW9SOUbbxGa7kEPl5EST274+AKZu4odgxCP0KEWFWqHAHSSEgQ8mT+/vGqx0S t1nG/ZVnyjePX8znSK4CAfk6yHLS2cw6u+HNqaAH8whCQyrqchKDZWakCkV620HRhe7f rUfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706206109; x=1706810909; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NmySkKti3A1UgPq1iTRboWY+dM+Pfdfrcq0p6Clfm1g=; b=D82gkl2EasqA6byTDsT7gGIyeOaXY9fOlmiNAwK/TAbemVrY3AFeHqcH/9cw+SbFjn 8BllLOIGFFjYT3ER5U/dJfbU7Uo+Py+u2vVIjcPj44gltor9nQOfKWq+un6Bj7uaPBq0 e5vWmn+lJBKfTm0XfYtTN4PxLkPyWTMoacscDZJ2/7yiMVdje5Lq2Pl0gM8Iyft4Zhdg +e/d4QlZXGOUFgsKzueV2+Gz4oQ9k78CF9A7Ciz1yzaabEqdmvFgu8L7YDQa1x2QMD+G yQ9OkO5zn9zUwUbW2ZrJVUuMXsdJPtjgA24YTFelUTGyKlFLqOMuLte5FDFBCIIu9qdD qc/A== X-Gm-Message-State: AOJu0Yyr4g40yGNKEGLZVkR5T6pbjNx18pPJRRoIGy3EEyFv+xPp3HZl R7r7nCYvdqXp7d0WdupmzINKHr/gXr7XA8YhqTy7uW74w3uJ01dWQJSFjG2q29UmSfYFm/rFK6X EfchFv5e9ZMgUsdU1jSqc3jWM7NaGH+GcPkxb/w== X-Google-Smtp-Source: AGHT+IEOYEv4Dj8HnGpc0IzSgQMTS67zaBlfz+YuDmGDiONaHyT+Q3jm+dwOdoM8naem0n325wJ5O21rQ+uTdK4IZZ4= X-Received: by 2002:a05:6870:d181:b0:210:9acd:2208 with SMTP id a1-20020a056870d18100b002109acd2208mr24836oac.78.1706206108760; Thu, 25 Jan 2024 10:08:28 -0800 (PST) MIME-Version: 1.0 References: <1a292ec3-3033-4579-bc36-5aba35600c8f@app.fastmail.com> In-Reply-To: <1a292ec3-3033-4579-bc36-5aba35600c8f@app.fastmail.com> Date: Thu, 25 Jan 2024 19:08:17 +0100 Message-ID: To: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Discussion: making continue and break into an expression From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Larry On Thu, Jan 25, 2024 at 6:38=E2=80=AFPM Larry Garfield wrote: > > On Thu, Jan 25, 2024, at 11:28 AM, Ilija Tovilo wrote: > > > > This leads to very similar issues as break/continue inside blocks. See: > > https://wiki.php.net/rfc/match_blocks#technical_implications_of_control= _statements > > > I'm curious, how did `throw` expressions manage to avoid these issues? O= r was it just "Ilija did the hard work of tracking down the weirdness?" Can't really take the credit for this. This issue went over my head, as this was my first RFC. Exceptions work a bit differently, in that they use something called live-ranges. Essentially, we look at the generated opcodes and figure out which variables are "live" (i.e. valid and unfreed) during which opcodes. For something like echo foo() + bar(): Pseudo opcodes: 0000 V1 =3D CALL foo 0001 V2 =3D CALL bar 0003 V3 =3D ADD V1 V2 0004 ECHO V3 V1 would be live for 0000-0003, V2 for 0001-0003, V3 for 0003-0004. If an exception is thrown (or rethrown across function boundaries) the VM checks which temporary variables are currently live and frees them. So if CALL bar were to throw, we'd see that V1 is currently live and needs to be freed. For something like foo() + throw new Exception(), if you replace the second CALL with a throw, you'll see that the live-range for V1 doesn't change, and so this "just works". There was, however, a related issue with the optimizer. echo foo() + throw new Exception(); 0000 V1 =3D CALL foo 0001 THROW 0003 V3 =3D ADD V1 false 0004 ECHO V3 Where the optimizer would remove the dead instructions after the throw, breaking live-range analysis. 0000 V1 =3D CALL foo 0001 THROW V1 no longer had a consuming opcode, and as such the algorithm could no longer determine the live-range of V1. This would cause V1 to leak. The solution was simply to disable dead code elimination for this case. The solution was suggested by Tyson Andre and implemented by Nikita. In theory, break/continue expressions might try to re-use live-ranges. I recall thinking about this, but I can't seem to remember if there was a reason not to do it. Ilija