Real nREPL interrupt + thread-local *ns* (jolt-amzy, jolt-6rld)

Two nREPL divergences the library shakeout surfaced — both have a real host
mechanism on Chez.

Interrupt (jolt-amzy): Chez's engine timer (set-timer + thread-local
timer-interrupt-handler) is polled at procedure-call / loop back-edges, so a
running computation — even a tight loop — can be aborted from another thread.
concurrency.ss adds jolt.host/{make-interrupt, interrupt!, run-interruptible}: an
interrupt token is a shared box; run-interruptible arms a periodic timer whose
handler escapes (call/cc) when the token is set, throwing {:jolt/interrupted true}.
The eval thread is reused, not abandoned. (A thread blocked in a __collect_safe
foreign call only sees it on return — like the JVM not killing native code.)

Thread-local *ns* (jolt-6rld): chez-current-ns is now a Chez thread-parameter, so
each session worker / future has its own current ns (vars stay global, only the
pointer is per-thread). *ns* reads derive from it (dyn-binding.ss), and a bound
*ns* drives chez-current-ns — so (binding [*ns* the-ns] (load-string code))
resolves against the-ns, and concurrent in-ns across threads don't clobber each
other. Single-threaded behaviour is unchanged. All runtime .ss — no re-mint.
This commit is contained in:
Yogthos 2026-06-22 18:57:16 -04:00
parent f30a517cf7
commit c18f8087f0
6 changed files with 79 additions and 8 deletions

View file

@ -102,12 +102,20 @@
;; var-deref (rt.ss): the compiled-code read path for every clojure.core var
;; reference. Consult the stack first; fall straight back to the root (NOT through
;; jolt-var-get's unbound-error path) so undefined-var reads keep prior behaviour.
;; The *ns* var cell — its reads are thread-local: with no thread-binding they
;; derive from chez-current-ns (a thread-parameter), so *ns* tracks in-ns per
;; thread and a (binding [*ns* ..]) drives resolution (jolt-6rld). Captured now
;; that *ns* is defined (ns.ss loaded earlier); chez-current-ns consults it too.
(set! star-ns-cell (jolt-var "clojure.core" "*ns*"))
(define %dyn-rt-var-deref var-deref)
(set! var-deref
(lambda (ns name)
(let ((cell (jolt-var ns name)))
(let ((bv (dyn-binding-value cell)))
(if (eq? bv dyn-no-binding) (var-cell-root cell) bv)))))
(cond ((not (eq? bv dyn-no-binding)) bv)
((eq? cell star-ns-cell) (intern-ns! (chez-current-ns)))
(else (var-cell-root cell)))))))
;; jolt-var-get (vars.ss): the var-get fn + deref/@ on a cell. Stack first, then
;; the original (which errors on an unbound root, matching Clojure).
@ -116,7 +124,9 @@
(lambda (v)
(if (var-cell? v)
(let ((bv (dyn-binding-value v)))
(if (eq? bv dyn-no-binding) (%dyn-var-get v) bv))
(cond ((not (eq? bv dyn-no-binding)) bv)
((eq? v star-ns-cell) (intern-ns! (chez-current-ns)))
(else (%dyn-var-get v))))
(%dyn-var-get v))))
;; var-cell keys hash/compare by ns/name (jolt=2 in vars.ss already compares