Chez Phase 2 (inc N): type (jolt-fmm4)
Implement (type x) on the Chez RT (host/chez/natives-meta.ss). Mirrors the seed's core-type: the :type metadata wins when present, a record yields its ns-qualified class-name SYMBOL (user.TyR — no-ns sentinel #f so it = the overlay's (symbol (str t))), everything else a host-taxonomy keyword (:number/:string/:vector/:map/:set/:seq/:fn/…). Total by construction — a non-record value falling through to a crash would read as a divergence, so the cond covers every value type incl. the host wrappers (atom/volatile/regex/var/ transient/uuid -> :jolt/*, a :jolt/type-tagged map like ex-info -> its tag, sorted-set -> :jolt/sorted-set, sorted-map -> :map) and a final :object. Also pin sequential?/seq? on lazy seqs (test/chez/_seqpred.janet): the inc M seq? re-def-var! fix already covers sequential? transitively (sequential? is overlay and delegates to seq?), so no code change — the earlier "still broken" note was wrong, it assumed sequential? was native like seq?. Prelude corpus parity 2000 -> 2002 (the two type cases), floor raised, 0 new divergences. Gate: _type 37/37 + _seqpred 22/22 (both vs build/jolt oracle), emit-test 321/321, full jpm test, conformance 355x3.
This commit is contained in:
parent
fc6551f877
commit
b7158e0690
5 changed files with 218 additions and 4 deletions
|
|
@ -44,3 +44,68 @@
|
|||
|
||||
(def-var! "clojure.core" "meta" jolt-meta)
|
||||
(def-var! "clojure.core" "with-meta" jolt-with-meta)
|
||||
|
||||
;; (type x) — Clojure's (or (:type (meta x)) (class x)). With no JVM classes the
|
||||
;; "class" is a host taxonomy: a record yields its ns-qualified class-name SYMBOL
|
||||
;; (user.TyR), everything else a keyword (:number/:vector/:seq/…). Mirrors the
|
||||
;; seed's core-type (src/jolt/core_io.janet). MUST be total — a non-record value
|
||||
;; falling through to a crash would read as a divergence, not the right keyword.
|
||||
;; Forward refs (jolt-lazyseq?, the sorted-htable / wrapper predicates) all bind by
|
||||
;; call time (every host .ss loads before any user expr runs).
|
||||
(define ty-kw-type (keyword #f "type")) ; the :type meta key
|
||||
(define ty-kw-jtype (keyword "jolt" "type")) ; tagged-map discriminator (ex-info)
|
||||
(define ty-number (keyword #f "number"))
|
||||
(define ty-string (keyword #f "string"))
|
||||
(define ty-keyword (keyword #f "keyword"))
|
||||
(define ty-symbol (keyword #f "symbol"))
|
||||
(define ty-boolean (keyword #f "boolean"))
|
||||
(define ty-char (keyword #f "char"))
|
||||
(define ty-vector (keyword #f "vector"))
|
||||
(define ty-map (keyword #f "map"))
|
||||
(define ty-set (keyword #f "set"))
|
||||
(define ty-seq (keyword #f "seq"))
|
||||
(define ty-fn (keyword #f "fn"))
|
||||
(define ty-atom (keyword "jolt" "atom"))
|
||||
(define ty-volatile (keyword "jolt" "volatile"))
|
||||
(define ty-regex (keyword "jolt" "regex"))
|
||||
(define ty-var (keyword "jolt" "var"))
|
||||
(define ty-transient (keyword "jolt" "transient"))
|
||||
(define ty-uuid (keyword "jolt" "uuid"))
|
||||
(define ty-sorted-set (keyword "jolt" "sorted-set"))
|
||||
(define ty-object (keyword #f "object"))
|
||||
|
||||
(define (jolt-type x)
|
||||
(let* ((m (jolt-meta x))
|
||||
(override (if (jolt-nil? m) jolt-nil (jolt-get m ty-kw-type jolt-nil))))
|
||||
(cond
|
||||
((not (jolt-nil? override)) override) ; :type meta wins
|
||||
;; record -> ns.Name symbol. No-ns sentinel is #f (not jolt-nil) so it = the
|
||||
;; overlay's (symbol (str t)) — jolt= compares the ns field with equal?.
|
||||
((jrec? x) (jolt-symbol #f (jrec-tag x)))
|
||||
((jolt-nil? x) jolt-nil)
|
||||
((boolean? x) ty-boolean)
|
||||
((number? x) ty-number)
|
||||
((string? x) ty-string)
|
||||
((keyword? x) ty-keyword)
|
||||
((symbol-t? x) ty-symbol)
|
||||
((char? x) ty-char)
|
||||
;; host wrappers — match the seed's :jolt/* tags (checked before the
|
||||
;; collection arms; none of these are pvec/pmap/pset).
|
||||
((jolt-atom? x) ty-atom)
|
||||
((jvol? x) ty-volatile)
|
||||
((jolt-regex? x) ty-regex)
|
||||
((var-cell? x) ty-var)
|
||||
((jolt-transient? x) ty-transient)
|
||||
((juuid? x) ty-uuid)
|
||||
((htable-sorted-set? x) ty-sorted-set)
|
||||
((htable-sorted-map? x) ty-map)
|
||||
;; collections — pvec INCLUDES map entries (:vector, like the seed's jvec?).
|
||||
((pvec? x) ty-vector)
|
||||
((pmap? x) ; a :jolt/type-tagged map (ex-info) -> its tag
|
||||
(let ((t (jolt-get x ty-kw-jtype jolt-nil))) (if (jolt-nil? t) ty-map t)))
|
||||
((pset? x) ty-set)
|
||||
((or (cseq? x) (empty-list-t? x) (jolt-lazyseq? x)) ty-seq)
|
||||
((procedure? x) ty-fn)
|
||||
(else ty-object))))
|
||||
|
||||
(def-var! "clojure.core" "type" jolt-type)
|
||||
|
|
|
|||
|
|
@ -286,9 +286,9 @@
|
|||
(let ((s (jrec-pr v))) (substring s 1 (string-length s)))))
|
||||
(%r-str-render-one v))))
|
||||
|
||||
;; NOTE: `type` is not shimmed on Chez yet (nil); a record-aware override here
|
||||
;; would turn non-record (type x) crashes into divergences. Deferred to a `type`
|
||||
;; increment with proper class names.
|
||||
;; `type` lives in natives-meta.ss (jolt-fmm4): it needs jolt-meta for the :type
|
||||
;; override and a total value->taxonomy mapping, so it sits with meta — a record
|
||||
;; yields (jolt-symbol #f (jrec-tag x)), the ns.Name class-name symbol.
|
||||
|
||||
(def-var! "clojure.core" "make-deftype-ctor" make-deftype-ctor)
|
||||
(def-var! "clojure.core" "make-protocol" make-protocol)
|
||||
|
|
|
|||
65
test/chez/_seqpred.janet
Normal file
65
test/chez/_seqpred.janet
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
# sequential? / seq? on lazy seqs (jolt-2o7x follow-up). The inc M fix made the
|
||||
# native seq? var recognize a lazy-seq (re-def-var!, not just set!). sequential?
|
||||
# is overlay (`(defn sequential? [x] (or (vector? x) (seq? x)))`), so it inherits
|
||||
# the fix transitively; this pins that both predicates agree with the JVM oracle
|
||||
# over every lazy-seq-producing form (and the native =/hash path via set!).
|
||||
# Expectations are the build/jolt (JVM-canonical) values.
|
||||
#
|
||||
# janet test/chez/_seqpred.janet
|
||||
(def jolt-bin (or (os/getenv "JOLT_BIN") "bin/jolt-chez"))
|
||||
|
||||
(def cases
|
||||
[# --- seq? over lazy seqs ---
|
||||
# (NB: not (seq? (range 3)) — the seed makes range an eager vector, chez a lazy
|
||||
# seq; a range-container divergence, not the predicate. sequential? agrees on it.)
|
||||
["seq? map" "(seq? (map inc [1 2 3]))" "true"]
|
||||
["seq? filter" "(seq? (filter odd? [1 2 3]))" "true"]
|
||||
["seq? lazy-seq" "(seq? (lazy-seq (cons 1 nil)))" "true"]
|
||||
["seq? take iterate" "(seq? (take 3 (iterate inc 0)))" "true"]
|
||||
["seq? cons onto lazy" "(seq? (cons 0 (range 3)))" "true"]
|
||||
["seq? vector false" "(seq? [1 2 3])" "false"]
|
||||
["seq? map-coll false" "(seq? {:a 1})" "false"]
|
||||
["seq? nil false" "(seq? nil)" "false"]
|
||||
|
||||
# --- sequential? over lazy seqs (overlay, delegates to seq?) ---
|
||||
["sequential? range" "(sequential? (range 3))" "true"]
|
||||
["sequential? map" "(sequential? (map inc [1 2 3]))" "true"]
|
||||
["sequential? filter" "(sequential? (filter odd? [1 2 3]))" "true"]
|
||||
["sequential? lazy-seq" "(sequential? (lazy-seq (cons 1 nil)))" "true"]
|
||||
["sequential? infinite" "(sequential? (take 2 (repeat 9)))" "true"]
|
||||
["sequential? vector" "(sequential? [1 2 3])" "true"]
|
||||
["sequential? list" "(sequential? '(1 2 3))" "true"]
|
||||
["sequential? map false" "(sequential? {:a 1})" "false"]
|
||||
["sequential? set false" "(sequential? #{1 2})" "false"]
|
||||
["sequential? nil false" "(sequential? nil)" "false"]
|
||||
|
||||
# --- native =/hash path (jolt-sequential? via set!) over a raw lazy seq ---
|
||||
["= vec lazyseq" "(= [0 1 2] (range 3))" "true"]
|
||||
["= lazyseq vec" "(= (range 3) [0 1 2])" "true"]
|
||||
["= lazyseq list" "(= (map inc [0 1]) '(1 2))" "true"]
|
||||
["set contains lazyseq" "(contains? #{[0 1 2]} (vec (range 3)))" "true"]])
|
||||
|
||||
(defn run-capture [expr]
|
||||
(def proc (os/spawn [jolt-bin "-e" expr] :p {:out :pipe :err :pipe}))
|
||||
(def out (ev/read (proc :out) 0x100000))
|
||||
(def err (ev/read (proc :err) 0x100000))
|
||||
(def code (os/proc-wait proc))
|
||||
(def lines (filter (fn [l] (not (empty? l)))
|
||||
(string/split "\n" (string/trim (if out (string out) "")))))
|
||||
[code (if (empty? lines) "" (last lines)) (if err (string err) "")])
|
||||
|
||||
(var pass 0)
|
||||
(def fails @[])
|
||||
(each [label expr expected] cases
|
||||
(def [code got err] (run-capture expr))
|
||||
(cond
|
||||
(not= code 0) (array/push fails [label (string "exit " code "; err: " (string/trim err))])
|
||||
(= got expected) (++ pass)
|
||||
(array/push fails [label (string "want `" expected "`, got `" got "`")])))
|
||||
|
||||
(printf "\n_seqpred parity [%s]: %d/%d passed" jolt-bin pass (length cases))
|
||||
(when (> (length fails) 0)
|
||||
(printf "%d FAIL(s):" (length fails))
|
||||
(each [l m] fails (printf " FAIL [%s] %s" l m)))
|
||||
(flush)
|
||||
(os/exit (if (empty? fails) 0 1))
|
||||
82
test/chez/_type.janet
Normal file
82
test/chez/_type.janet
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
# jolt-fmm4 — (type x) on Chez: :type meta override, record class-name symbol,
|
||||
# and a comprehensive value->taxonomy mapping (no value type crashes -> must be
|
||||
# total, the recorded gotcha). Expectations are the build/jolt (seed) oracle.
|
||||
# Producers that the seed makes eager (range) are avoided: (type (range 3)) is
|
||||
# :vector on the seed (eager) but :seq on chez (lazy) — a range-container
|
||||
# divergence unrelated to `type`, covered elsewhere.
|
||||
#
|
||||
# janet test/chez/_type.janet
|
||||
(def jolt-bin (or (os/getenv "JOLT_BIN") "bin/jolt-chez"))
|
||||
|
||||
(def cases
|
||||
[# --- scalars ---
|
||||
["int" "(type 5)" ":number"]
|
||||
["float" "(type 5.0)" ":number"]
|
||||
["ratio-ish" "(type (/ 10 2))" ":number"]
|
||||
["string" "(type \"s\")" ":string"]
|
||||
["keyword" "(type :k)" ":keyword"]
|
||||
["symbol" "(type 'x)" ":symbol"]
|
||||
["true" "(type true)" ":boolean"]
|
||||
["false" "(type false)" ":boolean"]
|
||||
["nil" "(type nil)" ""]
|
||||
["char" "(type \\a)" ":char"]
|
||||
|
||||
# --- collections ---
|
||||
["vector" "(type [1 2])" ":vector"]
|
||||
["empty vector" "(type [])" ":vector"]
|
||||
["map" "(type {:a 1})" ":map"]
|
||||
["set" "(type #{1})" ":set"]
|
||||
["list" "(type '(1 2))" ":seq"]
|
||||
["empty list" "(type '())" ":seq"]
|
||||
["map entry" "(type (first {:a 1}))" ":vector"]
|
||||
["lazy map" "(type (map inc [1 2]))" ":seq"]
|
||||
["lazy filter" "(type (filter odd? [1 2 3]))" ":seq"]
|
||||
["lazy-seq" "(type (lazy-seq (cons 1 nil)))" ":seq"]
|
||||
["take iterate" "(type (take 2 (iterate inc 0)))" ":seq"]
|
||||
["fn" "(type inc)" ":fn"]
|
||||
["sorted-map" "(type (sorted-map :a 1))" ":map"]
|
||||
["sorted-set" "(type (sorted-set 1))" ":jolt/sorted-set"]
|
||||
|
||||
# --- :type meta override (the headline jolt-fmm4 case) ---
|
||||
["meta override" "(type (with-meta [1] {:type :custom}))" ":custom"]
|
||||
["meta override map" "(type (with-meta {:a 1} {:type :rec}))" ":rec"]
|
||||
["meta no :type" "(type (with-meta [1] {:other 9}))" ":vector"]
|
||||
|
||||
# --- record -> ns-qualified class-name symbol ---
|
||||
["record symbol" "(do (defrecord TyR [a]) (type (->TyR 1)))" "user.TyR"]
|
||||
["record roundtrip" "(do (defrecord TyR [a]) (= (symbol (str (type (->TyR 1)))) (type (->TyR 1))))" "true"]
|
||||
["record is symbol" "(do (defrecord TyR [a]) (symbol? (type (->TyR 1))))" "true"]
|
||||
|
||||
# --- exotic host wrappers (seed :jolt/* tags; total, never crash) ---
|
||||
["atom" "(type (atom 1))" ":jolt/atom"]
|
||||
["volatile" "(type (volatile! 1))" ":jolt/volatile"]
|
||||
["regex" "(type #\"re\")" ":jolt/regex"]
|
||||
["var" "(do (def vx 1) (type (var vx)))" ":jolt/var"]
|
||||
["transient" "(type (transient []))" ":jolt/transient"]
|
||||
["uuid" "(type (random-uuid))" ":jolt/uuid"]
|
||||
["ex-info" "(type (ex-info \"x\" {}))" ":jolt/ex-info"]])
|
||||
|
||||
(defn run-capture [expr]
|
||||
(def proc (os/spawn [jolt-bin "-e" expr] :p {:out :pipe :err :pipe}))
|
||||
(def out (ev/read (proc :out) 0x100000))
|
||||
(def err (ev/read (proc :err) 0x100000))
|
||||
(def code (os/proc-wait proc))
|
||||
(def lines (filter (fn [l] (not (empty? l)))
|
||||
(string/split "\n" (string/trim (if out (string out) "")))))
|
||||
[code (if (empty? lines) "" (last lines)) (if err (string err) "")])
|
||||
|
||||
(var pass 0)
|
||||
(def fails @[])
|
||||
(each [label expr expected] cases
|
||||
(def [code got err] (run-capture expr))
|
||||
(cond
|
||||
(not= code 0) (array/push fails [label (string "exit " code "; err: " (string/trim err))])
|
||||
(= got expected) (++ pass)
|
||||
(array/push fails [label (string "want `" expected "`, got `" got "`")])))
|
||||
|
||||
(printf "\n_type parity [%s]: %d/%d passed" jolt-bin pass (length cases))
|
||||
(when (> (length fails) 0)
|
||||
(printf "%d FAIL(s):" (length fails))
|
||||
(each [l m] fails (printf " FAIL [%s] %s" l m)))
|
||||
(flush)
|
||||
(os/exit (if (empty? fails) 0 1))
|
||||
|
|
@ -193,8 +193,10 @@
|
|||
# bound-fn*/get-thread-bindings/alter-var-root; var-deref + jolt-var-get chained
|
||||
# onto the stack. Also fixed seq? to recognize a lazy-seq, which unblocked
|
||||
# with-in-str/line-seq) 2000.
|
||||
# jolt-fmm4 ((type x) — :type meta override, record ns-qualified class-name
|
||||
# symbol, total value->taxonomy keyword mapping) 2002.
|
||||
# Strided runs scale down.
|
||||
(def base-floor (scan-number (or (os/getenv "JOLT_CHEZ_PRELUDE_FLOOR") "2000")))
|
||||
(def base-floor (scan-number (or (os/getenv "JOLT_CHEZ_PRELUDE_FLOOR") "2002")))
|
||||
(def floor (if (os/getenv "JOLT_CORPUS_LIMIT") 0 base-floor))
|
||||
(when (or (> (length diverged) 0) (< pass floor))
|
||||
(printf "REGRESSION: pass %d < floor %d or %d new divergence(s)" pass floor (length diverged)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue