Box object literals with methods/accessors as reference-typed ObjectType#249
Merged
Conversation
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>
3 tasks
ASDAlexander77
added a commit
that referenced
this pull request
Jul 18, 2026
The #246 isBoundMethodTupleConstant special case in GlobalOpLowering decided whether a global's initializer needs the constructor path based on whether any ConstantOp in it had a bound-method-shaped tuple field. Since PR #249 boxes every method-bearing object literal, such a literal's initializer always contains a NewOp (the boxing recipe), which the walk's existing NewOp case already forces onto the constructor path -- making the bound-method check redundant. Verified via a diagnostic probe at that call site across every test file (zero hits) before removing it for real. Investigated but did NOT remove needsIdentityStorage/boundRefMaterializedCache: contrary to the original plan (docs/object-literal-boxing-design.md), these are still load-bearing. Whenever a boxed literal is unboxed back into a plain tuple to match a declared/inferred type (annotated const, parameter, interface-cast fallback, generic intersection/inference), the resulting tuple's method field is still bound-method-shaped even though the tuple itself is a plain value -- that machinery is what makes calling through it work correctly instead of crash. Root-caused via site-tagged diagnostic probes across the full test corpus; documented in the design doc so this isn't re-attempted without re-deriving the same finding. Full suite green: 353/353 JIT + 357/357 AOT. 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
BoxAsObjectboxing (PR Box the generator wrapper as a heap-allocated ObjectType instead of a value tuple #245, infra in Add ObjectType-boxing infrastructure: getFields, spread, tuple cast #248) — design indocs/object-literal-boxing-design.md. This is the actual flip:mlirGen(ObjectLiteralExpression)now boxes any literal with a method or accessor asObjectType, not just synthetic wrappers carrying the flag.ObjectTypecases across the compiler (each already-existing code that only ever saw tuples for method-bearing literals before). All fixed:mlirGenCreateTupleinstead of the generic cast pipeline, avoiding a spurious "losing this reference" warning.TupleGetSetAccessor's get/set now handles a pointer (ObjectType/RefType) operand viaPropertyRefOp+LoadOp, not justExtractPropertyOp(which is restricted to value-typed structs).castObjectToInterfacegained the same field-type-coercion fallbackcastTupleToInterfacealready had (e.g. an inferredsi32field vs. an interface declaringnumber).obj[Symbol.x]) dispatchesObjectTypelike the existingClassType/InterfaceTypecases.D & M) and generic parameter inference look throughObjectType's storage type, same asMLIRTypeHelper::getFields.si32but whose declared parameter type isnumbercorrupts the write — reproduces identically on unmodified pre-PR-Bmain.Test plan
test/tester/tests/00object_ref_semantics.tscovers alias mutation through: plain re-binding, function parameters, closure capture, array elements, nested-object elements, accessors, a globalconstliteral (generalizes the Fix crash lowering a global const object literal with a mutating method #246 repro), and conditional-expression merges of two same-shape literals.ctest --test-dir <builddir> -C Debug -R "^test-jit-"/"^test-compile-"-j8) — includes the three tests that initially regressed (00interface_object5,00symbol,00type_aliases_in_generics), each root-caused via MLIR/LLVM IR diffs against the pre-flip baseline and fixed.🤖 Generated with Claude Code