Skip to content

Commit 53f55da

Browse files
committed
AOT core wip
`cljs.analyzer/cache-file` now searches in the correct location for core analysis cache `cljs.analyzer/requires-analysis?` now returns true if cache is a URL that matches the expect core analysis cache location `cljs.closure/aot-cache-core` no longer sets :cache-analysis true as this will write the cache file to a default filename, instead write out the cache ourselves drop File type hint from `cljs.util/compiled-by-version`, could be URL or File
1 parent 306abad commit 53f55da

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

src/clj/cljs/analyzer.clj

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,7 @@ argument, which the reader will use in any emitted errors."
18931893
(if-let [core-cache
18941894
(and (util/url? src)
18951895
(.endsWith (.getPath ^URL src) (str "cljs" File/separator "core.cljs"))
1896-
(io/resource "aot_cljs/cljs/core.cljs.cache.edn"))]
1896+
(io/resource "cljs/core.cljs.cache.aot.edn"))]
18971897
core-cache
18981898
(let [ns-info (parse-ns src)]
18991899
(io/file (str (util/to-target-file output-dir ns-info "cljs") ".cache.edn"))))))
@@ -1911,9 +1911,17 @@ argument, which the reader will use in any emitted errors."
19111911
([src output-dir]
19121912
(let [cache (cache-file src output-dir)]
19131913
(requires-analysis? src cache output-dir)))
1914-
([src ^File cache output-dir]
1915-
(if (not (.exists cache))
1914+
([src cache output-dir]
1915+
(cond
1916+
(and (util/url? cache)
1917+
(.endsWith (.getPath ^URL cache) "cljs/core.cljs.cache.aot.edn"))
1918+
false
1919+
1920+
(and (util/file? cache)
1921+
(not (.exists ^File cache)))
19161922
true
1923+
1924+
:else
19171925
(let [out-src (util/to-target-file output-dir (parse-ns src))]
19181926
(if (not (.exists out-src))
19191927
true
@@ -1951,11 +1959,12 @@ argument, which the reader will use in any emitted errors."
19511959
(let [path (if (instance? File res)
19521960
(.getPath ^File res)
19531961
(.getPath ^URL res))
1954-
cache (when (and (:cache-analysis opts) output-dir)
1962+
cache (when (or (= f "cljs/core.cljs")
1963+
(and (:cache-analysis opts) output-dir))
19551964
(cache-file res output-dir))]
19561965
(when-not (get-in @env/*compiler* [::analyzed-cljs path])
1957-
(if (or (not (:cache-analysis opts))
1958-
(not output-dir)
1966+
(if (or (not= f "cljs/core.cljs")
1967+
(not cache)
19591968
(requires-analysis? res output-dir))
19601969
(binding [*cljs-ns* 'cljs.user
19611970
*cljs-file* path
@@ -1972,7 +1981,7 @@ argument, which the reader will use in any emitted errors."
19721981
(recur (:name ast) (next forms))
19731982
(recur ns (next forms))))
19741983
ns))]
1975-
(when cache
1984+
(when (and cache (true? (:cache-analysis opts)))
19761985
(write-analysis-cache ns cache))
19771986
(swap! env/*compiler* assoc-in [::analyzed-cljs path] true)))
19781987
;; we want want to keep dependency analysis information

src/clj/cljs/closure.clj

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,16 +1553,23 @@ should contain the source for the given namespace name."
15531553
(str goog-ns))))))
15541554

15551555
(defn aot-cache-core []
1556-
(let [src (io/file "src" "cljs" "cljs" "core.cljs")
1557-
dest (io/file "src" "aot_cljs" "cljs" "core.js")]
1556+
(let [base-path (io/file "src" "cljs" "cljs")
1557+
src (io/file base-path "core.cljs")
1558+
dest (io/file base-path "core.aot.js")
1559+
cache (io/file base-path "core.cljs.cache.aot.edn")]
15581560
(util/mkdirs dest)
15591561
(env/with-compiler-env (env/default-compiler-env)
15601562
(comp/compile-file src dest
15611563
{:source-map true
1562-
:cache-analysis true
1563-
:output-dir (str "src" File/separator "aot_cljs")}))))
1564+
:output-dir (str "src" File/separator "cljs")})
1565+
(ana/write-analysis-cache 'cljs.core cache))))
15641566

15651567
(comment
1568+
(time
1569+
(do (aot-cache-core) nil))
1570+
1571+
(time
1572+
(do (ana/analyze-file "cljs/core.cljs") nil))
15661573

15671574
(println (build '[(ns hello.core)
15681575
(defn ^{:export greet} greet [n] (str "Hola " n))

src/clj/cljs/util.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"-SNAPSHOT"))
3434
"0.0-0000"))
3535

36-
(defn ^String compiled-by-version [^File f]
36+
(defn ^String compiled-by-version [f]
3737
(with-open [reader (io/reader f)]
3838
(let [match (->> reader line-seq first
3939
(re-matches #".*ClojureScript (\d+\.\d+-\d+).*$"))]

0 commit comments

Comments
 (0)