collections: element steps and --explain-copies through the ArrayList record (follow-up of #526) #565

Closed
opened 2026-10-29 06:35:30 +00:00 by orion · 12 comments
Collaborator

Context

Follow-up of #526 (PR #529, step 3 of #55). Since ArrayList is a TorbScript record over Buffer<Item> (items, start, count, COLLECTION-STORAGE.md decision 1), two passes no longer see the list through that record:

  • ir/elements.trb: isListSetter accepts a set that forwards to items.set index, value (the wrapper shape of #468), but ArrayList.set rebases a windowed or shared list first (own()) and then writes items.set index, value. fieldForwardedCallee demands exactly one instruction, the std set has two, so it does not match; and elementTypeOf accepts only a Runtime(ListStorage, [Item]) container with a list setter. So a[i].f = v on an ArrayList takes the round trip (read the item, write the field, set it back) instead of one PathStep.Element.
  • --explain-copies (torb build --explain-copies) reports no copy for a nested write into an ArrayList row another value still holds: tokenOf/factOf give an at call an alias without the Field(items) token, listHoldingElement/isListType recognise only Runtime ListStorage, and nounOf names the record ("record", "O(number of its fields)") instead of the list.

PR #529 moved the compiler tests that pin these shapes (elements.test.trb, explain-copies.test.trb, lower-natives.test.trb, lower-places.test.trb, crossing.test.trb, partial.test.trb) and tests/command-line/copies to the harness/std TrieList, which is still the runtime's list, so they keep testing the passes. The harness prelude (compiler/tests/harness.trb) still declares native type ArrayList without manifest rows; only the debugger tests and lower-collections use the std shape (windowedList, declaredListFiles).

Goal

A write through an element of an ArrayList is one element step again, --explain-copies names its copy, and the tests about these two passes run over the ArrayList of the std shape. Switching the whole harness prelude is split out (#837).

Requirements

  • R1. When the compiler sees a set of the std ArrayList shape (a call of a private self-only var fn that rebases the list, own(), followed by the storage setter on the items field with the arguments forwarded), isListSetter shall accept it, recognised by that shape, not by name.
  • R2. When ir/elements.trb rewrites the round trip of an ArrayList element, it shall emit the same own() call before the write, then one Reference(container.base, steps + Field(items) + Element(item, key, at)), so the observable behaviour (rebase of a windowed or shared list, panic on a bad index) is unchanged.
  • R3. elementTypeOf shall accept the record ArrayList<Item> besides Runtime(ListStorage, [Item]) and FixedArray, giving Item; a look-alike that is not the std shape (other fields, two writes, a different callee) shall stay a round trip.
  • R4. readerSiteOf shall keep requiring exactly one panic in the reader; the std ArrayList.at has one, so no change is expected there, and a test pins it.
  • R5. When --explain-copies follows an ArrayList element, its alias path shall carry the Field(items) token, listHoldingElement/isListType shall recognise the ArrayList record, and the copy shall be named as a "list", O(length of the list), with the way-out hint of today. A copy reported at several MakeUnique levels (the record and its buffer) shall appear once.
  • R6. The rewrite and the report shall behave the same for TrieList (runtime list) as today: its tests stay green unchanged.

Files

  • compiler/src/ir/elements.trb: isListSetter, fieldForwardedCallee (or a sibling for the two-instruction shape), putBackArguments, elementWriteAt, elementTypeOf, rewritten, ownersMadeUnique.
  • compiler/src/ir/explain-copies.trb: tokenOf/placeAlias, factOf, listHoldingElement/isListType, nounOf, reasonOfCopy.
  • compiler/src/ir/lower/place.trb only if elementWriters needs the record's set registered (check; the at readers are already registered).
  • compiler/tests/elements.test.trb, compiler/tests/explain-copies.test.trb: the tests below, over the std ArrayList.
  • compiler/tests/harness.trb: a helper that gives a test the std ArrayList (reuse declaredListFiles, make it carry own() as in std/collections/src/list.trb); no change of the global prelude.
  • tests/command-line/copies/src/main.trb and its expected output: back to ArrayList.
  • docs/design/COLLECTION-STORAGE.md: the status line ("its element steps and its allocations are open (#565, #566)") says only #566 is open.

Tests

  • elements.test.trb, over the std ArrayList: field of an element, nested index write grid[0][1] = 5, a method on an element, a closure on an element are one element step; a container that two implementations meet in (ArrayList + TrieList) stays a round trip as today; look-alike setters (two writes, other callee, other field) stay a round trip.
  • explain-copies.test.trb: held = rows[row] then a nested write reports the copy of the list ("held still holds the list ... (O(length of the list))" with the way-out hint), once, over ArrayList.
  • tests/command-line/copies: output over ArrayList as it was before #529.
  • The TrieList variants stay for the runtime list.

Acceptance criteria

  • ir/elements.trb sees through the set of the ArrayList record (the rebase, then the storage's set): a[i].f = v, grid[i][j] = v, a method and a closure on an element are element steps on an ArrayList, as elements.test.trb pins for the runtime's list; look-alike setters stay a round trip.
  • --explain-copies reports the copy of a nested write into a shared ArrayList row, once, as a list copy (explain-copies.test.trb, tests/command-line/copies over ArrayList again).
  • The tests of the two passes named above run over the std shape of ArrayList; TrieList tests are unchanged and green.
  • COLLECTION-STORAGE.md status line updated.
  • Gates green in both tiers (CI).

Seed

Compiler-only change with existing syntax: recognition by shape in ir/elements.trb and ir/explain-copies.trb, no new syntax, no native, no name the compiler looks up in std. The seed question is therefore no: one commit, the two-commit rule does not apply, seed/ stays untouched.

Size

One PR (a few hours): two compiler files, two test files, a harness helper, one command-line test, one doc line. The global prelude switch is out (#837).

Dependencies

#526 / PR #529 (merged). Epic #55. #837 follows this issue; #566 is independent.

Decided by the loop

  • The element step goes through the record by shape recognition, not by a special case for the name ArrayList, so a user type of the same shape benefits and a look-alike does not.
  • The rewrite keeps the own() call and adds the Field(items) step; it does not drop the rebase (behaviour of windowed and shared lists stays).
  • --explain-copies names the copy as a list copy (O(length of the list)), the user-facing noun; the record's own fields are not shown.
  • Switching the whole harness prelude from native type ArrayList to the std shape is out of this issue: it touches many test files, snapshots and counts and cannot be iterated locally (CI only). Filed as #837.
  • No owner decision needed: no new syntax, no behaviour change visible to programs.
## Context Follow-up of #526 (PR #529, step 3 of #55). Since `ArrayList` is a TorbScript record over `Buffer<Item>` (`items`, `start`, `count`, COLLECTION-STORAGE.md decision 1), two passes no longer see the list through that record: - `ir/elements.trb`: `isListSetter` accepts a `set` that forwards to `items.set index, value` (the wrapper shape of #468), but `ArrayList.set` rebases a windowed or shared list first (`own()`) and then writes `items.set index, value`. `fieldForwardedCallee` demands exactly one instruction, the std `set` has two, so it does not match; and `elementTypeOf` accepts only a `Runtime(ListStorage, [Item])` container with a list setter. So `a[i].f = v` on an `ArrayList` takes the round trip (read the item, write the field, `set` it back) instead of one `PathStep.Element`. - `--explain-copies` (`torb build --explain-copies`) reports no copy for a nested write into an `ArrayList` row another value still holds: `tokenOf`/`factOf` give an `at` call an alias without the `Field(items)` token, `listHoldingElement`/`isListType` recognise only `Runtime ListStorage`, and `nounOf` names the record ("record", "O(number of its fields)") instead of the list. PR #529 moved the compiler tests that pin these shapes (`elements.test.trb`, `explain-copies.test.trb`, `lower-natives.test.trb`, `lower-places.test.trb`, `crossing.test.trb`, `partial.test.trb`) and `tests/command-line/copies` to the harness/std `TrieList`, which is still the runtime's list, so they keep testing the passes. The harness prelude (`compiler/tests/harness.trb`) still declares `native type ArrayList` without manifest rows; only the debugger tests and `lower-collections` use the std shape (`windowedList`, `declaredListFiles`). ## Goal A write through an element of an `ArrayList` is one element step again, `--explain-copies` names its copy, and the tests about these two passes run over the `ArrayList` of the std shape. Switching the whole harness prelude is split out (#837). ## Requirements - R1. When the compiler sees a `set` of the std `ArrayList` shape (a call of a private self-only `var fn` that rebases the list, `own()`, followed by the storage setter on the `items` field with the arguments forwarded), `isListSetter` shall accept it, recognised by that shape, not by name. - R2. When `ir/elements.trb` rewrites the round trip of an `ArrayList` element, it shall emit the same `own()` call before the write, then one `Reference(container.base, steps + Field(items) + Element(item, key, at))`, so the observable behaviour (rebase of a windowed or shared list, panic on a bad index) is unchanged. - R3. `elementTypeOf` shall accept the record `ArrayList<Item>` besides `Runtime(ListStorage, [Item])` and `FixedArray`, giving `Item`; a look-alike that is not the std shape (other fields, two writes, a different callee) shall stay a round trip. - R4. `readerSiteOf` shall keep requiring exactly one panic in the reader; the std `ArrayList.at` has one, so no change is expected there, and a test pins it. - R5. When `--explain-copies` follows an `ArrayList` element, its alias path shall carry the `Field(items)` token, `listHoldingElement`/`isListType` shall recognise the `ArrayList` record, and the copy shall be named as a "list", `O(length of the list)`, with the way-out hint of today. A copy reported at several MakeUnique levels (the record and its buffer) shall appear once. - R6. The rewrite and the report shall behave the same for `TrieList` (runtime list) as today: its tests stay green unchanged. ## Files - `compiler/src/ir/elements.trb`: `isListSetter`, `fieldForwardedCallee` (or a sibling for the two-instruction shape), `putBackArguments`, `elementWriteAt`, `elementTypeOf`, `rewritten`, `ownersMadeUnique`. - `compiler/src/ir/explain-copies.trb`: `tokenOf`/`placeAlias`, `factOf`, `listHoldingElement`/`isListType`, `nounOf`, `reasonOfCopy`. - `compiler/src/ir/lower/place.trb` only if `elementWriters` needs the record's `set` registered (check; the `at` readers are already registered). - `compiler/tests/elements.test.trb`, `compiler/tests/explain-copies.test.trb`: the tests below, over the std `ArrayList`. - `compiler/tests/harness.trb`: a helper that gives a test the std `ArrayList` (reuse `declaredListFiles`, make it carry `own()` as in `std/collections/src/list.trb`); no change of the global prelude. - `tests/command-line/copies/src/main.trb` and its expected output: back to `ArrayList`. - `docs/design/COLLECTION-STORAGE.md`: the status line ("its element steps and its allocations are open (#565, #566)") says only #566 is open. ## Tests - `elements.test.trb`, over the std `ArrayList`: field of an element, nested index write `grid[0][1] = 5`, a method on an element, a closure on an element are one element step; a container that two implementations meet in (ArrayList + TrieList) stays a round trip as today; look-alike setters (two writes, other callee, other field) stay a round trip. - `explain-copies.test.trb`: `held = rows[row]` then a nested write reports the copy of the list ("`held` still holds the list ... (O(length of the list))" with the way-out hint), once, over `ArrayList`. - `tests/command-line/copies`: output over `ArrayList` as it was before #529. - The `TrieList` variants stay for the runtime list. ## Acceptance criteria - [ ] `ir/elements.trb` sees through the `set` of the `ArrayList` record (the rebase, then the storage's `set`): `a[i].f = v`, `grid[i][j] = v`, a method and a closure on an element are element steps on an `ArrayList`, as `elements.test.trb` pins for the runtime's list; look-alike setters stay a round trip. - [ ] `--explain-copies` reports the copy of a nested write into a shared `ArrayList` row, once, as a list copy (`explain-copies.test.trb`, `tests/command-line/copies` over `ArrayList` again). - [ ] The tests of the two passes named above run over the std shape of `ArrayList`; `TrieList` tests are unchanged and green. - [ ] COLLECTION-STORAGE.md status line updated. - [ ] Gates green in both tiers (CI). ## Seed Compiler-only change with existing syntax: recognition by shape in `ir/elements.trb` and `ir/explain-copies.trb`, no new syntax, no native, no name the compiler looks up in std. The seed question is therefore no: one commit, the two-commit rule does not apply, `seed/` stays untouched. ## Size One PR (a few hours): two compiler files, two test files, a harness helper, one command-line test, one doc line. The global prelude switch is out (#837). ## Dependencies #526 / PR #529 (merged). Epic #55. #837 follows this issue; #566 is independent. ## Decided by the loop - The element step goes through the record by shape recognition, not by a special case for the name `ArrayList`, so a user type of the same shape benefits and a look-alike does not. - The rewrite keeps the `own()` call and adds the `Field(items)` step; it does not drop the rebase (behaviour of windowed and shared lists stays). - `--explain-copies` names the copy as a list copy (`O(length of the list)`), the user-facing noun; the record's own fields are not shown. - Switching the whole harness prelude from `native type ArrayList` to the std shape is out of this issue: it touches many test files, snapshots and counts and cannot be iterated locally (CI only). Filed as #837. - No owner decision needed: no new syntax, no behaviour change visible to programs.
Author
Collaborator

[loop:orion] labelled loop: live-design follow-up of #526 / PR #529 (epic #55), filed by an interactive session without the label. Not superseded; no retirement.

[loop:orion] labelled `loop`: live-design follow-up of #526 / PR #529 (epic #55), filed by an interactive session without the label. Not superseded; no retirement.
Author
Collaborator

[loop:torbscript] intake: in scope (author orion, label loop), no duplicate, no collision with a design record; dependency #526 / PR #529 is merged. Compiler pass work (ir/elements, --explain-copies), no owner question, no seed change known (to be confirmed in refine). next: refine

[loop:torbscript] intake: in scope (author orion, label loop), no duplicate, no collision with a design record; dependency #526 / PR #529 is merged. Compiler pass work (ir/elements, --explain-copies), no owner question, no seed change known (to be confirmed in refine). next: refine
Author
Collaborator

[loop:torbscript] refine: next: waiting (the ready buffer is full, 12 issues are ready against a refine threshold of 4, and 8 pull requests are open against a cap of 8; refine resumes when ready items have been picked up)

[loop:torbscript] refine: next: waiting (the ready buffer is full, 12 issues are ready against a refine threshold of 4, and 8 pull requests are open against a cap of 8; refine resumes when ready items have been picked up)
Author
Collaborator

[loop:torbscript] claim refine by session:loop-torbscript-565-refine until 2026-11-16T14:38:00Z
Reason: focus item #55 (epic), step 3a. Ready buffer is 3 of 4 (#836, #620, #365), one worker slot free.

[loop:torbscript] claim refine by session:loop-torbscript-565-refine until 2026-11-16T14:38:00Z Reason: focus item #55 (epic), step 3a. Ready buffer is 3 of 4 (#836, #620, #365), one worker slot free.
Author
Collaborator

[loop:torbscript] decided by the loop: #565 is scoped to the two passes (ir/elements.trb, ir/explain-copies.trb) plus the tests about them; the std ArrayList.set is recognised by shape (own() then the storage setter on items), the rewrite keeps own() and adds Field(items); copies are named as list copies. The global harness prelude switch (many test files, snapshots, counts, CI-only iteration) is split out as #837. Seed: compiler-only, existing syntax, one commit, two-commit rule does not apply. Numbers: ~6 files (2 src, 2 tests, 1 harness helper, 1 command-line test) plus one doc line. Details in the issue body ("Decided by the loop").

[loop:torbscript] decided by the loop: #565 is scoped to the two passes (`ir/elements.trb`, `ir/explain-copies.trb`) plus the tests about them; the std `ArrayList.set` is recognised by shape (`own()` then the storage setter on `items`), the rewrite keeps `own()` and adds `Field(items)`; copies are named as list copies. The global harness prelude switch (many test files, snapshots, counts, CI-only iteration) is split out as #837. Seed: compiler-only, existing syntax, one commit, two-commit rule does not apply. Numbers: ~6 files (2 src, 2 tests, 1 harness helper, 1 command-line test) plus one doc line. Details in the issue body ("Decided by the loop").
Author
Collaborator

[loop:torbscript] refine: ready. Body rewritten to the writing standard (context, R1-R6, files, tests, acceptance criteria, seed statement, size, dependencies, decisions); label ready added; the harness prelude switch split out as #837 (label loop, depends on this); claim released. next: implement

[loop:torbscript] refine: ready. Body rewritten to the writing standard (context, R1-R6, files, tests, acceptance criteria, seed statement, size, dependencies, decisions); label `ready` added; the harness prelude switch split out as #837 (label `loop`, depends on this); claim released. next: implement
Author
Collaborator

[loop:torbscript] claim implement by session:loop-torbscript-565-implement until 2026-11-16T18:50:00Z
Reason: #565 is ready (newest refine release), ready buffer is 4 of 4, openPrs 2 of 8, one worker slot free.

[loop:torbscript] claim implement by session:loop-torbscript-565-implement until 2026-11-16T18:50:00Z Reason: #565 is ready (newest refine release), ready buffer is 4 of 4, openPrs 2 of 8, one worker slot free.
Author
Collaborator

[loop:torbscript] implement: PR #838 (head loop/565-arraylist-element-steps, one commit 5de6207c, Argus requested). next: waiting (forge CI of 5de6207c had not started after 30 min, all four checks Waiting to run; the next tick reads ci-wait.sh again and fixes a red run on the same branch)

What changed:

  • ir/elements.trb: recognizes the ArrayList window record by its layout (windowLayoutOf, now public), rebases once with the setter's own() and writes the element in place as one PathStep.Element chain (take-out and put-back dropped).
  • ir/explain-copies.trb: the window record counts as the list (noun, held-row, method-on-row and live-alias notes); the rebase call forgets only the storage facts.
  • tests/command-line/copies is an ArrayList again; the pinned report text and position are unchanged. docs/design/COLLECTION-STORAGE.md status: only #566 is open.
  • Local checks only: elements.test.trb 21 passed, explain-copies.test.trb 15 passed, lower-collections.test.trb 14 passed, counted.test.trb 3 passed, torb format --check clean, check-commits.sh clean, skills/ unchanged by docs skill. Gates, bootstrap and the copies command-line case are CI-only and not yet seen.
  • Tokens: roughly 600k in this run (estimate, includes the compacted part).
[loop:torbscript] implement: PR https://git.torb.dev/torbscript/language/pulls/838 (head `loop/565-arraylist-element-steps`, one commit `5de6207c`, Argus requested). next: waiting (forge CI of 5de6207c had not started after 30 min, all four checks `Waiting to run`; the next tick reads `ci-wait.sh` again and fixes a red run on the same branch) What changed: - `ir/elements.trb`: recognizes the `ArrayList` window record by its layout (`windowLayoutOf`, now public), rebases once with the setter's `own()` and writes the element in place as one `PathStep.Element` chain (take-out and put-back dropped). - `ir/explain-copies.trb`: the window record counts as the list (noun, held-row, method-on-row and live-alias notes); the rebase call forgets only the storage facts. - `tests/command-line/copies` is an `ArrayList` again; the pinned report text and position are unchanged. `docs/design/COLLECTION-STORAGE.md` status: only #566 is open. - Local checks only: `elements.test.trb` 21 passed, `explain-copies.test.trb` 15 passed, `lower-collections.test.trb` 14 passed, `counted.test.trb` 3 passed, `torb format --check` clean, `check-commits.sh` clean, `skills/` unchanged by `docs skill`. Gates, bootstrap and the `copies` command-line case are CI-only and not yet seen. - Tokens: roughly 600k in this run (estimate, includes the compacted part).
argus closed this issue 2026-11-16 16:02:15 +00:00
Author
Collaborator

[loop:torbscript] done: merged as PR #838 (argus, 2026-11-16 16:02 UTC, merge commit 426b9fcf). Acceptance: ArrayList window layout recognized in ir/elements.trb and ir/explain-copies.trb, tests/command-line/copies is an ArrayList again with the same pinned report text. Merge-commit CI was still pending at 17:02 Berlin; main carries the change, so it ships in the nightly of 2026-11-17 (automatic, no tag needed). Next step (not done here): the change belongs to the stable 0.1.0 cut on the first Tuesday, 2026-12-01 (docs/contributing/releasing.md), not an out-of-cycle tag. Stale label ready removed.

[loop:torbscript] done: merged as PR #838 (argus, 2026-11-16 16:02 UTC, merge commit 426b9fcf). Acceptance: ArrayList window layout recognized in ir/elements.trb and ir/explain-copies.trb, tests/command-line/copies is an ArrayList again with the same pinned report text. Merge-commit CI was still pending at 17:02 Berlin; main carries the change, so it ships in the nightly of 2026-11-17 (automatic, no tag needed). Next step (not done here): the change belongs to the stable 0.1.0 cut on the first Tuesday, 2026-12-01 (docs/contributing/releasing.md), not an out-of-cycle tag. Stale label ready removed.
Author
Collaborator

[loop:torbscript] claim fix by session:loop-torbscript-main-fix until 2026-11-16T20:10:00Z Reason: main CI is red at 426b9fcf (merge of PR #838, this issue): jobs tier A (linux-x64) and gates failed in run 3182. Red main comes first; the worker diagnoses from the run logs and opens a fix PR or a revert PR (no merge, no push to main).

[loop:torbscript] claim fix by session:loop-torbscript-main-fix until 2026-11-16T20:10:00Z Reason: main CI is red at 426b9fcf (merge of PR #838, this issue): jobs `tier A (linux-x64)` and `gates` failed in run 3182. Red main comes first; the worker diagnoses from the run logs and opens a fix PR or a revert PR (no merge, no push to main).
Author
Collaborator

[loop:torbscript] main-fix: red main at 426b9fcf is not caused by this issue. Tier A fails in std/json-schema/tests/suite.test.trb: 17 idn-hostname known-difference entries became stale when the std/dns commits fbca4f09 and 11fe42c9 landed (red since 11fe42c9). Fix PR: #840 (Argus requested), next: waiting (merge gate, then main CI green).

[loop:torbscript] main-fix: red main at 426b9fcf is not caused by this issue. Tier A fails in `std/json-schema/tests/suite.test.trb`: 17 idn-hostname known-difference entries became stale when the std/dns commits fbca4f09 and 11fe42c9 landed (red since 11fe42c9). Fix PR: https://git.torb.dev/torbscript/language/pulls/840 (Argus requested), next: waiting (merge gate, then main CI green).
Author
Collaborator

[loop:torbscript] release by session:loop-torbscript-main-fix: fix PR #840 is open (branch loop/main-fix-idn-hostname, one commit, Argus requested). The loop never merges; main CI is re-read after the merge gate lands it.

[loop:torbscript] release by session:loop-torbscript-main-fix: fix PR https://git.torb.dev/torbscript/language/pulls/840 is open (branch `loop/main-fix-idn-hostname`, one commit, Argus requested). The loop never merges; main CI is re-read after the merge gate lands it.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
torbscript/language#565
No description provided.