init in compile mode is ~2.4 s (tier loading, analyzer self-compile, macro recompilation), paid by every process that builds a ctx from source — each jpm-test file, embedders, workers. init-cached marshals the built ctx to a disk image (same root-env dicts as snapshot/fork) and later processes unmarshal it in ~5 ms, any process: nothing from the baking process is needed at load. The cache key fingerprints the embedded .clj stdlib (which covers jolt-core: analyzer, IR, core tiers), the .janet seed sources next to the module, the janet version, the init opts, and the env knobs that shape a ctx (JOLT_PATH/ MUTABLE/AOT_CORE/FEATURES) — any change rebuilds. Corrupt or non-ctx images fall back to a rebuild (unmarshal of garbage can 'succeed' with a scalar, so the shape is checked, not just the throw). Writes are atomic (tmp + rename) so racing cold starts never publish a torn image. JOLT_NO_IMAGE_CACHE=1 opts out; JOLT_IMAGE_CACHE_DIR overrides the location (default TMPDIR). Test consumers switch to init-cached (harness, suite-worker, conformance, the behavioral unit/integration tests); tests that validate the bootstrap itself (bootstrap-fixpoint, staged-bootstrap, aot round-trip, direct-linking) and the deps tests (tmp-dir :paths would fragment the key) keep real init. Full jpm test: 2:46 -> 1:58 (~29%). New ctx-image-test covers cold/warm, cross-process load (subprocess runs defn/redef/macros/protocols/multimethods off the baked image), per-opts keying, and corrupt-image fallback.
60 lines
3.1 KiB
Text
60 lines
3.1 KiB
Text
# One-file worker for the clojure-test-suite battery. Loads the clojure.test
|
|
# shim, evaluates a single suite .cljc file, runs its deftests, and prints
|
|
# "pass fail error" to stdout. Used by the discovery pass to find files that
|
|
# hang under Jolt's eager evaluation (run under an external timeout).
|
|
(use ../../src/jolt/api)
|
|
(use ../../src/jolt/reader)
|
|
(use ../../src/jolt/evaluator)
|
|
(import ../../src/jolt/backend :as selfhost)
|
|
|
|
(defn- parse-forms [src]
|
|
(var s src) (def fs @[]) (var go true)
|
|
(while (and go (> (length (string/trim s)) 0))
|
|
(def r (protect (parse-next s)))
|
|
(if (not (r 0)) (set go false)
|
|
(let [p (r 1)] (set s (p 1)) (when (not (nil? (p 0))) (array/push fs (p 0))))))
|
|
fs)
|
|
|
|
# A helper, not a standalone test: it needs a .cljc path argument. When `jpm
|
|
# test` runs it with no args, no-op cleanly so it doesn't count as a failure.
|
|
(def path (get (dyn :args) 1))
|
|
|
|
(when path
|
|
# JOLT_COMPILE=1 runs the suite through the compile path (hybrid: hot forms
|
|
# compile, unsupported forms fall back to the interpreter) so the whole battery
|
|
# validates compile-mode correctness against the same baseline.
|
|
(def compile? (= "1" (os/getenv "JOLT_COMPILE")))
|
|
# JOLT_SELFHOST=1 routes each form through the self-hosted pipeline (the
|
|
# portable Clojure analyzer + Janet back end, hybrid with interpreter fallback)
|
|
# so the whole battery validates the self-hosted compiler against the baseline.
|
|
(def selfhost? (= "1" (os/getenv "JOLT_SELFHOST")))
|
|
(def ctx (init-cached (if compile? {:compile? true} {})))
|
|
(defn run-form [f]
|
|
(cond
|
|
selfhost? (selfhost/compile-and-eval ctx f)
|
|
compile? (eval-one ctx f)
|
|
(eval-form ctx @{} f)))
|
|
(each f (parse-forms (slurp "test/support/clojure_test.clj")) (run-form f))
|
|
|
|
# Pre-load the suite's own clojure.core-test.number-range helper ns if present
|
|
# (35 files require it for r/max-int, r/max-double, … — its :default branches are
|
|
# plain numeric literals Jolt can read). Its `ns` form sets the namespace; the
|
|
# test file's own `ns` form switches back afterwards.
|
|
(let [dir (string/slice path 0 (- (length path) (length (last (string/split "/" path)))))
|
|
nr (string dir "number_range.cljc")]
|
|
(when (os/stat nr)
|
|
(each f (parse-forms (slurp nr)) (protect (run-form f)))))
|
|
|
|
(eval-string ctx "(clojure.test/reset-report!)")
|
|
(each form (parse-forms (slurp path)) (protect (run-form form)))
|
|
(protect (eval-string ctx "(clojure.test/run-registered)"))
|
|
(def p (eval-string ctx "(clojure.test/n-pass)"))
|
|
(def f (eval-string ctx "(clojure.test/n-fail)"))
|
|
(def e (eval-string ctx "(clojure.test/n-error)"))
|
|
# A "dump" 2nd arg (or SUITE_DUMP env) also prints each failure/error message
|
|
# (one DUMP line each) for triage.
|
|
(when (or (os/getenv "SUITE_DUMP") (= "dump" (get (dyn :args) 2)))
|
|
(eval-string ctx "(doseq [m (clojure.test/failures)] (println (str \"DUMP \" m)))"))
|
|
# Counts on a sentinel line so parsers find it even if a test body printed to
|
|
# stdout (e.g. with-out-str / println-str tests).
|
|
(printf "@@COUNTS %d %d %d" (if (number? p) p 0) (if (number? f) f 0) (if (number? e) e 0)))
|