Skip to content

-mm=own: a class family spans one class hierarchy, not every class with that slot - #717

Merged
ASDAlexander77 merged 1 commit into
mainfrom
own-family-per-hierarchy
Oct 28, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
own-family-per-hierarchy

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

-mm=own: a class family spans one class hierarchy

Under -mm=own, any program that made both an Array<string> and an Array<int> (or
Array<number>) failed to compile, with errors inside DefaultLib's Array<T>:

lib.generics.ts: error: 'this value' borrows the result of '___Array.find<!ts.string>' and cannot be stored, returned or captured
note: 'Array<!ts.string>.find' could return a borrow or keep a parameter, but an override in its class family disagrees

OwnershipSignaturePass gives a virtual call the facts every member of its family agrees on. A
family was every function at that vtable position under that method name, in any class
(collectClassVTables). Two specializations of one generic share every slot and name, so
Array<string>.find (returns a borrow) and Array<int>.find (returns a number) were one
family, disagreed, and both lost their facts - though neither class extends the other and no
call through one can reach the other.

Families are now keyed by the root of the class's chain of bases as well (familyRoot: a base
is the first field of a class's storage, as extendsClass reads it). familyOf looks a call up
by its callee's class's root. A slot one of whose members has a root not known here (storage not
seen, or a chain deeper than 64) stays a single family, as every slot was before. The class
storages are now collected before the vtables.

Overrides within one hierarchy are unchanged: own_err_borrowed_result_family (an override that
returns a new object where its base returns a field) still errors.

Tests

  • own/own_generic_specializations.ts: Box<string>.find and Box<int>.find returning a
    helper's result. Fails under own without the fix (string-only passes); runs under own, rc, gc
    and none, plus own's no-counting check.
  • ctest Release: 6091/6091 passed.
  • DefaultLib tests.ps1: gc, rc, none, own all pass in all four passes. new Array<string>("a", "b")
    next to new Array<number>(10) compiles and runs under own.

🤖 Generated with Claude Code

…th that slot

A virtual call's family was every function at its vtable position under its
method name, in any class. Two specializations of one generic class -
Array<string> and Array<int> - were one family, though neither extends the
other: `find` returns a borrow for one and a number for the other, the family
disagreed, both lost their facts, and any program with both failed under own
("'this value' borrows a field and cannot be stored, returned or captured").

Families are now keyed by the root of the class's chain of bases as well
(familyRoot, through the class storages, now collected before the vtables). A
slot with a member whose root is not known stays one family, as before.

Test: own_generic_specializations (Box<string> and Box<int>).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit fa3facd into main Oct 28, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the own-family-per-hierarchy branch October 28, 2026 16:15
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