Skip to content

-mm=own: assigned parameters are kept, delete ends an owner; deterministic constant order - #868

Merged
ASDAlexander77 merged 6 commits into
mainfrom
own-delete-and-param-assign
Nov 15, 2026
Merged

ASDAlexander77 merged 6 commits into
mainfrom
own-delete-and-param-assign

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

-mm=own: assigned parameters and delete

-mm=own refused two constructs with "yet" errors, and those stopped 14 of the 621 corpus files.

A parameter the body assigns now gets a local of its own for every type that owns a block. Before, only a string or a Shared<T> got one, as under rc (#512). The local owns what it holds, so the function keeps the parameter, by the same rules as a parameter stored in a field, and no ownership pass changed:

  • A caller that reads the argument after the call is told it was moved (own_err_param_assigned).
  • An exported function, or one reached through an interface, needs @keeps("x"), the same as a function that stores its parameter (own_err_param_assigned_exported).
  • x = n of a local moves n in. This was the error Two fuzz rounds: own keeper literal elements, own parameters given a local's value, rc arguments read through a parameter's object #752 added, and it now works (fromLocal in own_param_assigned).
  • A parameter that a nested function mentions keeps the old error path, so a closure that captures and assigns it still says "a captured parameter and cannot be assigned".
  • Still refused: a parameter a generator assigns, and x ??= v (a merge).

delete under own emits no ts.Delete:

  • When the place owns its value (a local, a field, an element or a global), delete is written as the assignment that clears it. The passes already follow that: a local whose value moved frees nothing, and a borrow of it ends (own_err_delete_borrowed).
  • A value that no storage holds is released where its block ends.
  • delete of a parameter, or of a local that owns nothing, is an error (own_err_delete_param).

Corpus under own: 466 → 473 of 621 compile. New tests:

  • own_param_assigned, under own, rc and gc.
  • own_delete, under own and rc. Not gc: there, a delete after a move frees what the field holds.
  • The 7 corpus files that only these two errors stopped, now run under own, JIT and AOT (test-*-own-flipped-*).

Docs: docs/own-memory-model.md gains a section, and the spec gains §81.

Semantics worth a look: an assigned parameter now takes the argument away from the caller. That is consistent with kept parameters elsewhere, but it is a choice.

Compile output is the same from run to run

RelocateConstantPass collected the constants it moves into a SmallPtrSet and recreated them in the set's iteration order. Above 16 entries that set is a hash table keyed by address, so constants, and the string globals lowered from them, came out in a different order on each run. 00param_assigned_owned.ts gave 4 different IR files in 8 compiles. It is the variation docs/compile-time-work.md had written off as "not a finding".

The constants are now kept in a vector in program order. I compiled that file and the ray tracer 12 times each, with and without --opt, under gc, rc and own, and every combination gave a single output.

Testing

  • Windows Release, full suite on the first commit: 7471 tests, 9 failures.
    • 4 were my regressions in own tests, fixed in the follow-up commit.
    • 5 are test-borrow-facts-*, a known environment issue on the development machine (stale CMAKE_AR toolset).
  • A second full run on the final commits (before merging main back in) is still in progress.
  • The default library's src/lib.ts compiles under own and rc.
  • Not run yet: Linux (WSL) and an mm_fuzz round.

🤖 Generated with Claude Code

ASDAlexander77 and others added 6 commits November 15, 2026 19:29
…compiler crashed about once in 500 runs)

OwnershipInferencePass runs on the functions of a module at once, on several
threads. For a field read through an interface whose value leaves its function
(`function dirOf(r: R) { return r.dir; }`) releaseCellReads asks accessorFiller
whether a class fills the field with a getter, and accessorFiller looked for the
accessor cell's global with module.walk - which goes into the body of every
function of the module, among them the ones the other threads were putting
releases in and erasing reads from at that moment. It read an operation list as
it was relinked, and the compiler ended with an access violation: about once in
300 to 700 compiles of test/tester/own/own_field_chain_let.ts, and once in a
run of the suite.

It now looks at the module's own operations only: that is where globals are,
and no function's pass changes that list.

Found from a crash dump: two worker threads in releaseCellReads, both in the
module walk. The compiler from before the fix failed 2 of 1,000 and 1 of 725
compiles of that test; with the fix, 0 of 4,000. Release suite on Windows x64;
LLVM IR of the 190 tests of test/tester/own that compile without the default
library is unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Two refusals that said "yet", which stopped 14 of the 621 corpus files.

A parameter the body assigns starts a local of its own for every type that owns
a block, as rc does (it did under own only for a string and a Shared<T>). The
local owns what it holds, so the function keeps the parameter and its callers
give the argument up, by the rules of a parameter stored in a field; no pass
changed. `p.length = n` starts a local only for a string.

`delete place` is written as the assignment that clears the place when the
place owns its value; a value no storage holds is released where its block
ends; a parameter or a local that owns nothing is an error.

Corpus under own: 466 -> 473 of 621.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ogram order

RelocateConstantPass gathered the constants it moves to the top of a function
in a SmallPtrSet and recreated them in the set's iteration order. With more
than 16 of them the set is a hash table keyed by address, so the order - and
with it the order of the string globals lowered from them - changed from run
to run: 00param_assigned_owned.ts gave four different LLVM IR files in eight
compiles (the same lines in another order). They are now kept in a vector in
the order the function holds them; 12 compiles each of that file and the ray
tracer, with and without --opt, under gc, rc and own, give one output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ests follow the new rule

A parameter a nested function mentions gets no local of its own under own, so a
closure that captures and assigns it is still "a captured parameter and cannot
be assigned" rather than a kept parameter. own_err_delete compiles now (own_delete
covers it), and own-mlirgen-matches-rc checks moves and field stores instead of
delete, which own now writes as a clearing assignment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 363b13c into main Nov 15, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the own-delete-and-param-assign branch November 15, 2026 20:38
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