Repository navigation
A const of an owning let has a slot of its own (#454) - #467
Merged
Merged
Conversation
Under rc, `let a = new C(); const b = a; a = new C();` freed the first object while `b` still pointed at it. A `const` whose initializer is a plain value is folded: the name is that value, with no storage. Here the value is a read of `a`'s slot, so `b` held no reference of its own, and reassigning `a` released the only one. processConstRef now gives such a const identity storage, as it already does for arrays and Shared<T> handles: a const of anything that owns a block, read (through any casts) out of a local that owns what it holds (OWNED_LOCAL_ATTR_NAME - a declared `let`, a parameter; not a literal's temporary slot). It then takes its own reference, as a `let` does, in every model. A const of a const, a call or a field is unchanged. Under own, `b` is now a borrow of `a` rather than a later read of its slot, so own_err_const_alias_field is rejected for what it is - `'a' is moved here while 'b' borrows it` - and its two expectations are updated. The own corpus is unchanged (453 / 593, 451 with --opt). Test: 00const_of_let (compile and JIT, and in the rc/none corpus): a class, a string and an array const of a let, a const of a parameter, and a loop, each read after allocations of the same size have reused anything freed. It failed under rc before the change. Fixes #454. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # tslang/test/tester/CMakeLists.txt
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.
Fixes #454.
Under rc,
let a = new C(); const b = a; a = new C();freed the first object whilebstill pointed at it.The cause: a
constinitialised with a plain value is folded, so the name is that value and has no storage. Here the value is a read ofa's slot, sobheld no reference of its own, and reassigningareleased the only one.processConstRefnow gives such aconstidentity storage, as it already does for arrays andShared<T>handles. The rule covers aconstof anything that owns a block, when it is read (through any casts) out of a local that owns what it holds, meaningOWNED_LOCAL_ATTR_NAME: a declaredletor a parameter, not a literal's temporary slot. Theconstthen takes its own reference, as aletdoes, in every model. Aconstof aconst, a call or a field is unchanged.Under own,
bis now a borrow ofarather than a later read of its slot. Soown_err_const_alias_fieldis rejected for what it really is,'a' is moved here while 'b' borrows it, and its two expectations are updated.Tests
New
00const_of_let.ts, registered as compile and JIT and in the rc/none corpus. It covers:constof alet;constof a parameter;Each is read after allocations of the same size have reused anything freed. It failed under rc before the change.
The own corpus is unchanged: 453 / 593 plain, 451 / 593 with
--opt, with the same files.Full Release ctest: 3636/3637. The one failure is
test-compile-gc-defaultlib-collector, the known local LNK2005 against the stale installed default library, which fails on main the same way.🤖 Generated with Claude Code