Allow aux stack operations inside quotations #393
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
refactor
rust
technical-debt
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
navicore/patch-seq#393
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Summary
>auxandaux>are rejected inside quotations with:The workaround (extract to a named word) works but creates friction for common patterns like
list.foldcallbacks that need temporary storage.Motivation
When implementing algorithms that use
list.foldwith context beyond(acc, elem), the natural pattern is to stash a value on aux inside the fold quotation. For example, Horner's polynomial evaluation:Currently this requires extracting the fold body into a named word, which fragments the logic.
Proposed Change
Quotations are already compiled as separate LLVM functions with their own stack frames. The aux mechanism is compile-time
allocaslots at function entry — the same approach used for named words.Typechecker (
typechecker.rs)in_quotation_scopeguards ininfer_to_aux(line ~1354) andinfer_from_aux(line ~1385)aux_max_depths(currently keyed by word name)Codegen (
codegen/words.rs)codegen_quotation(line ~165), instead of clearing aux state defensively, look up the quotation's aux depth fromaux_slot_countsand emitalloca %Valueslots — the same pattern as word codegen (lines 81-89)%aux_slot_0,%aux_slot_1, etc., independent of the enclosing wordRuntime
No changes needed. Aux is purely compile-time allocas — zero overhead when not used.
Risk
Low. Quotation functions are already independent LLVM functions with their own frames. Adding allocas follows the established pattern. The typechecker already validates aux balance per-scope.
Context: discovered while implementing Shamir's Secret Sharing in Seq, where Lagrange interpolation requires fold callbacks with extra context.
implementation planed in https://github.com/navicore/patch-seq/blob/main/docs/design/AUX_IN_QUOTATIONS.md
github.com/navicore/patch-seq@166fea176ahttps://github.com/navicore/patch-seq/pull/398