Skip to content

-mm=own: a borrow ends only where what it reads is overwritten or freed (TSLANG 236-240) - #1129

Merged
ASDAlexander77 merged 3 commits into
mainfrom
fix-own-borrow-precision
Dec 4, 2026
Merged

ASDAlexander77 merged 3 commits into
mainfrom
fix-own-borrow-precision

Conversation

@ASDAlexander77

@ASDAlexander77 ASDAlexander77 commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

Fixes TSLANG 236-240: under -mm=own, borrows were ended or refused where nothing they read could be overwritten or freed.

  • 236: a call's result that borrows one argument now records the places it is read through (__own_result_places, e.g. this.lists[0]). Only an overwrite of those places ends the borrow; this.bag = order no longer does.
  • 237: emptying an int[] (length = 0, splice, pop) ends no borrow, because its elements hold no object. xs.length = 0 through const xs = this.xs is accepted, as xs.pop() already was.
  • 238: a closure that does not escape borrows what a named const owns, the same way it borrows a parameter. An escaping closure still moves the const, and a later use is still an error.
  • 239: a call's result borrows only the arguments its facts name, so t.copy(pts[0]) (returning this) no longer counts as storing pts.
  • 240: a value given to the call that may free it takes a reference of its own across the call (USER RULING 11-27, TSLANG 219), whatever form the argument has. This also fixes an early free: the accepted B.add(PAINT.a); B.add(PAINT.a) form released B once too often, because the lent-back this result was released.

Tests

  • 00tslang_issue_236..240 run under gc, rc, none and own, AOT and JIT, with churn allocations between the steps.
  • Six new own_err_* refusals cover the overwrites that do end a borrow:
    • the result's field reassigned, popped, or its holder replaced;
    • an object array emptied, directly or by a callee;
    • a result that returns its argument.
  • Seven former own_err_* cases are now counted under the 240/238 rules. They become own_counted_* with rc's output.
  • own_err_callback_cast_field_drops is still refused, now at its caller.
  • Full local ctest: 10495 tests. The only failures were those eight expectation changes, now updated.

Found by the new fuzzer mode (mm_fuzz.py --classes, second commit)

  • --classes adds the shapes behind 236–240: methods that lend fields back, return this, replace or empty fields, free them and then read their argument, and stored callbacks.
  • Crash fixed (it predates this branch). A result lent back as this (k.self(), or k.add2(..) returning this) was treated as an object separate from k. So k.self().add2(k.first()) passed the check while add2 freed k.arr under the borrow. On the same 200 fuzz seeds, main's compiler crashes on 3 programs and this branch on none.
  • USER RULING 12-04. A value given straight to the call that may free it is counted across the call whatever form it has: a call's lent result (k.add2(k.first())) or a field or element read (k.run2(k.arr[0])).
    • Eight more own_err_* cases are now counted; they become own_counted_* and expect rc's output.
    • The separate-compilation tests (own-facts-objects, own-shared-no-drops) now check for a count without facts instead of a refusal.
  • New test 00tslang_issue_240_temps. A 1000-program --classes campaign found no wrong output, and all 3625 own-related ctest cases pass.

🤖 Generated with Claude Code

ASDAlexander77 and others added 3 commits December 4, 2026 18:56
…ed (TSLANG 236-240)

- 236: a call's result that borrows one argument records the places it is read
  through (__own_result_places), so a call that overwrites an unrelated field no
  longer ends the borrow.
- 237: emptying an int[] ends no borrow (its elements hold no object), and
  `xs.length = 0` through `const xs = this.xs` is accepted like `xs.pop()`.
- 238: a closure that does not escape borrows what a named const owns, as it
  borrows a parameter; it no longer moves the const.
- 239: a call's result borrows only the arguments its facts name, so
  `t.copy(pts[0])` no longer stores `pts`.
- 240: a value given to the call that may free it takes a reference of its own
  across the call (USER RULING 11-27, TSLANG 219), whatever form the argument
  has. Also: a lent-back result (`this`) of a counted named const is not
  released, which freed the receiver one release early.

Tests: 00tslang_issue_236..240 (gc, rc, none, own; AOT and JIT, with churn);
six new own_err_* refusals keep the overwrites that do end a borrow; seven
own_err_* cases now counted become own_counted_* (output = rc);
own_err_callback_cast_field_drops is refused at its caller.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	tslang/test/tester/CMakeLists.txt
…lent `this` reaches its object (TSLANG 240)

Found with a new memory-model fuzzer mode, mm_fuzz.py --classes (class K whose
methods lend fields back, return `this`, replace or empty fields, free them and
read their argument, and run stored callbacks).

- A call's result lent back as `this` (`k.self()`, `k.add2(..)` returning `this`)
  was taken for an object apart from `k`: `k.self().add2(k.first())` passed the
  check while `add2` freed `k.arr` under the borrow, and crashed (pre-existing on
  main). The owned-root test in dropsChain now follows a lent call result to the
  arguments it borrows, and argumentOwnsApart never calls one apart.
- USER RULING 12-04: a value given straight to the call that may free it is
  counted across the call whatever form it has: a call's lent result
  (`k.add2(k.first())`) or a field or element read (`k.run2(k.arr[0])`), not only
  a named local. A lent temporary takes a count; rc's release of it gives it back.

Tests: 00tslang_issue_240_temps (gc, rc, none, own; AOT and JIT). Eight own_err_*
cases now counted become own_counted_* (output = rc). own-facts-objects and
own-shared-no-drops check the count without facts instead of a refusal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit af51037 into main Dec 4, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the fix-own-borrow-precision branch December 4, 2026 21:21
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