Don't direct-link a var redefined earlier in the same unit (jolt-wf4)
defrecord/deftype expands to (do (def R (make-deftype-ctor ...)) (def ->R R) ...), so the ->R alias references R within one compiled unit. Under direct-link a var ref embeds the cell's root as a compile-time constant, but on a redefine R's old root is still in place when that unit compiles — the (def R new) sibling hasn't run yet — so ->R sealed to the stale pre-redef ctor. (defrecord R [x a]) (defrecord R [a x]) (:a (->R 10 20)) read the old [x a] layout and returned 20. Track the vars a unit (re)defines and force their later in-unit references to the live indirect deref. The cell is registered only after its own init is emitted, so a recursive self-reference inside the init still direct-links (it runs after the def completes); only sibling references after the def go indirect.
This commit is contained in:
parent
747ac87e03
commit
93c86c20f7
2 changed files with 37 additions and 3 deletions
|
|
@ -58,6 +58,19 @@
|
|||
(let [ctx (init {:compile? true :aot-core? false})]
|
||||
(check "aot-core off still correct" (eval-string ctx "(last [1 2 3])") 3))
|
||||
|
||||
# 6. Redefining a record with REORDERED fields must rebind the ctor (jolt-wf4).
|
||||
# deftype expands to (do (def R (make-deftype-ctor ...)) (def ->R R) ...): the
|
||||
# `->R` alias references R in the SAME compiled unit. Direct-link embeds a var's
|
||||
# root as a compile-time constant, but R's redefined root hasn't RUN yet when
|
||||
# that unit compiles — so ->R must NOT seal to R's stale (pre-redef) ctor.
|
||||
(let [ctx (init {:compile? true :direct-linking? true})]
|
||||
(eval-string ctx "(defrecord R [x a])")
|
||||
(eval-string ctx "(defrecord R [a x])")
|
||||
(check "record field-reorder redefine: :a reads the new layout"
|
||||
(eval-string ctx "(:a (->R 10 20))") 10)
|
||||
(check "record field-reorder redefine: :x reads the new layout"
|
||||
(eval-string ctx "(:x (->R 10 20))") 20))
|
||||
|
||||
(if (pos? failures)
|
||||
(do (printf "direct-linking: %d failure(s)" failures) (os/exit 1))
|
||||
(print "direct-linking: all matrix cases passed"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue