Give const bindings with bound-method fields (generators) real identity storage#244
Merged
Merged
Conversation
5 tasks
ASDAlexander77
added a commit
that referenced
this pull request
Jul 18, 2026
… value tuple (#245) Object literals in this compiler compile to value-typed tuples by default, even though the generator wrapper ({step, next()}) has mutable identity that must be shared across aliases. This meant passing a generator to a function, capturing it in a closure, or reassigning it (const b = a) all silently copied its state instead of aliasing it. Add InternalFlags::BoxAsObject to mark the synthetic wrapper literal built by buildGeneratorWrapperDeclaration, and heap-box it (NewOp + StoreOp + CastOp, the same recipe castTupleToInterface already uses) into ObjectType instead of leaving it as a tuple. Property access on ObjectType already emits a PropertyRefOp directly on the pointer, so .next() now mutates shared storage for every alias. Supersedes the const-storage-only fix in #244 for generators specifically, and fixes the parameter-aliasing bug that fix explicitly left open. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This was referenced Jul 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
boundRefMaterializedCacheworkaround: aconstbinding whose type is a value-typed tuple aggregate with a bound-method field (currently only the generator wrapper'snext()) now gets real storage (an alloca) at declaration time, exactly likelet— instead of lazily discovering the need for a ref cache at the first property access.tslang/docs/const-let-storage-design.md.resolveIdentifierAsVariableonly loads through a variable's ref whengetReadWriteAccess()is set, which previously never mattered forconst(no storage). Now that identity-storage consts have storage, that flag is also set for them, fixing a crash where call sites got the raw ref/pointer instead of the loaded value.Test plan
cmake --build ... --target tslang --config Debug)00generator_manual_next.ts,00generator_manual_next2.ts,00generator7.tspass via JITctest -R "^test-jit-"/-R "^test-compile-",-j8)🤖 Generated with Claude Code