Repository navigation
own: concatenations, constructor arguments and this-returning chains in global initializers (TSLANG 85) - #860
Merged
Merged
Conversation
The inner sum of `"a" + "b" + "c"` in a global's initializer is a temporary the initializer makes, reads and gives back itself. moveIntoGlobals took its retain for a second reference the global takes. A fresh string retained once and released once, read only by a concatenation, now keeps its release and loses the retain, as in a function body. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…a global's initializer (TSLANG 85)
`const H = new Holder("x" + "y")` was refused ("takes a second reference"): the sum is
a call argument, which moveIntoGlobals did not accept. ownGlobalInitializerCalls,
after the facts, already moves it into a callee that keeps it, or leaves its release.
`const B = new Bag().add("m").add("n" + "o")`, with `add(): this`, was refused as a
borrow. A method call whose result is its own `this` (spec 78), on an object the
initializer made and gives to nothing after but its releases, now returns that object,
the global's own, as transferTemporaryReceivers does in function bodies. A chain on
another global's object, and a function returning its parameter (#638), stay errors.
Co-Authored-By: Claude Opus 5.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.
Fixes TSLANG_ISSUES 85, plus two related
-mm=owngaps in a global's initializer found while fixing it.1. Three or more joined strings (
const EXPORTS = "Raygen,Miss," + "Hit," + "Group"in native_ts_graphics'sakura_forest_ser.ts) were refused, "takes a second reference". The inner sum is a temporary the initializer makes, reads and frees.moveIntoGlobalstook its retain for one the global takes. A fresh string retained once and released once, read only by a concatenation, now loses the retain and keeps its release, as in a function body.2. A joined string given to a call (
const H = new Holder("x" + "y")) was refused the same way, even with two strings. Such an argument now passes that check.ownGlobalInitializerCalls, which runs after the facts, already moves it into a callee that keeps it, or keeps its release after a callee that only reads it.3. A chain returning
thison a new object (const B = new Bag().add("m").add("n" + "o"), withadd(): thisor an inferredreturn this) was refused as a borrow, even with a plain literal. Function bodies take the object over (spec 78), but only for calls in functions. The global step now does the same for a method call whose result is its ownthis, on an object the initializer made. That object becomes the global's own and its releases go.Still refused: a chain on another global's object (
const A = SHARED.add("q"), a second owner), a function returning its parameter (id(new V(1)), #638), and a call result that borrows a concatenated argument.Tests:
tests/00tslang_issue_85.ts, every model, JIT and compiled.own/own_err_global_concat_borrowed.tsandown/own_err_global_chain_other_global.ts.ctest -R "own|tslang_issue|global|string|chain|json"passed 2710/2710. The new test also passes under own as an exe, optimized and with--di --opt_level=0.🤖 Generated with Claude Code