Repository navigation
-mm=own: Array<string>, Array<Shared<T>>, f && f(x), captured callbacks - #706
Merged
Merged
Conversation
… in callbacks - A string stored by a statement that may run again (fill's loop) is not a move of the parameter: each store takes a copy (spec 50). - A string or a handle read out of a place and stored into a place rc does not retain it for (a yield's record, `if (c) yield v`) gets a copy or a count of its own; a handle given to a callback that may release things gets a count for the call (spec 50). - A for...of local over handles, declared from a counted read and never assigned, is not a drop when released: the array still holds a count (spec 51). ArraySplice items are counted receivers, as push's are. - A callback that assigns a captured string frees only that string (OWN_CAPTURED_STRING_POSITION); a call given a closure it does not keep is judged by its callees' place drops (spec 52). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- `f && f(x)` of an optional function is `undefined | T` in every model: a function is never falsy, so the false branch is `undefined`, not the function (spec 53). It used to fail to compile. - A slot whose type owns no block (a captured number assigned in a callback) releases nothing: no drop (spec 52). - A callback parameter captured by a closure that only calls it (`a.forEach((v) => f(v))`) keeps its family: the closure's reads of the cell out of its box resolve through the parameter's family, whether the closure is bound or, inlined, called by name (spec 54). - Spec sections 50-54, and the user doc's limits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without the default library the built-in forEach is inlined, and the test passed on the compiler without spec 52. 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.
The third batch of
-mm=ownDefaultLib fixes, specs 50-54. With it, theArray<T>class works under own for strings andShared<T>handles. Callbacks also compile in more shapes: tested with&&, captured by a closure, or given a second name. The user doc's limits section is updated.Changes
Array<string>(§50).fillstores itsvalueparameter into each element in a loop, so a move of the parameter failed with "moved inside a loop".ts.StringCopy) or count (ts.Retain). This coversif (f(v)) yield vinfilter2, where the value goes into the yield's record.ts.Retainbefore it,ts.Releaseafter it.Array<Shared<T>>(§51). Every method that handsthis.datato a walking function failed with "may be released or overwritten". The walk'sfor...oflocal is a counted copy of an element, and its release counted as a drop of anything.isCountedReadSlot) is not a drop. The source still holds a count while it lives.ArraySpliceitems are counted receivers, aspush's are.Callbacks that assign captured variables (§52).
t += v.n) releases nothing.OWN_CAPTURED_STRING_POSITION). It drops only a borrow that may itself be a string.f && f(x)(§53). Withcompare?: (x, y) => number,compare && compare(a, b)failed in every model with "invalid cast". A function is never falsy, so the false branch is nowundefined, as in TypeScript (mlirGenAndOrLogic).Captured and renamed callbacks (§54). A callback parameter captured by a closure that only calls it (
a.forEach((v) => f(v))) now keeps its family.capturedCallbacks,resolveCallback).forEachis inlined and calls it by name.const g = f; g(v)resolves as well.Tests
own_string_copiesown_shared_counted_readsown_captured_string_callbackown_callback_and_callown_callback_capturedown_err_captured_string_dropsandown_err_callback_captured_drops.own_callback_captured, which a later commit fixed: without the default library, the built-inforEachis inlined. After the fix, the own and Shared subsets pass 1968 of 1968.array_class_string,array_class_shared), out of 174:not own)These hold in release and debug, compiled and under the JIT.
Not in this PR
These callbacks still keep their families open:
const call = (v) => f(v); call(v));🤖 Generated with Claude Code