JOLT_TRACE: one case-insensitive off-check for both enable paths

Review turned up that the disable vocabulary was the exact lowercase strings
"0"/"false"/"no", so JOLT_TRACE=off (or FALSE, No, n) fell through and ENABLED
tracing — the opposite of intent — and the whole-run and dev-mode checks
disagreed on the empty string. Fold both into one jolt-trace-env-off? predicate
(case-insensitive, incl. off/n); empty/unset carries no signal (dev still traces,
a whole run still doesn't).
This commit is contained in:
Yogthos 2026-07-04 15:51:13 -04:00
parent 7167af4830
commit 79002526bb

View file

@ -110,24 +110,33 @@
;; older seed during the first re-mint pass. ;; older seed during the first re-mint pass.
(let ((scv (var-deref "jolt.backend-scheme" "set-var-cache!"))) (let ((scv (var-deref "jolt.backend-scheme" "set-var-cache!")))
(when (procedure? scv) (scv #t))) (when (procedure? scv) (scv #t)))
;; JOLT_TRACE is a falsey value (case-insensitive) — the single predicate both the
;; dev-mode enable and the whole-run enable consult, so "off" never accidentally
;; means "on". An empty / unset value is NOT falsey here — it carries no signal, so
;; dev mode still traces and a whole run still doesn't.
(define (jolt-trace-env-off? e)
(and (string? e)
(let ((s (string-downcase e)))
(or (string=? s "0") (string=? s "false") (string=? s "no")
(string=? s "off") (string=? s "n")))))
;; Tail-frame history. Turning it on makes the emitter add a per-fn history push to ;; Tail-frame history. Turning it on makes the emitter add a per-fn history push to
;; every fn compiled AFTERWARD, and allocates this thread's ring. Suppressed when ;; every fn compiled AFTERWARD, and allocates this thread's ring. Suppressed when
;; JOLT_TRACE is explicitly falsey, so JOLT_TRACE=0 disables it even in dev mode. ;; JOLT_TRACE is a falsey value, so JOLT_TRACE=0 / off / no disables it in dev mode.
(define (jolt-enable-trace!) (define (jolt-enable-trace!)
(let ((e (getenv "JOLT_TRACE"))) (unless (jolt-trace-env-off? (getenv "JOLT_TRACE"))
(unless (and e (member e '("0" "false" "no"))) (let ((stf (var-deref "jolt.backend-scheme" "set-trace-frames!")))
(let ((stf (var-deref "jolt.backend-scheme" "set-trace-frames!"))) (when (procedure? stf) (stf #t)))
(when (procedure? stf) (stf #t))) (jolt-trace-enable!)))
(jolt-trace-enable!))))
;; Exposed so the REPL / nREPL entrypoints (jolt.main, jolt.nrepl) can turn tracing ;; Exposed so the REPL / nREPL entrypoints (jolt.main, jolt.nrepl) can turn tracing
;; on for REPL-driven development without the user setting JOLT_TRACE. Because the ;; on for REPL-driven development without the user setting JOLT_TRACE. Because the
;; push is baked in at compile time, only code compiled after this call is traced — ;; push is baked in at compile time, only code compiled after this call is traced —
;; which is exactly the code you eval / reload in a live session. ;; which is exactly the code you eval / reload in a live session.
(def-var! "jolt.host" "enable-trace!" jolt-enable-trace!) (def-var! "jolt.host" "enable-trace!" jolt-enable-trace!)
;; Explicit opt-in for a whole run (JOLT_TRACE=1): enable at load, BEFORE any app ;; Explicit opt-in for a whole run (JOLT_TRACE=1): enable at load, BEFORE any app
;; namespace is compiled, so a plain `-M:run` traces the app's own code too. ;; namespace is compiled, so a plain `-M:run` traces the app's own code too. Only an
;; affirmative value (set, non-empty, not falsey) forces it on here.
(let ((e (getenv "JOLT_TRACE"))) (let ((e (getenv "JOLT_TRACE")))
(when (and e (not (member e '("0" "false" "no" "")))) (jolt-enable-trace!))) (when (and e (fx>? (string-length e) 0) (not (jolt-trace-env-off? e))) (jolt-enable-trace!)))
;; (with-meta sym m) -> sym, else x — an (ns ^:no-doc name …) yields the name with ;; (with-meta sym m) -> sym, else x — an (ns ^:no-doc name …) yields the name with
;; reader metadata as a with-meta form; strip it to read the bare ns symbol. ;; reader metadata as a with-meta form; strip it to read the bare ns symbol.