Skip to content

-mm=own: no CSE ahead of inference; two equal concatenations are two owners - #756

Merged
ASDAlexander77 merged 2 commits into
mainfrom
own-no-cse-before-inference
Oct 30, 2026
Merged

ASDAlexander77 merged 2 commits into
mainfrom
own-no-cse-before-inference

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

CSE before own inference merges two allocations into one owned value.

Under --opt (which --emit=jit turns on; AOT emits leave it off by default), transform.cpp added createCSEPass() to optPM, the FuncOp nest that runs before own's inference. CSE treats a string concatenation as pure, so

const s1 = "Hel" + "lo";
print(c.has(s1));      // has(a: any)
const s2 = "Hel" + "lo";
print(c.has(s2));

became one value with two named const owners, and inference stopped with 'this value' takes a second reference. Boxing into any was never the problem: the retain merely sits on the Cast -> any. One const alone always compiled.

Fix: under own, CSE does not run. Running it after inference instead would turn the two owners into two releases of one allocation, a double free. rc, gc and none keep CSE: their retains and releases stay paired.

Test: own/own_equal_strings_into_any.ts covers two equal concatenations each boxed into an any argument once, plus a loop where both are read after a churn. It runs under own (jit and compile, plus the no-counting check) and under rc/gc/none. Without the fix, the own JIT run fails with the error above.

Full release ctest: 100% passed, 0 failed out of 6458.

🤖 Generated with Claude Code

ASDAlexander77 and others added 2 commits October 30, 2026 22:41
…owners

Under --opt (on for --emit=jit) CSE was added to the FuncOp pipeline that runs before
own's inference. It merged two equal allocations, e.g. `const s1 = "Hel" + "lo"` and
`const s2 = "Hel" + "lo"`, into one value with two named owners, and inference refused it:
"'this value' takes a second reference". CSE after inference would leave two releases of
one allocation, so under own it does not run; rc, gc and none keep it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 348a776 into main Oct 30, 2026
0 of 2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the own-no-cse-before-inference branch October 30, 2026 23:09
ASDAlexander77 added a commit that referenced this pull request Oct 30, 2026
The merges of #754 and #756 each added their test to the own `foreach` lists without dropping the
line it replaced, so `tslang/test/tester/CMakeLists.txt` closed the list early and CMake failed to
configure ("Parse error. Expected "(", got identifier with text "own_callback_cast""). Both lists
now hold each name once: own_equal_strings_into_any, the spec 72/73 tests and own_rest_keeps_declared.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant