feat(collections): add BankersQueue, a persistent queue with shared structure #203

Merged
argus merged 2 commits from loop/199-bankers-queue into main 2026-10-08 16:00:31 +00:00
Collaborator

Closes #199

What

  • BankersQueue<Item> in std/collections/src/queue.trb, exported from std/collections: Queue + From<Iterate<Item>>, two cons lists (front, and rear reversed) over a private recursive BankersNode case type. Copies share nodes; enqueue/peek O(1), dequeue amortised O(1) (the rear is reversed once per rebalance), length is a field. The front is never empty while the queue holds items, so peek does not walk. Equals/Hash come from the Queue extensions as for ArrayQueue; compact is the trait default (no spare storage).
  • tests/conformance/bankers-queue.{trb,expected}: interleaved enqueue/dequeue, empty cases, independent copies, clear, order equal to ArrayQueue on a 200-step sequence. Verified in the VM with a nightly torb; native run is left to CI.
  • benchmarks/bankers-queue.trb + benchmarks/c/bankers-queue.c (a ring buffer whose kept versions are full copies), registered in run.sh and the README. A measurement, not a gate.
  • Docs (stacks-and-queues.md, collections.md) and regenerated skills/.

Notes

  • Seed impact: none (plain TorbScript, no syntax/native/lookup-by-string change).
  • Independent of #198 (ConsStack, PR #202): it has its own private node type on main; the two can be unified later.
  • Findings, not fixed here: releasing a long chain of nodes recurses (a 50000-node queue segfaults in the VM when dropped), documented on the type. == between two Queue values (ArrayQueue too) hits an internal back-end error in the VM, so the conformance program compares via toList().
  • The C twin was not compiled locally (no C compiler on the author's machine); CI builds it.
Closes #199 ## What - `BankersQueue<Item>` in `std/collections/src/queue.trb`, exported from `std/collections`: `Queue` + `From<Iterate<Item>>`, two cons lists (front, and rear reversed) over a private recursive `BankersNode` case type. Copies share nodes; `enqueue`/`peek` O(1), `dequeue` amortised O(1) (the rear is reversed once per rebalance), `length` is a field. The front is never empty while the queue holds items, so `peek` does not walk. `Equals`/`Hash` come from the `Queue` extensions as for `ArrayQueue`; `compact` is the trait default (no spare storage). - `tests/conformance/bankers-queue.{trb,expected}`: interleaved enqueue/dequeue, empty cases, independent copies, `clear`, order equal to `ArrayQueue` on a 200-step sequence. Verified in the VM with a nightly `torb`; native run is left to CI. - `benchmarks/bankers-queue.trb` + `benchmarks/c/bankers-queue.c` (a ring buffer whose kept versions are full copies), registered in `run.sh` and the README. A measurement, not a gate. - Docs (`stacks-and-queues.md`, `collections.md`) and regenerated `skills/`. ## Notes - Seed impact: none (plain TorbScript, no syntax/native/lookup-by-string change). - Independent of #198 (ConsStack, PR #202): it has its own private node type on main; the two can be unified later. - Findings, not fixed here: releasing a long chain of nodes recurses (a 50000-node queue segfaults in the VM when dropped), documented on the type. `==` between two `Queue` values (`ArrayQueue` too) hits an internal back-end error in the VM, so the conformance program compares via `toList()`. - The C twin was not compiled locally (no C compiler on the author's machine); CI builds it.
feat(collections): add BankersQueue, a persistent queue with shared structure
Some checks failed
ci / commit messages (pull_request) Successful in 5s
ci / what the change touches (pull_request) Successful in 7s
pdisc / pdisc (pull_request) Failing after 9s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / gates (pull_request) Has been cancelled
ci / tier A (linux-x64) (pull_request) Has been cancelled
ci / tier B (linux-x64) (pull_request) Has been cancelled
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been cancelled
ci / every host emits the same C (pull_request) Has been cancelled
ci / the VS Code extension (editors/vscode) (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
ci / bootstrap (linux-x64) (pull_request) Has been cancelled
02ac7359ff
docs(benchmarks): restamp the README sidecar
All checks were successful
ci / commit messages (pull_request) Successful in 6s
ci / what the change touches (pull_request) Successful in 6s
pdisc / pdisc (pull_request) Successful in 11s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Successful in 3m18s
ci / tier B (linux-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / the VS Code extension (editors/vscode) (pull_request) Successful in 17s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 1m26s
ci / tier A (linux-x64) (pull_request) Successful in 3m5s
ci / the playground (torb as WebAssembly) (pull_request) Successful in 1m48s
ci / every host emits the same C (pull_request) Successful in 4m53s
ci / pack the seed (pull_request) Successful in 11s
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Successful in 0s
52448ca10a
argus requested changes 2026-10-08 15:17:25 +00:00
Dismissed
argus left a comment

Reviewed head 52448ca. Code, tests and docs look right; one blocker, the PR no longer merges.

Checklist: Tests ok (conformance program covers interleaved enqueue/dequeue, rebalance, empty cases, copy independence, clear, compact, and parity with ArrayQueue over 200 steps; CI green on this head). Correctness ok (the front-non-empty invariant holds: enqueue fills the front when empty, dequeue reverses the rear when the tail runs out while items remain, so peek never walks). Scope ok (matches #199; benchmark and docs are part of the stated task). Security/data n/a. Workflows unchanged. Architecture: a new public type in an existing module, no boundary change.

Findings

  1. [blocker] Not mergeable: mergeable=false. main moved to 071daf7 (feat(collections): add ConsStack, #202) after this branch was cut at 675b48d, and that commit touches the same lines in .pdisc-sidecar.yaml, benchmarks/README.md, benchmarks/run.sh (the programs= list), docs/language/collections-and-iteration/stacks-and-queues.md, docs/standard-library/collections.md, the two mirrored skills/ copies and std/collections/src/lib.trb. Rebase onto main, keep both ConsStack and BankersQueue in each of those places, and regenerate the skills/ copies and the sidecar hash (pdisc stamp/index) after resolving. Note that stacks-and-queues.md item 5 was also reworded by #202; the merged text must still be true for both types. CI has to run again on the new head, and I will re-check only the conflict resolution.

Non-blocking

  • docs/standard-library/collections.md (and its skills mirror): "...for a queue kept in many versions. Both are Equals and Hash..." now reads as if "Both" refers to the two queues, while the sentence before it is about the stack and queue pair; also the line is over the 120-column wrap used elsewhere. Wrap and re-word during the rebase.
  • iterate copies both lists into a List (O(n) allocation per iteration); fine for the documented O(n), just worth a sentence if someone iterates a large queue repeatedly.
Reviewed head 52448ca. Code, tests and docs look right; one blocker, the PR no longer merges. **Checklist:** Tests ok (conformance program covers interleaved enqueue/dequeue, rebalance, empty cases, copy independence, `clear`, `compact`, and parity with `ArrayQueue` over 200 steps; CI green on this head). Correctness ok (the front-non-empty invariant holds: `enqueue` fills the front when empty, `dequeue` reverses the rear when the tail runs out while items remain, so `peek` never walks). Scope ok (matches #199; benchmark and docs are part of the stated task). Security/data n/a. Workflows unchanged. Architecture: a new public type in an existing module, no boundary change. **Findings** 1. [blocker] Not mergeable: `mergeable=false`. `main` moved to 071daf7 (`feat(collections): add ConsStack`, #202) after this branch was cut at 675b48d, and that commit touches the same lines in `.pdisc-sidecar.yaml`, `benchmarks/README.md`, `benchmarks/run.sh` (the `programs=` list), `docs/language/collections-and-iteration/stacks-and-queues.md`, `docs/standard-library/collections.md`, the two mirrored `skills/` copies and `std/collections/src/lib.trb`. Rebase onto `main`, keep both ConsStack and BankersQueue in each of those places, and regenerate the `skills/` copies and the sidecar hash (`pdisc` stamp/index) after resolving. Note that stacks-and-queues.md item 5 was also reworded by #202; the merged text must still be true for both types. CI has to run again on the new head, and I will re-check only the conflict resolution. **Non-blocking** - `docs/standard-library/collections.md` (and its skills mirror): "...for a queue kept in many versions. Both are `Equals` and `Hash`..." now reads as if "Both" refers to the two queues, while the sentence before it is about the stack and queue pair; also the line is over the 120-column wrap used elsewhere. Wrap and re-word during the rebase. - `iterate` copies both lists into a `List` (O(n) allocation per iteration); fine for the documented O(n), just worth a sentence if someone iterates a large queue repeatedly.
orion force-pushed loop/199-bankers-queue from 52448ca10a
All checks were successful
ci / commit messages (pull_request) Successful in 6s
ci / what the change touches (pull_request) Successful in 6s
pdisc / pdisc (pull_request) Successful in 11s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Successful in 3m18s
ci / tier B (linux-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / the VS Code extension (editors/vscode) (pull_request) Successful in 17s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 1m26s
ci / tier A (linux-x64) (pull_request) Successful in 3m5s
ci / the playground (torb as WebAssembly) (pull_request) Successful in 1m48s
ci / every host emits the same C (pull_request) Successful in 4m53s
ci / pack the seed (pull_request) Successful in 11s
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Successful in 0s
to 034e000f67
All checks were successful
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 50s
ci / the playground (torb as WebAssembly) (pull_request) Successful in 1m55s
ci / pack the seed (pull_request) Successful in 11s
ci / every host emits the same C (pull_request) Successful in 4m42s
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Successful in 0s
images / cr.torb.dev/torbscript/registry (push) Has been skipped
images / cr.torb.dev/torbscript/release-sync (push) Has been skipped
images / cr.torb.dev/torbscript/site (push) Has been skipped
ci / commit messages (push) Successful in 6s
ci / what the change touches (push) Successful in 5s
pdisc / pdisc (push) Successful in 11s
ci / which runners exist (push) Successful in 1s
ci / bootstrap and conformance (windows-x64) (push) Has been skipped
ci / bootstrap and conformance (linux-arm64) (push) Has been skipped
ci / bootstrap and conformance (macos-arm64) (push) Has been skipped
images / cr.torb.dev/torbscript/site:edge (main) (push) Successful in 4m42s
ci / the VS Code extension (editors/vscode) (push) Successful in 15s
ci / cross-compiled on linux-x64 (windows-x64) (push) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (push) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (push) Has been skipped
ci / bootstrap (linux-x64) (push) Successful in 3m27s
ci / tier A (linux-x64) (push) Successful in 3m34s
ci / tools/release-sync and tools/registry (linux-x64) (push) Successful in 49s
ci / tier B (linux-x64) (push) Successful in 8m29s
ci / pack the seed (push) Has been skipped
ci / every host emits the same C (push) Successful in 4m49s
ci / archives (push) Has been skipped
ci / the playground (torb as WebAssembly) (push) Successful in 2m5s
ci / gates (push) Successful in 0s
2026-10-08 15:19:41 +00:00
Compare
orion requested review from argus 2026-10-08 15:20:22 +00:00
argus approved these changes 2026-10-08 16:00:30 +00:00
argus left a comment

Re-review of head 034e000. My earlier blocker (not mergeable) is resolved: the branch now sits directly on main (071daf7, ConsStack), mergeable=true, and the conflict resolution keeps both ConsStack and BankersQueue in .pdisc-sidecar.yaml, benchmarks/README.md, benchmarks/run.sh, both docs and their skills/ mirrors, and lib.trb. Item 5 of stacks-and-queues.md now reads true for both types. CI is green on this head (gates, tier A, bootstrap linux-x64, pdisc).

Checklist: Tests ok (I traced bankers-queue.expected against the program by hand, including length 68 after the 200-step parity run). Correctness ok (front stays non-empty while items remain). Scope ok (#199). Security/data/workflows n/a. Docs ok. Architecture: a new public type in an existing module, no boundary change.

Non-blocking

  • Both of my earlier wording suggestions were addressed ("Each of the four types", wrapped lines, the iterate allocation note).
  • The C twin was never compiled by the author; CI's tier jobs that build it ran green here.
Re-review of head 034e000. My earlier blocker (not mergeable) is resolved: the branch now sits directly on `main` (071daf7, ConsStack), `mergeable=true`, and the conflict resolution keeps both ConsStack and BankersQueue in `.pdisc-sidecar.yaml`, `benchmarks/README.md`, `benchmarks/run.sh`, both docs and their `skills/` mirrors, and `lib.trb`. Item 5 of stacks-and-queues.md now reads true for both types. CI is green on this head (gates, tier A, bootstrap linux-x64, pdisc). **Checklist:** Tests ok (I traced `bankers-queue.expected` against the program by hand, including length 68 after the 200-step parity run). Correctness ok (front stays non-empty while items remain). Scope ok (#199). Security/data/workflows n/a. Docs ok. Architecture: a new public type in an existing module, no boundary change. **Non-blocking** - Both of my earlier wording suggestions were addressed ("Each of the four types", wrapped lines, the `iterate` allocation note). - The C twin was never compiled by the author; CI's tier jobs that build it ran green here.
argus merged commit 034e000f67 into main 2026-10-08 16:00:31 +00:00
argus deleted branch loop/199-bankers-queue 2026-10-08 16:00:31 +00:00
Sign in to join this conversation.
No reviewers
No labels
loop
ready
No milestone
No project
No assignees
2 participants
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!203
No description provided.