Skip to content

-mm=own: a linked list compiles (walk, push, append, pop, unlink); readiness page - #869

Merged
ASDAlexander77 merged 1 commit into
mainfrom
own-linked-structures
Nov 16, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
own-linked-structures

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

What

Under -mm=own, a singly linked list whose nodes own their next was refused in every method a newcomer writes first. It compiles now:

  • Walk: for (let c = this.head; c; c = c.next) and the while form, over this, a parameter's list or a local list.
  • Push: n.next = this.head; this.head = n.
  • Append and truncate: c.next = n or c.next = null after the walk.
  • Pop and unlink: this.head = this.head.next, c.next = c.next.next, also through const h = this.head when h is read before the assignment.

It also adds docs/own-readiness.md: where the model stands, with measurements (corpus coverage, fuzzing, the tier 3 exit criteria, what is left).

How

Four rules in the inference pass (design log, section 82):

  1. A let given only borrows owns nothing (chainOf). What is read through it lasts as long as what the let borrowed, so c = c.next in a loop no longer ends its own borrow. The declaration is a kill for an assigned borrow's uses.
  2. A field of the value read, overwritten, frees nothing above it (checkPlaceRead). Through a let, only when the let walks down from there on: every later assignment reads out of what it holds, through owning places.
  3. The refill may store the object the taker is a field of (refilledFieldTakeOf): rc's retain of the refill's value is let through.
  4. A value taken out of the object its place holds (splicedFieldTakeOf). The store's release frees the object, so its field is given up right before it.

Rule 4 needs a new op, ts.TakeOutOfField(object, field). Emptying the field is right when the object is freed. An object an append-only global keeps too is not freed, and emptying its field showed (KEEP[0].next was null under own, not under gc). The op empties a mortal object's field; an immortal object keeps it, and the value is made immortal.

Still refused

  • The popped node used after the assignment (this.head = h.next; return h.v): read it first.
  • this.head = new Node(v, this.head).
  • A walk that assigns a parameter (n = n.next).
  • A recursive insert that gives its parameter back (t.l = ins(t.l, v)).

Tests

  • 00linked_list, 00linked_list_kept: gc, rc, none and own, JIT and compiled; also -noopt under own.
  • Seven own_err_list_* expected-error cases: a drop inside the walk, a call that clears the list, a look-ahead alias, a let that may walk back up, the popped node used after, a next kept twice, a refill from a parameter's node.

Verification

Check Result
Windows ctest, Release 7497 of 7497
Own tests on Linux (WSL), MALLOC_PERTURB_ 2217 of 2217
Corpus sweep under own, against main no file newly refused, one newly accepted
mm fuzzer, 1,000 seeds no mismatch
native_ts_graphics own build, against main same 6 of 276 units fail with both
Default library, own, release and debug builds, tests pass
8,000 reads through one borrowing let 63-69 s before, 7.4-7.8 s now

For the reviewer

  • The fuzzer's seed 930591 hangs the compiler under own. main hangs on it too, so it is not from this change; it is not fixed here.
  • Not run: the full Linux ctest (only the own tests), wasm and Android.

🤖 Generated with Claude Code

…adiness page

A singly linked list whose nodes own their `next` was refused in every method:

- A `let` given only borrows owns nothing: what is read through it lasts as long
  as what the `let` borrowed, so `c = c.next` in a loop no longer ends its own
  borrow. Its declaration is a kill for an assigned borrow's uses.
- A field of the value read, overwritten, frees nothing above it: `c.next = n`
  and `c.next = null` after a walk, when the `let` only walks down.
- `n.next = this.head; this.head = n;` is the move of a field with the source
  refilled right after (TSLANG 49): rc's retain of the refill's value is let through.
- `this.head = this.head.next` and `prev.next = prev.next.next` take the value out
  of the object the place holds, which the store's release frees. A new op,
  ts.TakeOutOfField, gives the field up: emptied in a mortal object; an object an
  append-only global keeps too keeps it, and the value is made immortal.

Still refused: the popped node used after the assignment, `this.head = new
Node(v, this.head)`, a walk that assigns a parameter, a recursive insert that
gives its parameter back.

docs/own-readiness.md says where the model stands, with measurements; spec 82.

Tests: 00linked_list, 00linked_list_kept (every model, and -noopt under own),
seven own_err_list_* cases. ctest 7497/7497 on Windows; the own tests on Linux
under MALLOC_PERTURB_ (2217/2217); the corpus, 1,000 fuzz seeds and
native_ts_graphics' own build have no file newly refused; the default library's
own build passes its tests.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 8f1ec8d into main Nov 16, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the own-linked-structures branch November 16, 2026 09:14
ASDAlexander77 added a commit that referenced this pull request Nov 16, 2026
…ive tree insert and parameter walks compile (#870)

* -mm=own: a node made from the old head, a recursive tree insert, a walk that assigns its parameter; a walk cut ahead of itself is refused again

Three linked-structure shapes #869 left refused now compile, and a hole #869
opened is closed:

- A field given to a call that keeps it, refilled from the call's result
  (`this.head = new Node(v, this.head)`, `t.left = insert(t.left, v)`): the
  field is given up before the call (ts.TakeOutOfField) and the refill's
  release stays. Only for a call that never throws, whose other arguments hold
  no heap block or are the object `new` made.
- `__own_no_throw`: the signature pass marks calls whose callees (and all they
  call) have no throw. Without it a throwing constructor caught by a caller
  would empty the list where gc and rc keep it.
- A parameter (or a `let` given one) whose every assignment reads out of what
  it holds (`n = n.next`) borrows the caller's value instead of being kept.
- Fixed: `const nx = n.next; n.next = null; n = nx` compiled since #869 and
  read freed memory at run time. A walking `let` frees nothing above the value
  read only where it is read after being given that value.

Spec 83; the user guide and the readiness page are updated.

Tests: 00linked_list_build (every model, and -noopt under own), and
own_err_list_unlink_walk, _cut_through_alias, _push_ctor_throws,
_push_through_this, own_err_tree_field_given_twice, own_err_param_walk_mixed.
ctest 7513/7513 on Windows; own and list tests on Linux under
MALLOC_PERTURB_ with tcache off 2233/2233; corpus: no file newly refused
(00for_condition_narrowing newly compiles, output as gc's); 500 fuzz seeds
(936 programs) no failure; native_ts_graphics' own build unchanged; a 20M
iteration churn of the new shapes stays flat in memory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* -mm=own: no field given to async code; a walking parameter swapped stays kept; the in-step cut pinned

Review follow-ups to the previous commit:

- __own_no_throw also counts ops of the async dialect as throwing (an await
  rethrows what the awaited body threw).
- walksDownOnly accepts only reads, rc's counts and the debugger's record
  besides its walk-down stores: a swap or a given-away address keeps the
  parameter kept.
- own_err_list_cut_in_step pins the ordering half of the walk-cut fix:
  `c.next = (c = c.next, null)` crashes at run time on main.
  own_err_list_cut_through_alias was refused before #869 too.
- The user guide and the readiness page say the call must be one of the
  same module.

ctest 7514/7514 on Windows; Linux own and list tests 2234/2234 under
MALLOC_PERTURB_ with tcache off; corpus unchanged but the two crash shapes;
the default library's own build 219/225 in all four configurations (6
skipped by design).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

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