Fix direct-link crash on a non-fn var called as a function
Under --direct-link a top-level def binds jv$<fqn> and app->app calls bound directly
to it. emit-invoke raw-applied that binding for any var callee, but only a fn-valued
def is a Scheme procedure: (def cfg {...}) then (cfg :a) emitted (jv$cfg :a), applying
a pmap -> "attempt to apply non-procedure". Maps/sets/keywords are invokable in Clojure
via jolt-invoke, which the indirect path used, so this only bit closed-world builds.
Track which direct-linked vars hold fn literals (direct-link-fns, registered at the def
site when the init op is :fn) and only raw-apply those. A non-fn callee falls through to
the jolt-invoke branch, which still uses the direct jv$ binding as the invoke target —
so the var-deref is still skipped, just not the dispatch.
Seed source: re-minted. Regression in directlink-test.ss (jolt-cw1o).
This commit is contained in:
parent
9a21325972
commit
4461179804
3 changed files with 134 additions and 104 deletions
|
|
@ -44,6 +44,8 @@
|
|||
(jolt-compile-eval "(def hof (fn* ([] a)))" "app")
|
||||
(jolt-compile-eval "(def ^:dynamic d 5)" "app")
|
||||
(jolt-compile-eval "(def usesd (fn* ([] (d))))" "app")
|
||||
(jolt-compile-eval "(def cfg {:a 1 :b 2})" "app")
|
||||
(jolt-compile-eval "(def usecfg (fn* ([] (cfg :a))))" "app")
|
||||
|
||||
;; --- direct-link OFF: every reference stays indirect (var-deref) ---
|
||||
(let ((eb (emit-form "app" "(def b (fn* ([] (a))))")))
|
||||
|
|
@ -72,6 +74,16 @@
|
|||
(ok "on: a used as a value references the binding directly" (contains? eh " jv$app$a)"))
|
||||
(ok "on: value-ref to a is NOT var-deref'd" (not (contains? eh "(var-deref \"app\" \"a\")"))))
|
||||
|
||||
;; A map-valued (non-fn) def is invokable in Clojure but is NOT a Scheme procedure;
|
||||
;; a direct-link call to it must route through jolt-invoke, never raw-apply the
|
||||
;; binding (which crashed with "attempt to apply non-procedure" before the fix).
|
||||
(let ((ec (emit-form "app" "(def cfg {:a 1 :b 2})"))) ; registers app/cfg (non-fn) in the set
|
||||
(ok "on: a non-fn def still gets a jv$ binding" (contains? ec "(define jv$app$cfg ")))
|
||||
(let ((eu (emit-form "app" "(def usecfg (fn* ([] (cfg :a))))")))
|
||||
(ok "on: call to a map-valued def routes through jolt-invoke" (contains? eu "(jolt-invoke"))
|
||||
(ok "on: call to a map-valued def still uses the direct binding" (contains? eu "jv$app$cfg"))
|
||||
(ok "on: a map-valued def is NOT raw-applied as a procedure" (not (contains? eu "(jv$app$cfg"))))
|
||||
|
||||
;; ^:dynamic opts out: no jv$ binding, callers stay indirect.
|
||||
(let ((ed (emit-form "app" "(def ^:dynamic d 5)")))
|
||||
(ok "on: ^:dynamic def gets no jv$ binding" (not (contains? ed "(define jv$app$d"))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue