Fix crash lowering a global const object literal with a mutating method - #246
Merged
Merged
Conversation
…and add regression test
This was referenced Jul 18, 2026
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
const obj = { ..., method() { this.x = ... } }crashed the compiler (0xC0000005) at JIT materialization time.letat global scope andconstdeclared locally inside a function were both unaffected, which is why this went unnoticed until now.GlobalOpLoweringdecides whether a global needs a runtime constructor function or can be a plain static LLVMconstantinitializer by walking its initializer region against a fixed allowlist of op kinds — but had no case for aConstantOpwhoseTupleType/ConstTupleTyperesult has a bound-method field. Such a field lowers viaLLVM::AddressOfOp+LLVM::InsertValueOp(LLVMCodeHelper::getTupleFromArrayAttr), which is not valid inside a static global initializer region — only inside real code (a function) — so the global ended up with a corrupted struct layout and crashed on the first indirect call through it.TupleType/ConstTupleTypeconstants with a bound-method field (MLIRTypeHelper::hasBoundMethodField, from Give const bindings with bound-method fields (generators) real identity storage #244), not "any constant referencing a symbol." An earlier, broader attempt keyed on "does the constant's attribute contain aFlatSymbolRefAttranywhere" also caught MSVC RTTI/EH type-descriptor globals (e.g.??_R0PEAD@8, which reference thetype_infovtable symbol) that were already lowering correctly as static data — forcing those through the constructor path broke JIT symbol materialization for the whole module. That regression was caught and fixed before this PR by narrowing the check to the type-based predicate.Test plan
constobject with a mutating method) now runs cleanlytest/tester/tests/00global_const_object_method.ts(compile + JIT)00try_finally_break_continueand 11 others) is resolved🤖 Generated with Claude Code