Skip to content

Keep generator frames on the thread running the body - #2146

Open
BCSharp wants to merge 1 commit into
IronLanguages:mainfrom
BCSharp:generator-framestack
Open

BCSharp wants to merge 1 commit into
IronLanguages:mainfrom
BCSharp:generator-framestack

Conversation

@BCSharp

@BCSharp BCSharp commented Nov 5, 2026

Copy link
Copy Markdown
Member

Addresses the generator part of #2133:

The generator body pushes its entry once, through PythonOps.PushGeneratorFrame, and hands it over to its PythonGenerator.
The generator removes the entry from the current thread at each suspension, adds it back at each resumption, and removes it when the body finishes.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the generator frame-ownership changes.

No open issues 🎉

What changed in this PR

Addresses the generator portion of #2133 by making PythonGenerator manage its frame entry on the thread currently running the body. The .NET-async frame ownership issue remains outside this PR’s scope.

Changes:

  • Transfer ownership of generator frame entries from compiled bodies to PythonGenerator.
  • Remove entries on suspension or completion and restore them on the resuming thread.
  • Add regression tests for cross-thread completion and tracing changes between resumptions.
File Description
tests/​suite/​test_generator.py Tests cross-thread completion, frame preservation, and tracing transitions.
src/​core/​IronPython/​Runtime/​Operations/​PythonOps.cs Adds the generator frame handoff helper.
src/​core/​IronPython/​Runtime/​Generator.cs Manages frame entries across suspension, resumption, and completion.
src/​core/​IronPython/​Compiler/​Ast/​Node.cs Adds generator-specific frame handling without a body-owned pop.
src/​core/​IronPython/​Compiler/​Ast/​FunctionDefinition.cs Selects generator-specific framing for bodies backed by PythonGenerator.
src/​core/​IronPython/​Compiler/​Ast/​AstMethods.cs Registers the new helper for generated calls.

Review effort: Balanced

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.

2 participants