Repository navigation
rc: an interface-typed global initialized with a class object holds it - #656
Merged
Merged
Conversation
`let a: I = K.w` (a static field, another global, a field or an element) gave the global no count of its own: claimGlobalInitializers looked through casts and unions to the value a global is given, but not through `ts.NewInterface`, the view a class object takes for an interface-typed global. Giving either side a new value freed the block the other still read (rc printed 999 for 1). A call's or a `new`'s reference (`let a: I = mk()`, `let a: I = new V(8)`) was given back as a discarded temporary at the end of the initializer, so the global was born pointing at freed memory; under own too (`let a: I = mk()` read a freed block). The initializer now looks through `ts.NewInterface` to the object. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 23, 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.
Follow-up 9 from the own-raytrace rulings ("an interface-typed global given another global's value is never counted").
Bug
let a: I = K.wgave the global no count of its own under rc:claimGlobalInitializerslooked through casts and unions to the value a global is given, but not throughts.NewInterface, the view a class object takes for an interface-typed global. Giving either side a new value freed the block the other still read (a = new V(3)freedK.w; rc printed 999 for 1).Wider than filed:
let a: I = G / h.v / arr[0]) andconst a: I = G(rc);let a: I = mk()andlet a: I = new V(8): the call's or thenew's reference was given back as a discarded temporary at the end of the initializer, so the global was born pointing at freed memory - under rc and own (own exited 127 on main).Fix
claimGlobalInitializerslooks throughts.NewInterfaceto the object (getThisVal()), so a fresh object is claimed and a read gets its retain.Tests
tests/00global_interface_initializer.ts(gc, rc, none; AOT + JIT): each source and each interface global given a new value, after allocations of the same size.own/own_global_interface_fresh.tsunder own, rc, none and gc.a call's result(exit 127), own fails the same.Verified
MALLOC_PERTURB_=165 MALLOC_CHECK_=3: 14/14.Found, not fixed here
let opt: I | null = flag ? mk(5) : nullreads garbage under gc and rc: theC | null->I | nullconversion is a plain cast with nots.NewInterface.🤖 Generated with Claude Code