We're updating the issue view to help you get more done. 

Inter-ns s/fdef expansion side effect fails when load cached source

Description

Like CLJS-1989, but for inter-ns s/fdef as opposed to intra-ns. When loading from cache, if an s/fdef specs a function in another namespace, the load can fail. The root cause is that analysis cache writing and reading is scoped by namespace, and one failure mode is as follows: When analysis cache is written for a given namespace A, specs set up by a different namespace B may not have yet been loaded. When that namespace B is subsequently loaded, if any cache is written for B, it will, due to the scoping, only write out information relevant to B.

To repro, the setup is similar to that in CLJS-1989, but involves splitting the defn and s/fdef across two namespaces:

Have src/foo/core.cljs with:

1 2 3 (ns foo.core) (defn bar [x])

Have src/baz/core.cljs with:

1 2 3 4 5 (ns baz.core (:require [clojure.spec.alpha :as s] [foo.core])) (s/fdef foo.core/bar :args (s/cat :x number?))

Then:

1 2 3 4 5 6 7 $ java -cp cljs.jar:src clojure.main -m cljs.repl.nashorn To quit, type: :cljs/quit cljs.user=> (require '[clojure.spec.test.alpha :as st] 'baz.core) true cljs.user=> (st/instrument) [foo.core/bar] cljs.user=> :cljs/quit

Now this has been cached. If you exit and try again, (st/instrument) fails:

1 2 3 4 5 6 $ java -cp cljs.jar:src clojure.main -m cljs.repl.nashorn To quit, type: :cljs/quit cljs.user=> (require '[clojure.spec.test.alpha :as st] 'baz.core) true cljs.user=> (st/instrument) []

Note, the above was reproduced using ClojureScript 1.9.655 as well, where CLJS-1989 landed, to be sure that this wasn't a subsequent regression.

As an aside, the motivating example where this inter-ns pattern arises is porting of clojure.core.specs.alpha to cljs.core.specs.alpha (CLJS-2413) where in each case, the specs are in a separate *...specs namespace.

Environment

None

Status

Assignee

David Nolen

Reporter

Mike Fikes

Labels

Approval

None

Patch

None

Affects versions

1.9.908
1.9.655

Priority

Critical