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:
Yogthos 2026-06-18 19:40:17 -04:00
parent fc6551f877
commit b7158e0690
5 changed files with 218 additions and 4 deletions

65
test/chez/_seqpred.janet Normal file
View 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
View 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))

View file

@ -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)))