flan/test/programs/reload-v5.flan
Joseph Ferano a4c6b996ff def re-runs its initialiser, and defvar is renamed defonce
The trio the author decided on 2026-09-20 is now all built: def is CL's
defparameter — its initialiser runs on every daemon re-run, unguarded, so
an edited initialiser repaints the same storage on C-c C-c plus re-run —
defonce (Clojure's name for CL's defvar, per the author) initialises once
behind the .init~once. flag, and defconst stays the image.

One parse arm reads both forms; the difference is Ast.reinit, carried to
Tast.global's grerun. Emit.startup_plan gives a def no guard flag, and
Check.check_global lifts every def initialiser — zero and literal
included — into global/<n>, so the host's startup reaches it through the
function cell and a re-evaluated def swaps it (Session's def_inits;
Emit.redefinition declares the cell for a non-sibling target). The old
defvar spelling is refused with the rename and both compiling spellings,
and every program, test, doc and editor list is swept — except sand.flan,
the author's live WIP, whose seven defvar lines are flagged in FIX.org
and keep its three dependent tests red on this branch.
2026-09-21 07:12:04 +07:00

30 lines
1.1 KiB
Plaintext

;;;; v5 is v4 with one difference: [extra] is an i32 rather than an i64.
;;;;
;;;; [extra] does not exist in the host — v3 introduced it at run time, so its
;;;; storage was allocated by runtime/flan_dev.c the first time a module asked
;;;; for it, and every later module that mentions the name is handed back that
;;;; same allocation. Handing it back for a differently shaped type is layout
;;;; drift: the new body would read and write at offsets the old allocation was
;;;; never laid out for, and nothing downstream could ever say so. The registry
;;;; compares the size it recorded against the size it is asked for and aborts
;;;; instead — retyping a var needs a restart, and this is the file that says
;;;; the guard is real.
;;;;
;;;; Loaded on top of v3, and never alongside v4: the process it aborts is the
;;;; whole of the test.
(defonce counter i64)
(defonce extra i32)
(defn helper [x i64] i64 (* x 2))
(defn added [] i32
(set extra (+ extra 100))
extra)
(defn bump [] i64
(println "v5")
(set counter (+ counter (i64 (added))))
(helper counter))
(defn outer [] i64 (bump))