Skip to content

Editorial: non-syntactic async/generator functions use NormalCompletion #3606

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

bakkot
Copy link
Contributor

@bakkot bakkot commented May 15, 2025

This moves the machinery for handling implicit returns in syntactic async/generator functions into the branches for evaluating parse nodes, instead of also using that logic for evaluating Abstract Closures.

It assumes that non-syntactic async/generator functions always internally return ThrowCompletions or NormalCompletions. Right now they can use both ReturnCompletions or NormalCompletions, which provides an unnecessary degree of freedom. The alternative is to enforce that non-syntactic async/generator functions return ThrowCompletions or ReturnCompletions, for which see #3605.

This makes non-syntactic async/generator functions match non-syntactic ordinary functions, which similarly always return ThrowCompletions or NormalCompletions. For that reason, I prefer this PR over #3605. (Edit: in the editor call today, the other editors agreed.)

In addition, it moves the handling of ReturnCompletions in evaluation of ordinary functions to immediately after the evaluation of the function body, to match async/generator functions as of this PR. This means EvaluateBody and its callees now return NormalCompletions.

Commits should be reviewed individually.

(This PR would also require changing the existing built-in generators/async functions to never return ReturnCompletions. I'll push up a commit doing that if we go this route.)

bakkot added 2 commits May 23, 2025 12:36
AsyncBlockStart needs to get a return completion when evaluating concise async arrows so that it knows to use the value instead of *undefined*, so we need to return a return completion in the evaluation semantics for ExpressionBody and then in the non-async case unwrap that to a normal completion in EvaluateConciseBody (which is not used in the async case).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant