Fix -m arg drop under whole-program cache (jolt-4mui) + RFC 0003 sync (#138)

* Bind *command-line-args* after the deps-image cache swap (jolt-4mui)

Under whole-program (deps-image cache active), `jolt -m NS ARG` dropped ARG:
run-main set *command-line-args* on the current ctx, but a cache HIT then
replaced ctx with the saved image (via `set ctx cached`), whose *command-line-
args* was whatever got baked when the image was saved. The stale binding won at
`(apply NS/-main *command-line-args*)`, so -main ran with the wrong (usually
default) args — silently, for any optimized -m program.

Move set-command-line-args to AFTER the cache swap so it binds on the final ctx.
Repro/regression in deps-cache-args-test.janet: first run builds the image
(arg "first"), second run (cache hit) must echo "second", not the baked "first".

* docs: RFC 0003 — phm is a HAMT, sorted colls a red-black tree

The transients RFC described phm as "bucket-based copy-on-write" and mused about
"if it ever becomes a HAMT" — it is one now (jolt-684u), and sorted maps/sets are
a red-black tree (jolt-0hbr). Update the deviation/future-work notes accordingly.

---------

Co-authored-by: Yogthos <yogthos@gmail.com>
This commit is contained in:
Dmitri Sotnikov 2026-06-16 13:34:08 +00:00 committed by GitHub
parent 82525b6a81
commit 307b65b45b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 50 additions and 4 deletions

View file

@ -477,7 +477,6 @@
(defn- run-main [ns-name argv]
(when (nil? ns-name) (eprint "Error: -m/--main requires a namespace") (os/exit 1))
(set-command-line-args argv)
(try
(do
(def path (deps-image-path ns-name))
@ -495,6 +494,10 @@
(when-let [ip (get (ctx :env) :infer-program!)] (protect (ip ctx)))
(put (ctx :env) :infer-program-done? true))
(save-deps-image ctx path)))
# Bind *command-line-args* on the FINAL ctx, AFTER any cache swap: a cache
# hit replaces ctx with the saved image, which carries the args baked when
# it was saved — the current run's argv must win (jolt-4mui).
(set-command-line-args argv)
(load-string ctx (string "(apply " ns-name "/-main *command-line-args*)")))
([err fib] (report-error err fib) (os/exit 1))))