feat(collections): add ConsStack, a persistent stack with shared tails #202
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/198-cons-stack"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #198
What
ConsStack<Item>instd/collections: aStackwritten as a persistent cons list in plain TorbScript (COLLECTIONS.md section 3.3 and C7). A copy (var rest = stack) is one reference to the top cell and shares the whole tail;push/popare O(1) and copy nothing, and changing a copy never changes the original.public type ConsStack<Item> with Stack<Item>, From<Iterate<Item>>:push,pop,peek,length,clear,iterate(top first);Equals/Hashcome from theStackextensions exactly as forArrayStack.ConsStack.of(...)and typed literals go throughFrom.ConsNode<Item>(next: ConsNode<Item>?), reference counted by the runtime; no change toruntime/, the compiler orlist.c.std/collections/src/lib.trb; doc comments carry the cost profile.tests/conformance/cons-stack-persists(copies both ways, undo history, backtracking, clear on a shared copy, literals, equality/hash incl. againstArrayStack, a 10000-item stack and its copy).cons-stackandarray-stackwith C twins (10000 versions of a 1000-item base); measurement only, added torun.shand the README table.stacks-and-queues.mdandcollections.md;skills/regenerated.Seed impact
None: a new public type, no syntax change, no new native, no driver flag, and the compiler looks up none of the new names by string.
Checks
Run locally with a released
torb(VM only, no gates, no bootstrap): the conformance program output,torb check benchmarks,torb format --check,pdisc check,torb docs skillregenerated,check-commits.sh origin/main HEAD. Both benchmarks print the checksum the C twins compute (10449088). Tier A/B are left to CI.Note:
a == bon two concrete stacks fails in the backend ("argument is Object(Stack)") forArrayStackas well, so the conformance program compares throughStack<Int>-typed parameters. Not caused by this change.2f921c101db176ad8bddApproved. Checklist for head
b176ad8:cons-stack-persistscovers copies in both directions, undo history, backtracking, clear on a shared copy, literals/of/to, equality and hash (incl. againstArrayStack) and a 10000-item stack with its copy. CI is green on this head (tier A, bootstrap, gates, pdisc, commit messages).top/countstay in step inpush/pop/clear; cells are immutable, so sharing the tail is safe; the iterator holds its own cell reference and does not see later changes.runtime/, the compiler orlist.c. The benchmarkarray-stackis the baseline the issue asks for.stacks-and-queues.mdandcollections.mdare updated,skills/is regenerated, and the pdisc sidecar hash is updated (pdisc check green).Stacktrait, no new boundary.Non-blocking:
a == bbackend failure on two concrete stacks (noted in the PR body, also true forArrayStack) deserves its own issue if there isn't one yet.==on two concrete stack values fails to compile #209==on two concrete stack values fails to compile #209