flan/test/programs/reload-v5.flan
Joseph Ferano aa0b799bb6 Retyping a global across a reload, which nothing had ever done
flan_dev_global hands back the allocation it made the first time a name
was asked for, and compares the size it recorded against the size it is
asked for. Nothing exercised the comparison: v5 is v4 with extra as an
i32, loaded on top of v3, and what it does is abort the process — so it
gets a host run of its own. The message is asserted alongside the exit
status, because a process that died for some other reason is not this
guard firing and the status alone cannot tell them apart.
2026-09-12 10:51:14 +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.
(defvar counter i64)
(defvar 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))