Uploaded image for project: 'ClojureScript'
  1. CLJS-2417

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Completed
    • Affects versions: 1.9.908, 1.9.655
    • Fix versions: None
    • Labels:

      Description

      Like CLJS-1989 Closed , 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 Closed , but involves splitting the defn and s/fdef across two namespaces:

      Have src/foo/core.cljs with:

      (ns foo.core)
      
      (defn bar [x])
      

      Have src/baz/core.cljs with:

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

      Then:

      $ 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:

      $ 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 Closed 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 Closed ) where in each case, the specs are in a separate *...specs namespace.

        Attachments

          Activity

            People

            • Assignee:
              dnolen David Nolen
              Reporter:
              mfikes Mike Fikes
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: