Skip to content

Editorial: Factor out AO RunSuspendedContext()#2664

Merged
ljharb merged 1 commit into
tc39:mainfrom
jmdyck:RunSuspendedContext
May 6, 2026
Merged

Editorial: Factor out AO RunSuspendedContext()#2664
ljharb merged 1 commit into
tc39:mainfrom
jmdyck:RunSuspendedContext

Conversation

@jmdyck
Copy link
Copy Markdown
Collaborator

@jmdyck jmdyck commented Feb 13, 2022

This doesn't address the semantics of Suspend/Resume, just factors out a common chunk of code.

This PR is split into 6 commits where it's easier to confirm the correctness. They're probably fine to be squashed before landing.

Comment thread spec.html Outdated
1. Push _asyncContext_ onto the execution context stack; _asyncContext_ is now the running execution context.
1. <emu-meta effects="user-code">Resume the suspended evaluation of _asyncContext_</emu-meta> using NormalCompletion(_value_) as the result of the operation that suspended it.
1. Assert: When we reach this step, _asyncContext_ has already been removed from the execution context stack and _prevContext_ is the currently running execution context.
1. Perform Completion(RunSuspendedContext(_asyncContext_, NormalCompletion(_value_))).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmdyck @bakkot Does ecmarkup complain if you remove these Completion(...)s? If so, we should allow them to be omitted when used with Perform since they're not actually entering the algorithm.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does, e.g.: error: RunSuspendedContext returns a Completion Record, but is not consumed as if it does (typecheck) at spec.html:46018:24

@michaelficarra michaelficarra added the editor call to be discussed in the next editor call label Nov 21, 2022
@michaelficarra michaelficarra removed the editor call to be discussed in the next editor call label Dec 7, 2022
@jmdyck jmdyck force-pushed the RunSuspendedContext branch 2 times, most recently from ed3013c to 4cfe666 Compare January 14, 2023 14:29
@jmdyck
Copy link
Copy Markdown
Collaborator Author

jmdyck commented Jan 14, 2023

This PR's RunSuspendedContext (on the 'next' side) is the complementary operation to RunCallerContext (on the 'yield' side), which I proposed in PR #2665, but which got separated out of that PR by editor request. So I'm expecting that this PR will be rejected. If that's the case, hearing it sooner would mean less maintenance work for me.

@jmdyck jmdyck force-pushed the RunSuspendedContext branch from 4cfe666 to a05d197 Compare March 1, 2023 04:18
@jmdyck jmdyck force-pushed the RunSuspendedContext branch from a05d197 to c6bc612 Compare May 23, 2024 14:13
@jmdyck jmdyck force-pushed the RunSuspendedContext branch from c6bc612 to 27a2df5 Compare April 7, 2025 18:57
@jmdyck jmdyck force-pushed the RunSuspendedContext branch from 27a2df5 to 98d3b24 Compare July 16, 2025 21:17
@jmdyck jmdyck force-pushed the RunSuspendedContext branch from 98d3b24 to 308349d Compare April 16, 2026 03:29
@nicolo-ribaudo
Copy link
Copy Markdown
Member

I know that a few years ago there was some opposition to this, but I think it's a good change. It's a somewhat complex set of steps, and a reader should be able to easily tell that in all those places the spec is doing exactly the same thing.

@nicolo-ribaudo nicolo-ribaudo added the editor call to be discussed in the next editor call label Apr 23, 2026
@michaelficarra michaelficarra removed the editor call to be discussed in the next editor call label Apr 23, 2026
Copy link
Copy Markdown
Member

@gibson042 gibson042 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also in favor of this change, and the sequence of commits makes its editorial nature clear.

@jmdyck
Copy link
Copy Markdown
Collaborator Author

jmdyck commented Apr 23, 2026

As requested at today's editor call: RunCallerContext, the complementary AO extracted from PR #2665, is at https://github.com/jmdyck/ecma262/tree/RunCallerContext. It might make sense to add those commits to this PR (rather than making another PR), since the two are so closely related.

To summarize:
RunSuspendedContext:

  • invoked from the next side,
  • pushes a context onto the execution context stack, and
  • "resumes" that context.

RunCallerContext:

  • invoked from the yield side,
  • pops a context from the execution context stack, and
  • "resumes" the new top of the execution context stack.

I'm not entirely happy with the names of the proposed AOs. They're mostly based on existing terminology, which has issues. In particular, RunSuspendedContext is called that because its cases say "resume the suspended evaluation of context ...", which the cases for RunCallerContext don't. But this is not great, because, in the next/yield distinction, either side is 'suspended' while the other side is running, so "SuspendedContext" could describe both sides. RunGenerativeContext might be better. Or RunCalleeContext, though the caller/callee distinction is maybe misleading (plus it's not great that they differ by only a single letter).

(Note that PR #2962 changes some of the terminology, including scrapping the idea of "suspending" and "resuming" execution contexts.)

Comment thread spec.html
1. Push _asyncContext_ onto the execution context stack; _asyncContext_ is now the running execution context.
1. <emu-meta effects="user-code">Resume the suspended evaluation of _asyncContext_</emu-meta> using NormalCompletion(_v_) as the result of the operation that suspended it.
1. Assert: When we reach this step, _asyncContext_ has already been removed from the execution context stack and _prevContext_ is the currently running execution context.
1. Perform Completion(RunSuspendedContext(_asyncContext_, NormalCompletion(_v_))).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to give an explicit NOTE that this completion record is intentionally ignored. Same below.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. It's also ignored in AsyncGeneratorResume; would you like the same Note there?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In AsyncGeneratorResume, it's not ignored, it's asserted to be normal. So I think we only need the note here.

@michaelficarra
Copy link
Copy Markdown
Member

michaelficarra commented Apr 23, 2026

@jmdyck I think both RunSuspendedContext and RunCallerContext are an improvement, and I'm looking forward to getting #2962 rebased on top of them.

edit: Though I also think we need to find new names for these operations.

@jmdyck jmdyck force-pushed the RunSuspendedContext branch from 308349d to 3e5f088 Compare May 4, 2026 20:35
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

The rendered spec preview for this PR is available as a single page at https://tc39.es/ecma262/pr/2664 and as multiple pages at https://tc39.es/ecma262/pr/2664/multipage .

@jmdyck
Copy link
Copy Markdown
Collaborator Author

jmdyck commented May 4, 2026

@jmdyck I think both RunSuspendedContext and RunCallerContext are an improvement, and I'm looking forward to getting #2962 rebased on top of them.

So would you like RunCallerContext in this PR or a separate one?

@michaelficarra
Copy link
Copy Markdown
Member

@jmdyck Either is fine, but separate is probably better to make the review process simpler.

Comment thread spec.html Outdated
@jmdyck
Copy link
Copy Markdown
Collaborator Author

jmdyck commented May 5, 2026

@jmdyck Either is fine, but separate is probably better to make the review process simpler.

Done: PR #3846.

Copy link
Copy Markdown
Member

@linusg linusg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mild preference for s/Run/Resume/ here and in #3846 but overall this LGTM.

@michaelficarra
Copy link
Copy Markdown
Member

@linusg But it's called the "running" execution context 😉. More seriously, #2962 will probably want to name it something about transferring control, so these are probably short-lived names.

@michaelficarra michaelficarra added the ready to merge Editors believe this PR needs no further reviews, and is ready to land. label May 5, 2026
@jmdyck jmdyck force-pushed the RunSuspendedContext branch from c9d6aab to f36acf9 Compare May 5, 2026 23:47
ljharb pushed a commit to jmdyck/ecma262 that referenced this pull request May 6, 2026
@ljharb ljharb force-pushed the RunSuspendedContext branch from f36acf9 to 875e880 Compare May 6, 2026 00:23
@ljharb ljharb force-pushed the RunSuspendedContext branch from 875e880 to e07ec27 Compare May 6, 2026 00:24
@ljharb ljharb merged commit e07ec27 into tc39:main May 6, 2026
10 checks passed
@jmdyck jmdyck deleted the RunSuspendedContext branch May 6, 2026 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

editorial change ready to merge Editors believe this PR needs no further reviews, and is ready to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants