Skip to content

fix(repl): Add local/global store operation in comprehension expressions#297

Open
Embers-of-the-Fire wants to merge 3 commits intopydantic:mainfrom
Embers-of-the-Fire:fix/issue-281
Open

fix(repl): Add local/global store operation in comprehension expressions#297
Embers-of-the-Fire wants to merge 3 commits intopydantic:mainfrom
Embers-of-the-Fire:fix/issue-281

Conversation

@Embers-of-the-Fire
Copy link
Copy Markdown
Contributor

Fixes #281 by force-clearing global slots left by list/generator comprehensions.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 28, 2026

Merging this PR will not alter performance

✅ 13 untouched benchmarks


Comparing Embers-of-the-Fire:fix/issue-281 (1d130b4) with main (a5e2266)

Open in CodSpeed

@davidhewitt
Copy link
Copy Markdown
Collaborator

Thanks for the PR. This seems to me like a patch around what's probably a compiler bug. I think we can probably apply a better fix by doing something like PEP 709 - in monty the comprehensions are already inlined but we don't save / restore names either side of them as per the LOAD_FAST_AND_CLEAR / STORE_FAST opcodes described in that PEP.

Would you be up for exploring an alternative fix which instead makes comprehensions match PEP 709 better?

@Embers-of-the-Fire
Copy link
Copy Markdown
Contributor Author

@davidhewitt Ok but that might take some more time :) I'm still working on this.

@Embers-of-the-Fire Embers-of-the-Fire marked this pull request as draft March 31, 2026 04:55
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 95.23810% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/monty/src/bytecode/vm/mod.rs 94.00% 6 Missing ⚠️
crates/monty/src/bytecode/compiler.rs 97.36% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Embers-of-the-Fire and others added 3 commits April 1, 2026 15:13
Match PEP 709 more closely by saving and restoring synthetic comprehension slots instead of trimming hidden REPL globals afterward. This keeps comprehension temporaries from leaking across turns, exceptions, and pause/resume boundaries.

Co-authored-by: OpenCode <noreply@openai.com>
@Embers-of-the-Fire Embers-of-the-Fire marked this pull request as ready for review April 1, 2026 07:18
@Embers-of-the-Fire Embers-of-the-Fire changed the title fix(repl): clear hidden comprehension slots between MontyRepl turns fix(repl): Add local/global store operation in comprehension expressions Apr 1, 2026
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.

MontyRepl.feed_start() corrupts state on comprehension patterns, causing TypeError: object is not callable on next turn

2 participants