https://github.com/navicore/patch-seq/issues/393#398
Conversation
Code Review — Issue #393: Aux Stack Inside QuotationsOverall this is a well-motivated change with clear comments and good test coverage for the typechecker layer. A few things worth addressing before merge: Bug:
|
| Correctness | Error-path state leak in infer_quotation needs fix |
| Design | Duplicate alloca loop — minor but worth extracting |
| Test coverage | No integration test for the LLVM codegen path |
| Docs/examples | High quality; aux-in-quotations.seq is excellent |
| Overall | Solid design, clean typechecker expansion; address the error paths and add one integration test before merging |
┌────────────────────────────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ Item │ Fix │ ├────────────────────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Bug: state leak on error │ Restructured: body inference and balance check now run inside an immediately-invoked closure that returns │ │ paths in infer_quotation │ Result<Effect, String>. State (current_aux_stack, quotation_id_stack, expected_quotation_type) is restored │ │ │ unconditionally before propagating the result. All error paths are now safe. │ ├────────────────────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Duplicate aux-slot │ Extracted emit_aux_slots(count) helper. Three call sites (codegen_word, quotation arm, closure arm) now share one │ │ allocation loop │ implementation. │ ├────────────────────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ │ Added 4 tests to tests/integration/src/test-aux.seq using test.assert-eq: round-trip, nested quotations with isolated │ │ No integration test for │ aux, aux in list.fold callback, aux in closure body. Also fixed pre-existing test-if-else to be self-contained (it │ │ the LLVM codegen path │ took an argument from a manual main, which broke when the file became framework-driven). The file went from 0 tests in │ │ │ the runner to 10 tests, all passing. │ ├────────────────────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Misleading "sum of │ The example body had swap on a single-element stack — undefined behavior that happened to produce deterministic output │ │ squares" comment (turned │ by reading the runtime's temp stack memory. Replaced with a correct binary-to-decimal conversion via Horner: │ │ out to be a real bug) │ [1,0,1,1] → 11. │ └────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ just ci clean, 10 aux integration tests pass, one bonus bug fixed.
Code Review — Issue #393: Aux Stack in QuotationsThis is a clean, well-scoped implementation. The design is sound (quotations already compile to independent LLVM functions, so giving each its own aux slot table is a natural fit), and the PR follows existing patterns throughout. A few notes below: What Works WellIIFE cleanup pattern ( Per-quotation depth tracking
Test quality Minor IssuesUnnecessary *self.expected_quotation_type.borrow_mut() = expected_for_this_quotation.clone();
*self.expected_quotation_type.borrow_mut() = expected_for_this_quotation;(This is purely cosmetic — zero runtime cost either way.)
The function doc says "Caller is responsible for resetting /// Clears `current_aux_slots`, then emits `count` fresh `alloca %Value`
/// instructions and records their names.
ConsiderationsExpected type restoration on error In the original code, if Quotation ID uniqueness assumption The implementation implicitly requires parser-assigned quotation IDs to be stable and unique across the whole program. This appears to be an existing guarantee, but No runtime test for repeated invocation The Test Correctness Spot-check
SummaryApproved from a design and correctness standpoint. The two items worth a quick follow-up are the unnecessary |
No description provided.