Box the generator wrapper as a heap-allocated ObjectType instead of a value tuple - #245
Merged
Merged
Conversation
… value tuple
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>
2 tasks
ASDAlexander77
added a commit
that referenced
this pull request
Jul 18, 2026
… tuple cast (#248) Generalizes the generator-wrapper's BoxAsObject boxing (PR #245) toward supporting any object literal with methods: getFields now looks through ObjectType to its storage type, object spread ({...obj}) handles a boxed ObjectType source, and castTupleLikeVariants gained an ObjectType->tuple unboxing cast. No behavior change for existing code paths; verified via generator objects (the only literals boxed today) in new test 00object_boxed_infra.ts. Full suite: 352/352 JIT + 356/356 AOT. See docs/object-literal-boxing-design.md for the full staged plan (this is PR A of three). Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2 tasks
ASDAlexander77
added a commit
that referenced
this pull request
Jul 18, 2026
…ype (#249) Generalizes the generator-wrapper's BoxAsObject boxing (PR #245, PR #248) to any object literal with a method or accessor: mlirGen(ObjectLiteralExpression) now boxes whenever oli.methodInfos/methodInfosWithCaptures is non-empty, not just synthetic wrappers carrying the flag. Every alias of such a literal (second binding, parameter, closure capture, array/object element) now shares mutable state, matching JS semantics; pure-data literals keep value (struct) semantics. The flip itself is two lines, but exercising ObjectType through every path that previously only saw tuples for method-bearing literals surfaced five more missing ObjectType cases, each fixed: - boxing seed value routed through mlirGenCreateTuple instead of the generic cast pipeline, avoiding a spurious "losing this reference" warning - TupleGetSetAccessor's get/set now handles a pointer (ObjectType/RefType) operand via PropertyRefOp+LoadOp, not just ExtractPropertyOp - castObjectToInterface gained the same field-type-coercion fallback castTupleToInterface already had (e.g. si32 vs number) - element access (obj[Symbol.x]) dispatches ObjectType like Class/Interface - generic intersection-type merge (D & M) and parameter inference look through ObjectType's storage type, same as MLIRTypeHelper::getFields New test 00object_ref_semantics.ts covers alias mutation through bindings, parameters, closures, array/object elements, accessors, globals, and conditional-expression merges. Full suite green: 353/353 JIT + 357/357 AOT. See docs/object-literal-boxing-design.md (PR B of three staged PRs). Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
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
{step, next()}, built bybuildGeneratorWrapperDeclaration) has mutable identity (stepadvanced by.next()) but was still a value tuple — so 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.InternalFlags::BoxAsObjectflag and heap-box it intomlir_ts::ObjectType(NewOp+StoreOp+CastOp— the same recipecastTupleToInterfacealready uses) instead of leaving it as a tuple. Property access onObjectTypealready emits aPropertyRefOpdirectly on the pointer, so.next()now mutates shared storage for every alias.for...of/yield*/destructuring needed no changes — they discovernextthrough generic property access, which already handlesObjectType.docs/generator-object-wrapper-design.md(chosen approach, implemented) anddocs/generator-param-by-ref-design.md(a RefType-parameter alternative that was analyzed and rejected for its function-type-equality blast radius — kept for the record).Test plan
00generator_manual_next.ts,00generator7.tspass via JIT00generator_manual_next2.tsextended with permanent regression coverage for parameter aliasing (caller observes callee's.next()calls), closure-capture aliasing, and plain-assignment aliasing — all passthistype mismatch this fix addresses)🤖 Generated with Claude Code