Skip to content

-mm=own: a callback field keeps its family when other classes extend the class - #709

Merged
ASDAlexander77 merged 1 commit into
mainfrom
own-field-families-open
Oct 28, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
own-field-families-open

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Under -mm=own, a callback stored into a class's field now keeps its family when other classes extend the class. Before, any derived class opened the field's family, so this.f(a[i]) in the base class's method reached any function. The new spec section is 57, and the limits in the user doc are updated.

Changes

Same key through the base's storage. A derived class's object holds its base's storage as its first field. A derived class reaches the base's field there, through a ts.PropertyRef of !ts.ref<!ts.class_storage<@Base>>, and the family used to see no such access. Now fieldFamilyKey gives that access the same key as one through an object of the base class: the class's constructor and -1 - the field's position. So a derived class's reads of the field (this.f(v)) and stores into it (this.f = drain) count toward the field's family. onlyCalledValue also treats a store into such a field as passing the parameter on.

When the family stays closed. Neither the class nor any class extending it may be built by another module, and no object of a class on that chain may become an interface, any, object, unknown or a union. A cast from a derived class to its base (Sub to Walker) keeps the family closed. The base-class check already in the file moved into a static helper, extendsClass, that both places now use.

Tests

  • own_callback_extended: a derived class, and one two levels down, store into and call the base's field, with churn between steps. It runs under own, rc, gc and none, and own emits no counting. A repro of the same shape failed on main.
  • own_err_callback_extended_drops: a derived class stores a callback that replaces a global array, and the walk reads an element of it after the call. It errors at :16:13. With a harmless callback swapped in, the same file compiles.
  • Full ctest: 6047 of 6047 pass.
  • DefaultLib under own: 163 passed and 11 skipped out of 174, in release and debug, compiled and under the JIT. That's unchanged. The 11 tests marked not own are refused by design: untyped Maps, an Array<T> of objects, and reduceRight returning an element.

Not in this PR

A class whose object, or a derived class's object, becomes an interface or any still keeps its fields' families open.

🤖 Generated with Claude Code

…the class

A derived class reaches its base's field in the base's storage; that access now
has the same family key, so the family stays closed while no class on the chain
is built by another module or becomes an interface, any or a union (spec 57).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit b3f1fd9 into main Oct 28, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the own-field-families-open branch October 28, 2026 08:51
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