WIP: feat: migrate builtins to extension functions and add rounding (Phase 2) #27
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/builtins-as-extensions"
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?
Unify all arithmetic operators under the extension function mechanism
introduced in Phase 1. The ArithExpr enum simplifies from 6 variants
(Lit, Var, NaryOp, BinOp, UnaryOp, Call) to 3 (Lit, Var, Call), with
all 10 built-in operators (+, -, *, /, min, max, div, rem, **, abs)
dispatched through FunctionRegistry as Call nodes.
Key changes:
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
nice one!
just a small issue;
[P2] Add runtime arity guard before extension/builtin dispatch — arith.rs (the ArithExpr::Call eval arm)
func.eval(&term_args) is called without checking func.signature().arity.accepts(term_args.len()). This is safe when the full pipeline runs (the Validate stage catches it), but public entry points like
eval_with_context and ground_theory_with_limit can reach this path directly. With builtins-as-extensions, the blast radius widens since all arithmetic ops now route through Call.
Extension authors naturally index into args (e.g. args[0]), so a wrong arg count will panic instead of returning an ArithError.
Fix: check arity after evaluating args, before func.eval(), and add an ArithError::ArityMismatch { name, expected, got } variant.
@hugooconnor wrote in https://codeberg.org/anuna/spindle-rust/pulls/27#issuecomment-11181143:
Good catch, thanks! Addressed, and I've added notes to my planning documents about being very careful when a refactor relaxes constraints from being structural to being convention.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.