Fold type predicates on proven types (jolt-wcw) (#129)
When the collection-type inference proves an argument's type, number?/ string?/keyword?/record?/nil?/some? fold to a compile-time boolean. A const-fold now runs after inference so a folded predicate propagates and collapses any if it gates to the taken branch. Sound by construction: only a provable answer folds, and only when the argument is side-effect-free (a const or local) so dropping its evaluation is a no-op. Unknown types (:any/:truthy) and impure args keep the call. vector?/set?/map? are left out — the :vec tag conflates a real vector with a range/seq, so vector? could be wrong. 50M-iter loop, same shape isolated with a carry-only control: number? call+ branch 5080ms, predicate folded 1365ms — matching the 1417ms control floor, so the 3.7x is entirely the eliminated call+branch. Co-authored-by: Yogthos <yogthos@gmail.com>
This commit is contained in:
parent
b6fd49f5a8
commit
a029afc127
3 changed files with 107 additions and 1 deletions
|
|
@ -39,5 +39,7 @@
|
|||
(if (and @dirty (< i 8))
|
||||
(recur (inc i) n2)
|
||||
n2)))]
|
||||
(run-inference opt))
|
||||
;; a final const-fold after inference propagates any predicate folded to a
|
||||
;; constant (jolt-wcw), collapsing the `if` it gates to the taken branch.
|
||||
(const-fold (run-inference opt)))
|
||||
(const-fold node)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue