Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126814 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 0F5161A00BC for ; Mon, 17 Mar 2025 23:08:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1742252768; bh=AmH7Izk0+l1HY5n3MXpoP3dQkDZ17AhqAqsx1700riM=; h=Date:Subject:To:References:From:In-Reply-To:From; b=EOJTcOpinBNAFW5gKBt1T3Rc5+SN3PBYegvqpNReGoFaSXF3cZ1RBmEB7KjFQAVOM R+b3OMw5dQBGIJHzMAsRZ8ifjuqAwH4DoWjXkzBuB7//Av4zVTsX0zLGVWqMyYVtS5 615ztSQTvrAzqvxRNtrk+T4MYVqXuinPUArN9axLZqTbqjzdyQTeIVOYVQM5nMG0JG mpOHy+Bsq1y+mJ4na4bkjdei3AgnyEVPZfh71HdkPNT+pmDND79wLMpJLc7CzOvF0w G2vLJzdk/1UwA4pGy4DGJVH9R078y8Yd1TOwbbVBjpYePcGC3lYqMOgkuiF3/D9N/g ybvPkGhZIMcPg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4C26A180071 for ; Mon, 17 Mar 2025 23:06:06 +0000 (UTC) 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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (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 ; Mon, 17 Mar 2025 23:06:05 +0000 (UTC) Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id 0FFB313833E6 for ; Mon, 17 Mar 2025 19:08:37 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Mon, 17 Mar 2025 19:08:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1742252917; x=1742339317; bh=Ay1qAJEU8Aue8489Yv2JnjS5B4sCTECSA8mbtTBv9j4=; b= Z3u6fbhaVij1nl11OM2V9XMYBRQ1uQMuRiA1pBZ8ieh/O4sVAdDKJK1AQEGomfk/ mLsNuX5rpSyjs7NjhYQNpM5CxjZD629slwejkoixFj8//oszfBLqnsx4mIoga4xt xIEaiymr+KipbRQxYdKjd1pC7gFeD9zfwFLzFr9/cFUbWF9BnnMNnQKm+OjtwwCj jFMxpFGgfp6sOCjVJ/F/8goiafsIjXRnyq05nzhlBHR5S3PTIrLaIf5vJGemcNJu uVL6ubaT7vEYKV4dhDUpzMLcEQaO+HPlSQbV5v5KTXGGh7xLLecnmvBxbEGB+DQr 8KW1Ti/aYUX7Y56a94xI1w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1742252917; x=1742339317; bh=A y1qAJEU8Aue8489Yv2JnjS5B4sCTECSA8mbtTBv9j4=; b=Vo6wJ37pWXQzf9A70 nIsxQnxkIQAyGzhE3S3AqDdXjgbcb7YvZ9cTrbM5zwqG15dUqryNuUEUr2O9ds23 NUck3N7qsWSxbT4uJJTJvfpGAEHpaM4IDm3iac7Aj7YkomyNuhfKGkvz1WWcLom+ hLFcrXJKMdftjLq0k2KzI7CAhvzr1QLLWOF01tjkgKi6xkmF3zLa8COnSQzlpAQS 1qAe1rmYF12Ksdv9sGb0Wvq3451yQ30gpLnj96gFnI2LyYDjvPxAkx9A4iq0KOC3 Eq1wOvb4C6U7uQQA5HRry+OLQD4bpE4VZJEUWy0OSPWGiW3oFc5gGVm8qytTStUF pgCFw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddugedtkeduucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefkff ggfgfuvfhfhfgjtgfgsehtkeertddtvdejnecuhfhrohhmpedftfhofigrnhcuvfhomhhm ihhnshculgfkoffuohfrngdfuceoihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqe enucggtffrrghtthgvrhhnpeffkeevudffuddvheejvdefkeelfedtudegfeehjeduheeg ieduffeggeegveefheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehimhhsohhprdhphhhpsehrfigvtgdrtghordhukhdpnhgspghrtghpthht ohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslh hishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 17 Mar 2025 19:08:36 -0400 (EDT) Message-ID: Date: Mon, 17 Mar 2025 23:08:34 +0000 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] PHP True Async RFC - Stage 2 To: internals@lists.php.net References: <72bd5401-53a9-409f-ad45-687333401961@rwec.co.uk> Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 17/03/2025 07:58, Edmond Dantes wrote: > > However, I really liked the `$scope->spawn()` construct in the example > code, as it feels the most natural compared to `spawn in`. > Moreover, the `spawn in` expression is quite complex to implement, but > I don't have enough experience to evaluate it properly. I agree, it's a natural way of making the spawn happen "on" the scope; but it potentially makes spawning in a scope a "second-class citizen" if `spawn foo($bar);` has to be expanded out to as `$scope->spawn( fn() => foo($bar) );` just to add a scope. There are other ways it could be included, like with some extra punctuation: spawn($scope) foo($bar); spawn<$scope> foo($bar); spawn@$scope foo($bar); > ## Defer > > I have nothing against the `suspend` keyword. > However, the `defer` keyword raises some questions. "Defer" means to > postpone something (to delay execution). > But in this case, it’s not about "postponing" but rather "executing > upon function block exit." > I don't know why the creators of Go chose this word. I considered > `finally`, but it is already used in the `try` block. I did say the names were subject to bikeshedding; my main point was that this was one of the actions that should have a keyword. I mostly chose "defer" because it's what used in other languages, and "onexit" sounds like "run at end of program". That said, "defer" makes perfect sense to me: the action is not run immediately, it's delayed (deferred) until the end of the scope. do_this_first(); defer do_this_later(); do_this_second(); > The implementation also concerns me a bit. > It seems that to fully implement the `defer` block, we would need > something similar to `finally`, or essentially make `defer` create an > implicit `try...finally` block. I'm confused - $scope->onExit() is already in the RFC, and I wasn't suggesting any change other than the syntax. (Although I'm not sure if it should defer to coroutine exit rather than scope exit by default?) > > **General syntax:** > > ```php > spawn [in ] function [use()][: ] { > > }; > ``` The "function" keyword just looks out of place here, because there's never a function the user can see. I also don't like that it's almost-but-not-quite a valid closure expression - the missing () looks like a typo. If the syntax is going to be that close, why not just allow an actual callable? That way, a user can write an anonymous function with all the features already supported - return types, captured variables (you've labelled them "parameters" here, but that's not what a "use" statement lists), etc. In an earlier draft of my e-mail, I was going to suggest a "spawn call" variant, where: spawn foo(42); // spawns a call to foo with argument 42 spawn call $callable; // spawns a call to whatever's in $callable, with no arguments spawn call function() use($foo, &$bar) { do_whatever($foo, $bar); }; // creates a Closure, and spawns a call to it spawn call bar(...); // mostly equivalent to "spawn bar();", but with some extra overhead spawn call create_me_a_lovely_function('some', 'args'); // calls the function directly, then asserts that the result is a callable, and spawns a call to that with no arguments Or maybe they're just two different keywords: async_run foo(42); async_call $callable; In general, I prefer code to be explicit and unambiguous at a glance, rather than concise but ambiguous unless you've memorised the grammar. So if there are two forms of "spawn", I'd prefer to spell them differently. > The form `spawn ();` > is a shorthand for `spawn use(, ) { return ... };` > The expression `();` is not executed directly at > the point where `spawn` is used but in a different context. > > There is a slight logical ambiguity in this form, but it does not seem > to cause any issues with comprehension. Is this just a description of your own comprehension, or based on some more general experience of something similar? > As for the form: > > `spawn ()(parameters)` — I suggest not implementing it at > all. I'm not sure what you mean by above. Slightly expanding out the actual parser rules from php-src, a function_call can be: name argument_list class_name T_PAAMAYIM_NEKUDOTAYIM member_name argument_list variable_class_name T_PAAMAYIM_NEKUDOTAYIM member_name argument_list callable_variable argument_list dereferenceable_scalar argument_list new_dereferenceable argument_list '(' expr ')' argument_list Where callable_variable is a slightly misleading name, and includes expanding recursively to function_call, as in the add(1)(2) form beloved of Function Programmers Is there a reason to redefine all of this and make fresh decisions about what to allow? I would argue for "principle of least surprise": reuse or emulate as much of the existing grammar as possible, even if you personally would never use it. -- Rowan Tommins [IMSoP]