-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editorial: Notes that tell you where a Return
step returns to
#2400
Comments
In Await and GeneratorYield and (since the merge of PR #2413) AsyncGeneratorYield, the relevant pseudo-code is roughly of the form:
I believe we could editorially change this to (something like):
(So one odd
|
Oh, also, in the case of |
The "Resume ... passing ..." language could be usefully extended to GeneratorStart as well. GeneratorStart currently has (roughly, skipping some cases and details)
That final
Modulo an unfortunately normative change to the Realm used for the IterResultObject (which is wildly inconsistent in implementations), we could rewrite GeneratorStart as
This also applies to AsyncFunctionStart and (I think) AsyncGeneratorStart, though in those cases the value with which the outer context is resumed will not be consumed (except in AsyncFunctionStart, to assert it is |
Why don’t we store a reference to |
The current text says that control "returns to the evaluation of the operation that had most previously resumed evaluation of contextA", which suggests that contextA has to remember where that is, and your suggestion would be a way to make that more explicit. But really, control just transfers to what is now the running execution context, i.e., the context that was "under" contextA on the stack, which by design is also the context that most recently resumed contextA. In effect, the execution context stack does all the remembering we need. |
OK, I missed that "running execution context" is a synonym to "top of the stack". It makes sense now, thanks. |
That is, eliminate NOTE-steps that tell you where a Return-step returns to. Resolves tc39#2400 by performing the transformation outlined in: tc39#2400 (comment)
That is, eliminate NOTE-steps that tell you where a Return-step returns to. Resolves tc39#2400 by performing the transformation outlined in: tc39#2400 (comment)
That is, eliminate NOTE-steps that tell you where a Return-step returns to. Resolves tc39#2400 by performing the transformation outlined in: tc39#2400 (comment)
Normally, when an operation executes a
Return
step, it transfers control back to the operation that invoked it. In fact, this is so normal that the spec doesn't even bother saying it.So it's pretty weird that when the operation GeneratorYield executes the
Return
at step 9, it doesn't return to its caller.What makes it even weirder is that the only thing in the spec that tells you that it doesn't return to its caller is a Note (step 10), but Notes are supposed to be non-normative. If you remove the operation's Notes, there's nothing to tell you that step 9 isn't a garden-variety
Return
.(As for the
Return
at 8.a, it's harder to say what the normal interpretation would be, because it's less clear what would constitute its "caller" if/when it executes, though I'd say that the GeneratorResume that will have just resumed it would have a better claim than whatever originally called GeneratorYield. So again, the Note at 8.b is necessary to convey the intended semantics of theReturn
step.)The spec has 2 other places where a Note tells you where a
Return
returns to:Await
AsyncGeneratorYield
Given that Notes should be non-normative, what are we to make of these cases?
For brevity, ORT = "operation return-target", i.e. where a
Return
-step in an abstract operation will return to.In order for the
Return
steps to behave as the Notes indicate, the assumed mental model appears to be this:If algorithm A invokes operation B, and B has a step of the form:
then when B executes that step, this causes B to modify its ORT. Specifically, B's ORT changes from:
to:
(E.g., when B is
GeneratorYield
, A might be a definition of theEvaluation
SDO for a YieldExpression, and R isGeneratorResume
.)Roughly speaking, the assumption appears to be that the ORT is an attribute of each execution context, so when you change the running execution context, you change where the current operation will return to.
(1)
It's odd that the spec would assume this mental model, because as far as I can tell, it doesn't do anything to give you that mental model. I had to reverse-engineer it from Notes.
(2)
As a model, it leaves questions unanswered:
(3)
Even if we could answer those questions, it just seems to me like a bad model, where the semantics of something as basic as a
Return
step involve the current state of the execution context stack. In my opinion, we should only useReturn
when it has garden-variety semantics. If anything else is happening, we should use different phrasing. I'm working on a PR to that effect.The text was updated successfully, but these errors were encountered: