Skip to content

-mm=own: values merged by ?: move; constant merges; an optional record's field is read - #873

Merged
ASDAlexander77 merged 3 commits into
mainfrom
own-not-yet
Nov 16, 2026
Merged

ASDAlexander77 merged 3 commits into
mainfrom
own-not-yet

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Readiness item 3, the "not yet" messages: four shapes from the corpus that own refused with "takes a second reference" or "merged from several branches", though their meaning under own is clear.

Shape Before Now
return set ? n : undefined, h.n = set ? n : null of an owned local "takes a second reference" n moves on the branch that chooses it; it is released on the other branch
return first ? shared : other (globals never reassigned), typeof x === "string" ? 1 : "one" "merged from several branches" the merge owns nothing; the retain goes
object(true)?.v == "x" (an optional object literal result) "takes a second reference" the field is read, not taken
let pick: Node | null = on() ? mk(3) : null at the top level "the initializer of global 'pick' takes a second reference" compiles; null is constant data

How

  • A local moved through a merge. The branch carrying n into the merge's block argument now acquires it, when rc retains the merged value in that block (mergeRetainOf). That retain is the reference n moves into. The release of n on the branch that doesn't choose it goes on that edge, using the existing TSLANG 81 edge releases.
    • This applies only when every way into the merge brings null, undefined or a fresh value. A borrow coming in (set ? n : h.k) stays refused, because it would be given an owner.
    • Using n after the merge is reported as a use after a move.
    • set ? n : m with two locals lowers to arith.select, which has no edge to release the other value on, so it stays refused.
  • A merge of what nothing owns. When every way in brings a literal, null, a read of an immortal global, or another such merge, a retain of the merged value takes nothing (mergeOwnsNothing).
  • An optional object literal's field. fieldOnlyRead now follows the merge that ?. makes with undefined, so a field that is only read is a read of the record.
  • A global initializer. isConstantData sees null and undefined through their casts, and a global initializer's retain of constant data takes nothing.

Corpus

Every file in tslang/test/tester/tests, compiled with --opt_level=3 under gc and under own:

Before After
Compile under own (of 890 that compile under gc) 717 724
"takes a second reference" 24 19
"merged from several branches" 7 5

The seven newly accepted files also run correctly under own. No file went from accepted to refused.

Validation

Check Result
Windows ctest 7620/7620
Linux own, shared, callback and merge tests (MALLOC_PERTURB_=165, tcache off) 2766/2766
Default library under own, gc, none and rc everything passes; the only tests not run are those skipped by design
Differential fuzzer, seed 920000 ×500 925 programs, 3 crashes, all older than this branch (below)

All three fuzzer crashes give identical IR with main's compiler, so they are not regressions; they come next as their own batch:

  • Seed 920187 (own): a closure in a try/finally that is never used captures a local; the local is freed early and read afterwards.
  • Seed 920048 (own): a parameter reassigned inside a call argument, f1(p5, (p6 = mk(6), p6)). It crashes only under Linux's poisoning allocator.
  • Seed 920443 (rc): a global reassigned in an argument while a finally block holds an interface view of it.

Spec section 86 records the rules. docs/own-readiness.md has the new measurement and the new shape rows.

🤖 Generated with Claude Code

ASDAlexander77 and others added 3 commits November 16, 2026 14:48
…s read

Three "takes a second reference; cannot prove a move or a borrow here yet" shapes of the
corpus (readiness item 3):

- `return set ? n : undefined` (and `h.n = set ? n : null`) of an owned local: a branch into
  a merge whose value rc retains in its block now acquires the value (mergeRetainOf); the
  retain is the reference it moves into, and the release on the way that does not choose it
  goes on that edge (TSLANG 81's valueUnmovedEdges). Only when every way in brings null,
  undefined or a fresh value: a borrow brought in stays refused.
- `object(true)?.v == "x"`: a field of an optional record merged with undefined and only read
  is a read of the record (fieldOnlyRead follows the merge), not a taker of the field.
- `let pick: Node | null = on() ? mk(3) : null` at the top level: null seen through its cast
  is constant data, and a global initializer's retain of constant data takes nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`return first ? shared : other` of two immortal globals, and `let v = typeof text ===
"string" ? 1 : "one"`, were refused as "merged from several branches; cannot prove which
one owns it yet". When every way into the merge brings data (a literal, null), an
immortal global's read or such a merge, the merged value owns nothing, and a retain of it
takes nothing (mergeOwnsNothing).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 40a22da into main Nov 16, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the own-not-yet branch November 16, 2026 15:44
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