Stage 1 Task 3. self-host-test checks results but not which path ran. This runs the portable analyzer (backend/analyze-form) on a corpus of non-stateful forms and asserts NONE raise :jolt/uncompilable — i.e. the self-hosted analyzer compiled them, not the interpreter fallback. Inverse sanity list confirms a few intentional-interpret forms (ns/defmacro/require/set?/letfn) still punt, so the harness can't pass by compiling everything. 29 must-compile (incl set literals from Task 1) + 5 must-punt, 0 failures. As Stage 1 parity grows, forms move from the punt list into must-compile; when the fallback set equals the frozen intentional stateful set, the bootstrap is retireable.
64 lines
2.8 KiB
Text
64 lines
2.8 KiB
Text
# Fallback-zero verification (Stage 1 Task 3).
|
|
#
|
|
# self-host-test.janet checks observable RESULTS but not WHICH path ran — a form
|
|
# that silently fell back to the interpreter still "passes" there. This harness
|
|
# checks the path: it runs the portable analyzer (jolt.analyzer/analyze, via
|
|
# backend/analyze-form) on a corpus of NON-STATEFUL forms and asserts NONE raise
|
|
# :jolt/uncompilable — i.e. the self-hosted analyzer actually COMPILED them.
|
|
#
|
|
# As analyzer↔compiler.janet parity grows (Stage 1), move forms from the
|
|
# "intentional fallback" sanity list into the must-compile corpus. The day the
|
|
# fallback set equals the frozen intentional stateful set, the Janet bootstrap
|
|
# compiler is retireable.
|
|
#
|
|
# Mechanism: backend/analyze-form throws (a "jolt/uncompilable: …" string) for a
|
|
# punted form; (protect …) turns that into [false msg]. [true ir] == compiled.
|
|
|
|
(import ../../src/jolt/backend :as backend)
|
|
(use ../../src/jolt/api)
|
|
(use ../../src/jolt/reader)
|
|
|
|
(def ctx (init))
|
|
|
|
(defn- analyzes? [s]
|
|
# true if the analyzer produced IR (compiled), false if it punted/uncompilable.
|
|
(def r (protect (backend/analyze-form ctx (parse-string s))))
|
|
(and (r 0) true))
|
|
|
|
# --- Must compile: pure, non-stateful value production. NONE may punt. ---
|
|
(def must-compile
|
|
[# set literals (Task 1)
|
|
"#{1 2 3}" "#{}" "#{:a :b :c}" "#{(inc 0) 2}" "(conj #{1 2} 3)"
|
|
"[#{1 2} {:s #{3}}]" "(let [x 5] #{x (inc x)})"
|
|
# other literals
|
|
"[1 2 3]" "{:a 1 :b 2}" "{:k (inc 0)}" "[[1] [2 3]]" "42" ":kw" "\"str\""
|
|
# control flow + binding
|
|
"(+ 1 2)" "(if true 1 2)" "(do 1 2 3)" "(let [a 1 b 2] (+ a b))"
|
|
"(fn [x] (* x x))" "(fn ([a] a) ([a b] (+ a b)))"
|
|
"(loop [i 0] (if (< i 3) (recur (inc i)) i))"
|
|
"(quote (a b c))" "(throw (ex-info \"x\" {}))"
|
|
"(try (inc 1) (catch :default e e))"
|
|
# def + calls into core
|
|
"(def answer 42)" "(map inc [1 2 3])" "(reduce + 0 [1 2 3])"
|
|
"(get {:a 1} :a)" "(vec (range 5))"])
|
|
|
|
# --- Intentional fallback (sanity sample): these SHOULD punt to the interpreter.
|
|
# Not the frozen set (that's Task 2) — just a few to confirm the boundary holds
|
|
# in the punt direction so the harness can't pass by compiling everything.
|
|
(def must-punt
|
|
["(ns foo.bar)" "(defmacro m [x] x)" "(require (quote [clojure.string]))"
|
|
"(set? #{1 2})" "(letfn [(f [n] (g n)) (g [n] (f n))] (f 1))"])
|
|
|
|
(var fails @[])
|
|
(each s must-compile
|
|
(unless (analyzes? s) (array/push fails (string "FALLBACK (should compile): " s))))
|
|
(each s must-punt
|
|
(when (analyzes? s) (array/push fails (string "COMPILED (should punt): " s))))
|
|
|
|
(printf "fallback-zero: %d must-compile + %d must-punt — %d failures"
|
|
(length must-compile) (length must-punt) (length fails))
|
|
(when (> (length fails) 0)
|
|
(print "\nFailures:")
|
|
(each f fails (printf " %s" f))
|
|
(os/exit 1))
|
|
(print "fallback-zero: OK (analyzer compiled the full non-stateful corpus)")
|