Repository navigation
-mm=own phase 6: named messages for a second reference; nullable views, spreads, declaration retains - #449
Merged
Conversation
…s, spreads, declaration retains
The catch-all ("takes a second reference; -mm=own cannot prove a move or a borrow here yet") was
the first error of 100 corpus files. reportSecondReference now names the shape it is given, from
the retained value's root, for all four places that report it: a function returning a borrow of
its argument on some paths and another value on others (___unbox<string>, ___cast<A, string>,
user code), a parameter returned or kept where its callers cannot learn the fact, a parameter
assigned, a local that owns nothing given a value, a value merged from branches, a global's value,
a captured variable's value, and an object literal holding a value it owns.
Accepted on the way:
- a string or an array widened to a union of it and null or undefined, or narrowed back, is a view;
- a view of a value whose type owns no block holds none (a union's number payload made into another
union), and a retain of it is erased;
- a local's declaration retain of constant data is erased wherever the slot still holds its
initializer, whatever is stored later (MLIRGen emits it only at the declaration);
- a field of constant data is constant data;
- an array a spread builds in a local of its own moves into the owning local it is read into;
- an interface's `this` bound for a call of a function-typed field is a borrow (#410's shape).
Corpus: 402 -> 416 of 592 (415 with --opt), none lost; the catch-all 100 -> 25. Spec section 21.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 6, second PR (plan
docs/superpowers/plans/2026-10-02-own-phase-6.md, task 5; spec §21).What
The catch-all
'x' takes a second reference; -mm=own cannot prove a move or a borrow here yetnamed no rule.reportSecondReferencenow classifies what it is given, from the retained value's root, in one place, so all four places that report it get the same names:___unbox<string>and___cast<A, string>helpers, and user code such asreturn name/return "Sorry, " + name), with a note at the other return;Accepted on the way (each with a positive test, and a tooth: turning the rule off makes it fail plain, with
--optand with--di):mkN(v: number): number | P { return v }no longer has a result that "borrows" its argument;ts.RetainSlotonly at a declaration). Replaces §20's "nothing is ever stored into the slot";const b = [...a, ...a]);thisbound for a call of a function-typed field is a borrow (-mm=own: an importer can build objects of an imported class #410's shape withts.ExtractInterfaceThis).Two rules were tried and dropped because nothing needed them:
ts.SafeCastas a view, and a number cast to a union as holding no block.Corpus (592 files,
--no-default-lib)--opt)--opt)takes a second reference(catch-all)None lost, plain or
--opt. The 13 files gained under--opteach pass test-runner-mm=own, AOT and JIT, with the default flags and with-noopt.00interface_object3compiles plain only: under--opt, CSE merges the interfacethisreads into a taker (§21.6), so it is not counted.Tests
own_nullable_view,own_declared_constant,own_spread_build,own_interface_field_call(also pass under rc, none and gc, AOT and JIT).own_error_cases, one per message.-mm=own), so rc, gc and none emit what they did.Found, not fixed
instanceofis false for a class value held in a union or nullable local under every model, even narrowed:let a: C | null = new C(1); a instanceof C.🤖 Generated with Claude Code