Repository navigation
A value read from an Array is borrowed or moved, and a def may answer a borrowed part of its argument - #8
Draft
nicolas-abril wants to merge 2 commits into
Draft
nicolas-abril wants to merge 2 commits into
nicolas-abril wants to merge 2 commits into
Conversation
This was referenced Nov 24, 2026
Closed
Owner
Author
|
Pushed
|
… a borrowed part of its argument An Array.get of a boxed element reads the slot in place when its consumer only lends the element; a write, a free or a hand-on of the array while the element is live makes the read copy, as before. An Array.set that stores the value read from the same slot moves it. A def whose every result is a part of one borrowed parameter answers a borrowed box. hashmap: 2.41 s to 1.17 s on one thread. comp.ts is 68,402 ttok. Co-Authored-By: Claude Fable 5.2 <[email protected]> (cherry picked from commit edadb78)
The probe (rets: a def whose every result is a part of its borrowed box parameter) emitted every unit, a third emit of the book: c_units went from two passes to three. A unit can be in rets only if its def is live with a box result and a box parameter; the probe now skips the rest. Emit time over the 17 runtime benches 1.761 s to 1.680 here (2.171 to 2.050 on opt/integration 09d002f); the C is the same up to the order of its definitions, and the native lane's 1,123 tests keep every status on integration. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 4a6843c)
nicolas-abril
force-pushed
the
opt/borrowed-reads
branch
from
December 1, 2026 21:52
4a6843c to
9bd4aa9
Compare
This was referenced Dec 1, 2026
nicolas-abril
added a commit
that referenced
this pull request
Dec 1, 2026
…33, #34, #36, #39, #44, #61-#68): record their heads Each is a port onto main of integration's own branch, its content already here (integration keeps the original commits; the ports add type fixes, line wraps, moved pieces and #68's book_passes, applied in the previous commit). Groups: #61 (#9 #11 #15 #32 #41 #42), #62 (#26 #56), #63 (#48 #50 and compile-time), #64 (#19 #20 #45), #67 (#55 #58), #68 (#54); par-defer (#43) is now part of #34, lazy-startup's parts are in #16 and #34. This merge records their heads (-s ours: no content change). Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
On main (
6180be5b)This PR is a port onto main, on
main: 2 commits of its own, with no integration history (head9bd4aa94).Port notes
Checks
run/array_slabfails on main too).ttok -m gpt-3.5-turbo) over main, which is at 65,989 of the 66,000 cap.Performance was measured on integration when this change merged there (see the original description or the replaced PRs); it has not been re-measured on main.
Original description (written for integration)
comp.tsis 68,402 ttok, 2,402 over the 66,000 cap, sorepo-gatefails until that is settled. Measured on one Mac (M4), not on the cluster: thetestandperfgates have not been run.What it does
Three rules, all in
comp.ts. Each falls back to today's copy when its condition fails.Array.getof a boxed element reads the slot in place when its consumer only lends the element. The pair(array, element)a helper takes is a slot parameter: the array word is the helper's, the element is borrowed. A write, a free or a hand-on of the array while the element is live makes the helper own the element, and the read copies as before.Array.set(a, i, v)wherevholds the value lent froma[i], which nothing uses after, moves the value: the set drops nothing, and the element's family is no longer forced hot.rownfact takes a result back (a result that is not a part, a tail call into the def from another def, a self call that passes something else).Results
Wall time, one M4, GPU off, means of 7 runs.
hashmap, 1 threadhashmap, 8 threadstests/run/borrowed_result_tree.bendat 10M lookups a pass)hashmapruns 18.50G instructions on main and 8.09G here; its C twin takes 0.58 s, so it is still about 2x behind C.Bench suite: of the 17
bench/runtimeprograms onlyhashmapandhistogramcompile to different C.histogram's helpers are emitted inline and it takes the same time (1.573 s against 1.574 s). The other 15 are byte-identical.The lookup program is written to show the borrowed result: the caller holds the tree across two passes. A tree handed over and never used again is owned by the callee, as on main, and gains nothing.
Checks
All local, against main
f3115277:#|lines.-DBEND_POISONand a count of live heap words at exit: the same output and the same count as main on every one.tests/run/array_slot_borrow.bend,array_slot_take.bend,array_slot_part.bend,borrowed_result.bendandborrowed_result_tree.bendspell the shapes that must fall back (a slot overwritten or an array dropped while its value is read, a value written to another slot, two reads of one slot, a part that outlives its holder). They pass on the C lane, the JS lane andbend file.bend.repo.tsfails only on the ttok cap.Two bugs came up while writing those tests and are fixed here: a helper that dropped its array before reading the element, and the probe pass hiding layout facts. The first passed every existing test.
Not covered
Maybeor a pair), and only where the caller's argument is itself borrowed or read from an array.Map.getfollowed by aMap.setis untouched.tscwas not run.Cost
+2,440 ttok. Getting under the cap needs that many tokens cut elsewhere in
comp.ts, or a raise.🤖 Generated with Claude Code