Repository navigation
-mm=own: callbacks declaring fewer parameters over Map/Set; WeakRef of a nullable target - #872
Merged
Merged
Conversation
`m.forEach((v, k) => { names.push(k); })` over a Map or a Set failed under own with
"argument 'this value' is given to '...', which keeps it, but -mm=own cannot move it
here", at <unknown>:0. The callback declares fewer parameters than forEach's type, so
it is called through an adapter (fewerParametersThunk) that passed its block arguments
straight on: own saw an argument the adapter did not own given to a callee that keeps it.
The adapter now takes its parameters into slots, as any function does, so own reads it
as keeping what its callee keeps; when callbacks passed in its place disagree, a string
it only borrows is copied for the callee that keeps it (callCopies, spec 22), as one read
out of a field is. Without --di it carries the location it is made at, so an error found
in it points at the callback's use.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`let n: Node | null = new Node(); new WeakRef(n)` was refused under own and none
("WeakRef needs a class object"), and under gc made a WeakRef<Node | null> that a later
store into `WeakRef<Node> | string` failed to verify. TypeScript reads n as Node there;
this compiler keeps the declared type, so T is now the target's type without null. A null
target makes a WeakRef whose deref() gives undefined.
Deferred minor M1 of the WeakRef review (#871).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…here) The copy 3da319c meant for a string an adapter only borrows was recorded in the dry run, which then passed, so the copies were never made: the adapter gave the Map's own key to a callback that pushed it, and the key was freed twice (two forEach callbacks over one Map, keeping the key and the value, crashed in a loop). The dry run now fails there, as for a string read out of a place, and the real run finds the copy given. own_callback_fewer_params now builds its strings at run time and frees the table's after the callbacks: literals are immortal, so the test passed without the copy. 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.
Readiness item 4, plus the first deferred minor of the WeakRef review (#871) and the readiness docs.
Capturing callbacks over
MapandSetUnder own, this failed with an error at
<unknown>:0:The callback declares fewer parameters than
forEach's type ((value, key, map) => void), so the compiler calls it through a generated adapter (fewerParametersThunk,<callee>.args<N>). The adapter passed its block arguments straight to the callback. Own therefore never saw it keep what its callee keeps, and it reported a value given without being owned. The adapter also had no source location. A callback that declared every parameter already compiled.ts.Param), as any function does. It keeps what its callee keeps, and the callback family decides it like any other member (spec 33).callCopies, spec 22), as a string read out of a field does.--dithe adapter now carries the location it is made at, so an error found in it points at the callback's use.A note on the first version of the copy: it was recorded in the dry run but never made, because the dry run then passed. Two disagreeing callbacks over one Map gave the Map's own key away, and it was freed twice. My compiler test missed this because string literals are immortal. The new default-library test, with keys built at run time and a later
delete, crashed under own. The second commit fixes it, andown_callback_fewer_paramsnow builds its strings at run time and frees the table's strings before checking.WeakRef of a nullable declared target
let n: Node | null = new Node(); new WeakRef(n)failed under every model:WeakRef<Node | null>that a later store intoWeakRef<Node> | stringfailed to verify.With no type argument,
Tis now the target's type without null. A null target makes a WeakRef whosederef()givesundefined; the copy, the release andderefalready test for null.Docs
docs/own-readiness.mdwas stale after #871 and this change. I updated:docs/production-readiness-plan.mdis updated too, and spec section 85 records both changes.Validation
MALLOC_PERTURB_=165, tcache off)mainThe default-library run includes the companion PR's new test. That test first failed only because it ended with
done.instead of theALL DONEmarker; after the fix it passes under all four models (JIT).Companion: a default-library test of Map and Set
forEachcallbacks that keep their keys and values. Merge this PR first.🤖 Generated with Claude Code