core: edn :readers/:default opts; uncaught throws no longer leak the callee's ns

clojure.edn was nearly complete (sets, #uuid/#inst, :eof all landed earlier);
the :readers opt was ignored and :default missing. Both work now — the
reader stores a tag as a :#name keyword, so the lookup normalizes it to the
symbol Clojure keys :readers with; :default gets (tag value); built-in data
readers stay the fallback. 8 new edn spec rows. This was the last open item
of jolt-0mb (the vendored walk/zip/data/edn battery has been green for a
while: 34/33/61/50, all clean).

Chasing the probe cascade ('Unable to resolve symbol: edn/...' after one
error) found a real evaluator bug: an interpreted fn body runs with
current-ns rebound to its DEFINING ns and restores it with a plain trailing
call — an UNCAUGHT throw skips every restore on the way out, leaving the ctx
stuck in the deepest callee's ns, where alias-qualified lookups then fail
(the same cascade previously seen via sci). The repair lives at the
TOP-LEVEL boundary (loader/eval-toplevel saves the entry ns and restores it
on error before re-raising) — NOT per-call defer/try, which builds a fiber
per frame and blew the C stack on deep interpreted recursion (file-seq)
when tried first. Regression tests cover the cross-eval leak and that
aliases keep resolving.
This commit is contained in:
Yogthos 2026-06-10 18:16:06 -04:00
parent fef99db6d8
commit 6260230231
6 changed files with 87 additions and 9 deletions

View file

@ -96,3 +96,20 @@
(print " passed")
(print "\nAll namespace tests passed!")
# An UNCAUGHT throw inside an interpreted fn body must restore the caller's
# current-ns (the body runs with current-ns rebound to the defining ns; the
# restore is a defer now). Pre-fix, the ctx was left stuck in the defining ns
# and every later alias-qualified lookup failed — the sci-bootstrap and
# clojure.edn "Unable to resolve alias/..." cascades.
(print "ns restored after uncaught throw...")
(let [ctx (fresh-ctx)]
(api/eval-string ctx "(in-ns (quote otherns))")
(api/eval-string ctx "(clojure.core/refer-clojure)")
(api/eval-string ctx "(defn boom [] (throw (ex-info \"x\" {})))")
(api/eval-string ctx "(in-ns (quote user))")
(assert (not ((protect (api/eval-string ctx "(otherns/boom)")) 0)) "boom throws")
(assert (= "user" (api/eval-string ctx "(str *ns*)")) "*ns* restored after uncaught throw")
(api/eval-string ctx "(require (quote [clojure.string :as s9]))")
(assert (= "A" (api/eval-string ctx "(s9/upper-case \"a\")")) "aliases still resolve"))
(print " ok")