Numeric return-type hints: ^double/^long on a defn (round 3)
A ^double/^long return hint on a fn's name now (a) coerces the fn's value on the way out — exact->inexact / jolt->fx, like a JVM primitive return — and (b) types a call to it, so an accumulator over the result specializes: (defn ^double work [^double x ^double y] (+ (* x x) (* y y))) (loop [acc 0.0] (recur (+ acc (work a b)))) ; (+ acc (work ..)) -> fl+ The analyzer pushes the name's numeric tag onto each arity (:ret-nhint) for the back-end coercion, and resolve-global surfaces the callee's declared return (:num-ret, read from var meta) onto the :var node so jolt.passes.numeric types the call. defn carries the name hint through. This unblocks the accumulator-over-fn-result pattern that round 2 had to demote. The win is bounded by call overhead in an open/dispatched build (~1.15x on a hot loop whose body is a helper call); it compounds with direct-linking and, later, inlining. A numeric return hint is a contract, like ^long — redefining the var to return another type in an open build breaks it. Not yet: per-arity arglist return hints, (defn f (^double [x] ..)). Gate: test/chez/numeric-test.ss 39/39; full make test green, 0 new corpus divergences.
This commit is contained in:
parent
0db417a491
commit
5a9acd3cf4
6 changed files with 227 additions and 164 deletions
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue