Re: PHP True Async RFC - Stage 2

From: Date: Wed, 19 Mar 2025 08:44:00 +0000
Subject: Re: PHP True Async RFC - Stage 2
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message


On 19 March 2025 07:07:36 GMT, Edmond Dantes <[email protected]> wrote:
>Continuing the discussion from [[PHP-DEV] PHP True Async RFC - Stage 2](
>https://discourse.thephp.foundation/t/php-dev-php-true-async-rfc-stage-2/1573/24
>):
>
>[quote="Rowan_Tommins_IMSoP, post:24, topic:1573"]


Just a quick reminder that although various mirrors exist, this is primarily a mailing list, and
email clients won't parse whatever unholy mix of markdown and BBCode that is.

A bit of punctuation for things like emphasis etc is fine, but how it looks on https://news-web.php.net/php.internals is going to
be how it looks for a lot of contributors.


>I meant that the defer operator is needed in the language not only in the
>context of coroutines but in functions in general. In essence, defer is a
>shortened version of try-finally, which generates more readable code.
>
>Since that's the case, I shouldn't describe this operator in this RFC.
>However, onExit() and defer are essentially almost the same.


Ah, I get it now, thanks.


>spawn [with <scope>] <callable>[(<parameters>)];
>
>spawn (getClosure());
>
>spawn sleep(5);

You're cheating again - you've put an extra pair of brackets around one expression and not
the other, and assumed they'll work differently, but that's not the grammar you proposed.

It's possible we could resolve the ambiguity that way - if it's in brackets, it's
evaluated as an expression - but then all the other examples need to be changed to match, including
this one:

>spawn function() use(): string { return "string"; };

Instead you'd have to write this: 

spawn (function() use(): string { return "string"; });

In the end, it still comes back to "there are two grammar rules here, how do we name
them?" Only this time its "spawn" vs "spawn()" rather than
"spawn" vs "spawn call", or all the other examples I've used.




>[quote="Rowan_Tommins_IMSoP, post:24, topic:1573"]
>The only caveat is that calls using the nullsafe ?-> operator are forbidden
>- for reasons directly related to the feature, not because Nikita thought
>they were ugly.
>[/quote]
>
>Yes, that's exactly what we'd like to avoid.


Sorry, what is exactly what we'd like to avoid?


>
>[quote="Rowan_Tommins_IMSoP, post:24, topic:1573"]
>But most likely you'd still want a separate syntax for a direct function
>call, however you want to spell it:
>[/quote]
>
>**Exactly!** It turns out that the expression spawn something();
>can be interpreted as if something is a PHP constant rather than a
>function.


It's more fundamental than that: function_call and expr are overlapping grammars, so having a
rule that spawn can be followed by either of them, with different meanings, leads to ambiguities.
You can carefully tune the grammar to avoid those, but then the user has to learn those rules; or
you can just use two keywords, which I don't remember you actually responding to as a
suggestion.



Rowan Tommins
[IMSoP]


Thread (59 messages)

« previous php.internals (#126836) next »