Migrate clojure.core/set from a native shim to the kernel overlay tier
set was a native shim (apply jolt-hash-set (seq->list coll)). It is a pure composition, so the Clojure version (apply hash-set (seq coll)) lowers to the same code. The compiler uses set, but only off the emit path (the backend's bare-native-names def and type inference), so it can live in the kernel tier: compiling that tier never calls set, and by the time those callers run the tier is already bound. This is distinct from boolean, which the backend calls for every :if node on the emit path. Moving boolean even to the kernel tier deadlocks (compiling the tier that defines boolean needs boolean), so boolean stays native. Added a comment in predicates.ss recording that. Re-mint converges in 3 passes and the benchmark suite is unchanged within noise (collections 43.3 vs 43.1, binary-trees 367 vs 367, the rest flat).
This commit is contained in:
parent
3d0cbed3c5
commit
d77b4e6420
5 changed files with 310 additions and 298 deletions
|
|
@ -11,9 +11,9 @@
|
|||
(define (jolt-array-map . kvs) (jolt-array-map-build kvs))
|
||||
(define (jolt-hash-map-fn . kvs) (jolt-hash-map-build kvs))
|
||||
|
||||
;; set: realize any seqable to a list, then dedup through the set ctor. nil -> #{}.
|
||||
(define (jolt-set coll)
|
||||
(if (jolt-nil? coll) (jolt-hash-set) (apply jolt-hash-set (seq->list coll))))
|
||||
;; set lives in the kernel overlay tier (clojure/core/00-kernel.clj): it's a pure
|
||||
;; composition (apply hash-set (seq coll)) the compiler uses only off the emit path,
|
||||
;; so the Clojure version lowers to the same code without a bootstrap cycle.
|
||||
|
||||
;; rand: a flonum in [0, n) (n defaults to 1.0) — jolt is all-flonum, so the
|
||||
;; result is a double like every other number.
|
||||
|
|
@ -24,6 +24,5 @@
|
|||
(def-var! "clojure.core" "hash-map" jolt-hash-map-fn)
|
||||
(def-var! "clojure.core" "hash-set" jolt-hash-set)
|
||||
(def-var! "clojure.core" "array-map" jolt-array-map)
|
||||
(def-var! "clojure.core" "set" jolt-set)
|
||||
(def-var! "clojure.core" "rand" jolt-rand)
|
||||
(def-var! "clojure.core" "map-entry?" jolt-map-entry?)
|
||||
|
|
|
|||
|
|
@ -33,7 +33,11 @@
|
|||
(define (jolt-fn? x) (procedure? x))
|
||||
(define (jolt-boolean-pred? x) (boolean? x))
|
||||
|
||||
;; (boolean x) coerces truthiness (nil/false -> false, else true).
|
||||
;; (boolean x) coerces truthiness (nil/false -> false, else true). MUST stay native:
|
||||
;; the backend's emit path calls clojure.core/boolean for every :if node
|
||||
;; (backend_scheme.clj bool tracking), so it has to exist before ANY compilation,
|
||||
;; including the kernel overlay tier (whose own fns contain `if`). Migrating it even
|
||||
;; to the kernel tier deadlocks: compiling the tier that defines boolean needs boolean.
|
||||
(define (jolt-boolean x) (if (jolt-truthy? x) #t #f))
|
||||
|
||||
;; (name x): keyword/symbol -> name string; string -> itself.
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -116,6 +116,8 @@
|
|||
(def-var! "clojure.core" "mapv" (letrec ((mapv (lambda (f . colls) (let fnrec5542 ((f f) (colls (list->cseq colls))) (jolt-invoke (var-deref "clojure.core" "vec") (jolt-apply jolt-map f colls)))))) mapv)))
|
||||
(guard (e (#t #f))
|
||||
(def-var! "clojure.core" "update" (letrec ((update (lambda (m k f . args) (let fnrec5543 ((m m) (k k) (f f) (args (list->cseq args))) (jolt-assoc m k (jolt-apply f (jolt-get m k) args)))))) update)))
|
||||
(guard (e (#t #f))
|
||||
(def-var! "clojure.core" "set" (letrec ((set (lambda (coll) (let fnrec5544 ((coll coll)) (if (jolt-nil? coll) (jolt-hash-set) (jolt-apply jolt-hash-set (jolt-seq coll))))))) set)))
|
||||
(guard (e (#t #f))
|
||||
(def-var! "clojure.core" "vreset!" (letrec ((vreset! (lambda (vol newval) (let fnrec4683 ((vol vol) (newval newval)) (begin (jolt-invoke (var-deref "jolt.host" "ref-put!") vol (keyword #f "val") newval) newval))))) vreset!)))
|
||||
(guard (e (#t #f))
|
||||
|
|
@ -485,9 +487,9 @@
|
|||
(guard (e (#t #f))
|
||||
(def-var! "clojure.core" "trampoline" (letrec ((trampoline (case-lambda ((f) (let fnrec4585 ((f f)) (let* ((ret (jolt-invoke f))) (if (jolt-truthy? (jolt-invoke (var-deref "clojure.core" "fn?") ret)) (trampoline ret) ret)))) ((f . args) (let fnrec4586 ((f f) (args (list->cseq args))) (trampoline (lambda () (let fnrec4587 () (jolt-apply f args))))))))) trampoline)))
|
||||
(guard (e (#t #f))
|
||||
(def-var! "clojure.core" "max" (letrec ((_max (case-lambda ((x) (let fnrec4588 ((x x)) x)) ((x y) (let fnrec4589 ((x x) (y y)) (if (> x y) x y))) ((x y . more) (let fnrec4590 ((x x) (y y) (more (list->cseq more))) (jolt-reduce _max (_max x y) more)))))) _max)))
|
||||
(def-var! "clojure.core" "max" (letrec ((max (case-lambda ((x) (let fnrec4588 ((x x)) x)) ((x y) (let fnrec4589 ((x x) (y y)) (if (> x y) x y))) ((x y . more) (let fnrec4590 ((x x) (y y) (more (list->cseq more))) (jolt-reduce max (max x y) more)))))) max)))
|
||||
(guard (e (#t #f))
|
||||
(def-var! "clojure.core" "min" (letrec ((_min (case-lambda ((x) (let fnrec4591 ((x x)) x)) ((x y) (let fnrec4592 ((x x) (y y)) (if (< x y) x y))) ((x y . more) (let fnrec4593 ((x x) (y y) (more (list->cseq more))) (jolt-reduce _min (_min x y) more)))))) _min)))
|
||||
(def-var! "clojure.core" "min" (letrec ((min (case-lambda ((x) (let fnrec4591 ((x x)) x)) ((x y) (let fnrec4592 ((x x) (y y)) (if (< x y) x y))) ((x y . more) (let fnrec4593 ((x x) (y y) (more (list->cseq more))) (jolt-reduce min (min x y) more)))))) min)))
|
||||
(guard (e (#t #f))
|
||||
(def-var! "clojure.core" "reverse" (letrec ((reverse (lambda (coll) (let fnrec4594 ((coll coll)) (jolt-reduce jolt-conj (jolt-list ) coll))))) reverse)))
|
||||
(guard (e (#t #f))
|
||||
|
|
|
|||
|
|
@ -43,3 +43,10 @@
|
|||
(defn mapv [f & colls] (vec (apply map f colls)))
|
||||
|
||||
(defn update [m k f & args] (assoc m k (apply f (get m k) args)))
|
||||
|
||||
;; set: realize a seqable and dedup through the set constructor; nil -> #{}. The
|
||||
;; compiler uses it off the emit path (backend bare-native-names, type inference),
|
||||
;; so unlike boolean it can live here — compiling this tier never calls set, and by
|
||||
;; the time those callers run the tier is bound. Pure composition of hash-set/seq/
|
||||
;; apply, so it lowers to the same code the native shim did.
|
||||
(defn set [coll] (if (nil? coll) #{} (apply hash-set (seq coll))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue