Skip to content

Commit 0e85a1a

Browse files
committed
move two more symbols to impl
move the impl ns into the cljs part use self-host perf predicates from cljs.analyzer.impl ns, remove from cljs.analyzer organize cljs.compiler ns form unset JAVA_TOOL_OPTIONS before running CLI tests add cljs.analyzer.impl ns, move pre-allocated symbols used for perf there, add self-host perf predicates too, not used yet organize the analyzer ns form
1 parent a15247a commit 0e85a1a

File tree

4 files changed

+148
-135
lines changed

4 files changed

+148
-135
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,5 +204,6 @@ jobs:
204204

205205
- name: Run tests
206206
run: |
207+
unset JAVA_TOOL_OPTIONS
207208
clojure -A:cli.test.run | tee test-out.txt
208209
grep -qxF '0 failures, 0 errors.' test-out.txt

src/main/clojure/cljs/analyzer.cljc

Lines changed: 61 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,39 @@
77
; You must not remove this notice, or any other, from this software.
88

99
(ns cljs.analyzer
10-
#?(:clj (:refer-clojure :exclude [macroexpand-1 ensure])
11-
:cljs (:refer-clojure :exclude [macroexpand-1 ns-interns ensure js-reserved]))
12-
#?(:cljs (:require-macros
13-
[cljs.analyzer.macros
14-
:refer [no-warn wrapping-errors with-warning-handlers
15-
disallowing-recur allowing-redef disallowing-ns*]]
10+
#?(:clj (:refer-clojure :exclude [ensure macroexpand-1])
11+
:cljs (:refer-clojure :exclude [ensure js-reserved macroexpand-1 ns-interns]))
12+
#?(:cljs (:require-macros [cljs.analyzer.macros
13+
:refer [allowing-redef disallowing-ns* disallowing-recur
14+
no-warn with-warning-handlers wrapping-errors]]
1615
[cljs.env.macros :refer [ensure]]))
17-
#?(:clj (:require [cljs.util :as util :refer [ns->relpath topo-sort]]
18-
[clojure.java.io :as io]
19-
[clojure.string :as string]
20-
[clojure.set :as set]
16+
#?(:clj (:require [cljs.analyzer.impl :as impl]
2117
[cljs.env :as env :refer [ensure]]
18+
[cljs.externs :as externs]
2219
[cljs.js-deps :as deps]
2320
[cljs.tagged-literals :as tags]
24-
[clojure.tools.reader :as reader]
25-
[clojure.tools.reader.reader-types :as readers]
21+
[cljs.util :as util :refer [ns->relpath topo-sort]]
2622
[clojure.edn :as edn]
27-
[cljs.externs :as externs])
28-
:cljs (:require [goog.string :as gstring]
29-
[clojure.string :as string]
23+
[clojure.java.io :as io]
3024
[clojure.set :as set]
25+
[clojure.string :as string]
26+
[clojure.tools.reader :as reader]
27+
[clojure.tools.reader.reader-types :as readers])
28+
:cljs (:require [cljs.analyzer.impl :as impl]
3129
[cljs.env :as env]
30+
[cljs.reader :as edn]
3231
[cljs.tagged-literals :as tags]
3332
[cljs.tools.reader :as reader]
3433
[cljs.tools.reader.reader-types :as readers]
35-
[cljs.reader :as edn]))
36-
#?(:clj (:import [java.io File Reader PushbackReader]
37-
[java.util.regex Pattern]
38-
[java.net URL]
39-
[java.lang Throwable]
34+
[clojure.set :as set]
35+
[clojure.string :as string]
36+
[goog.string :as gstring]))
37+
#?(:clj (:import [cljs.tagged_literals JSValue]
4038
[clojure.lang Namespace Var LazySeq ArityException]
41-
[cljs.tagged_literals JSValue])))
39+
[java.io File Reader PushbackReader]
40+
[java.lang Throwable]
41+
[java.net URL]
42+
[java.util.regex Pattern])))
4243

4344
#?(:clj (set! *warn-on-reflection* true))
4445

@@ -220,52 +221,6 @@
220221
(when-not (identical? m SENTINEL)
221222
(get m k3)))))))))
222223

223-
#?(:cljs
224-
(def CLJ_NIL_SYM 'clj-nil))
225-
226-
#?(:cljs
227-
(def NUMBER_SYM 'number))
228-
229-
#?(:cljs
230-
(def STRING_SYM 'string))
231-
232-
(def BOOLEAN_SYM 'boolean)
233-
234-
#?(:cljs
235-
(def JS_STAR_SYM 'js*))
236-
237-
#?(:cljs
238-
(def DOT_SYM '.))
239-
240-
#?(:cljs
241-
(def NEW_SYM 'new))
242-
243-
#?(:cljs
244-
(def CLJS_CORE_SYM 'cljs.core))
245-
246-
#?(:cljs
247-
(def CLJS_CORE_MACROS_SYM 'cljs.core$macros))
248-
249-
(def IGNORE_SYM 'ignore)
250-
251-
(def ANY_SYM 'any)
252-
253-
#?(:cljs
254-
(defn ^boolean cljs-seq? [x]
255-
(implements? ISeq x)))
256-
257-
#?(:cljs
258-
(defn ^boolean cljs-map? [x]
259-
(implements? IMap x)))
260-
261-
#?(:cljs
262-
(defn ^boolean cljs-vector? [x]
263-
(implements? IVector x)))
264-
265-
#?(:cljs
266-
(defn ^boolean cljs-set? [x]
267-
(implements? ISet x)))
268-
269224
#?(:cljs
270225
(defn munge-path [ss]
271226
(munge (str ss))))
@@ -950,7 +905,7 @@
950905
"Ensures that a type tag is a set."
951906
[t]
952907
(if #?(:clj (set? t)
953-
:cljs (cljs-set? t))
908+
:cljs (impl/cljs-set? t))
954909
t
955910
#{t}))
956911

@@ -1348,7 +1303,7 @@
13481303
(let [ns (cond
13491304
(some? (get-in namespaces [ns :macros sym])) ns
13501305
(core-name? env sym) #?(:clj 'cljs.core
1351-
:cljs CLJS_CORE_MACROS_SYM))]
1306+
:cljs impl/CLJS_CORE_MACROS_SYM))]
13521307
(when (some? ns)
13531308
#?(:clj (get-in namespaces [ns :macros sym])
13541309
:cljs (get-in namespaces [ns :defs sym])))))))
@@ -1417,10 +1372,6 @@
14171372

14181373
(declare infer-tag)
14191374

1420-
(def NOT_NATIVE '#{clj not-native})
1421-
1422-
(def BOOLEAN_OR_SEQ '#{boolean seq})
1423-
14241375
(defn unwrap-quote [{:keys [op] :as expr}]
14251376
(if #?(:clj (= op :quote)
14261377
:cljs (keyword-identical? op :quote))
@@ -1439,23 +1390,23 @@
14391390
(cond
14401391
(or #?(:clj (= then-tag else-tag)
14411392
:cljs (symbol-identical? then-tag else-tag))
1442-
#?(:clj (= else-tag IGNORE_SYM)
1443-
:cljs (symbol-identical? else-tag IGNORE_SYM))) then-tag
1444-
#?(:clj (= then-tag IGNORE_SYM)
1445-
:cljs (symbol-identical? then-tag IGNORE_SYM)) else-tag
1393+
#?(:clj (= else-tag impl/IGNORE_SYM)
1394+
:cljs (symbol-identical? else-tag impl/IGNORE_SYM))) then-tag
1395+
#?(:clj (= then-tag impl/IGNORE_SYM)
1396+
:cljs (symbol-identical? then-tag impl/IGNORE_SYM)) else-tag
14461397
;; TODO: temporary until we move not-native -> clj - David
1447-
(and (or (some? (get NOT_NATIVE then-tag)) (type? env then-tag))
1448-
(or (some? (get NOT_NATIVE else-tag)) (type? env else-tag)))
1398+
(and (or (some? (get impl/NOT_NATIVE then-tag)) (type? env then-tag))
1399+
(or (some? (get impl/NOT_NATIVE else-tag)) (type? env else-tag)))
14491400
'clj
14501401
:else
1451-
(if (and (some? (get BOOLEAN_OR_SEQ then-tag))
1452-
(some? (get BOOLEAN_OR_SEQ else-tag)))
1402+
(if (and (some? (get impl/BOOLEAN_OR_SEQ then-tag))
1403+
(some? (get impl/BOOLEAN_OR_SEQ else-tag)))
14531404
'seq
14541405
(let [then-tag (if #?(:clj (set? then-tag)
1455-
:cljs (cljs-set? then-tag))
1406+
:cljs (impl/cljs-set? then-tag))
14561407
then-tag #{then-tag})
14571408
else-tag (if #?(:clj (set? else-tag)
1458-
:cljs (cljs-set? else-tag))
1409+
:cljs (impl/cljs-set? else-tag))
14591410
else-tag #{else-tag})]
14601411
(into then-tag else-tag))))))))
14611412

@@ -1469,7 +1420,7 @@
14691420
(:ret-tag info)
14701421
(when (= 'js (:ns info)) 'js))]
14711422
ret-tag
1472-
ANY_SYM)))))
1423+
impl/ANY_SYM)))))
14731424

14741425
(defn infer-tag
14751426
"Given env, an analysis environment, and e, an AST node, return the inferred
@@ -1478,8 +1429,8 @@
14781429
(if-some [tag (get-tag e)]
14791430
tag
14801431
(case (:op e)
1481-
:recur IGNORE_SYM
1482-
:throw IGNORE_SYM
1432+
:recur impl/IGNORE_SYM
1433+
:throw impl/IGNORE_SYM
14831434
:let (infer-tag env (:body e))
14841435
:loop (infer-tag env (:body e))
14851436
:do (infer-tag env (:ret e))
@@ -1488,16 +1439,17 @@
14881439
:invoke (infer-invoke env e)
14891440
:if (infer-if env e)
14901441
:const (case (:form e)
1491-
true BOOLEAN_SYM
1492-
false BOOLEAN_SYM
1493-
ANY_SYM)
1442+
true impl/BOOLEAN_SYM
1443+
false impl/BOOLEAN_SYM
1444+
impl/ANY_SYM)
14941445
:quote (infer-tag env (:expr e))
14951446
(:var :local :js-var :binding)
14961447
(if-some [init (:init e)]
14971448
(infer-tag env init)
14981449
(infer-tag env (:info e)))
1499-
(:host-field :host-call) ANY_SYM
1500-
:js ANY_SYM
1450+
(:host-field :host-call)
1451+
impl/ANY_SYM
1452+
:js impl/ANY_SYM
15011453
nil)))
15021454

15031455
(defmulti parse (fn [op & rest] op))
@@ -1940,7 +1892,7 @@
19401892
tag (cond
19411893
fn-var? (or (:ret-tag init-expr) tag (:inferred-ret-tag init-expr))
19421894
tag tag
1943-
dynamic ANY_SYM
1895+
dynamic impl/ANY_SYM
19441896
:else (:tag init-expr))
19451897
export-as (when-let [export-val (-> sym meta :export)]
19461898
(if (= true export-val) var-name export-val))
@@ -3527,7 +3479,7 @@
35273479
(if (and (symbol? t) (some? (get NUMERIC_SET t)))
35283480
true
35293481
(when #?(:clj (set? t)
3530-
:cljs (cljs-set? t))
3482+
:cljs (impl/cljs-set? t))
35313483
(or (contains? t 'number)
35323484
(contains? t 'long)
35333485
(contains? t 'double)
@@ -3550,7 +3502,7 @@
35503502
:else
35513503
(boolean
35523504
(when #?(:clj (set? t)
3553-
:cljs (cljs-set? t))
3505+
:cljs (impl/cljs-set? t))
35543506
(or (contains? t 'any)
35553507
(contains? t 'js)
35563508
(some array-types t))))))
@@ -3837,7 +3789,7 @@
38373789
nstr (if (some? res) (str res) nstr)]
38383790
(cond
38393791
#?@(:clj [(= "clojure.core" nstr) (find-ns 'cljs.core)]
3840-
:cljs [(identical? "clojure.core" nstr) (find-macros-ns CLJS_CORE_MACROS_SYM)])
3792+
:cljs [(identical? "clojure.core" nstr) (find-macros-ns impl/CLJS_CORE_MACROS_SYM)])
38413793
#?@(:clj [(= "clojure.repl" nstr) (find-ns 'cljs.repl)]
38423794
:cljs [(identical? "clojure.repl" nstr) (find-macros-ns 'cljs.repl)])
38433795
#?@(:clj [(.contains nstr ".") (find-ns (symbol nstr))]
@@ -3868,7 +3820,7 @@
38683820
(.findInternedVar ^clojure.lang.Namespace
38693821
#?(:clj (find-ns nsym) :cljs (find-macros-ns nsym)) sym)
38703822
(.findInternedVar ^clojure.lang.Namespace
3871-
#?(:clj (find-ns 'cljs.core) :cljs (find-macros-ns CLJS_CORE_MACROS_SYM)) sym)))))))
3823+
#?(:clj (find-ns 'cljs.core) :cljs (find-macros-ns impl/CLJS_CORE_MACROS_SYM)) sym)))))))
38723824

38733825
(defn get-expander
38743826
"Given a sym, a symbol identifying a macro, and env, an analysis environment
@@ -3933,11 +3885,11 @@
39333885
(throw (ArityException. (- (.actual e) 2) (.name e)))))
39343886
(catch #?(:clj Throwable :cljs :default) e
39353887
(throw (ex-info nil (error-data env :macroexpansion (var->sym mac-var)) e))))]
3936-
(if #?(:clj (seq? form') :cljs (cljs-seq? form'))
3888+
(if #?(:clj (seq? form') :cljs (impl/cljs-seq? form'))
39373889
(let [sym' (first form')
39383890
sym (first form)]
39393891
(if #?(:clj (= sym' 'js*)
3940-
:cljs (symbol-identical? sym' JS_STAR_SYM))
3892+
:cljs (symbol-identical? sym' impl/JS_STAR_SYM))
39413893
(let [sym (if (some? (namespace sym))
39423894
sym
39433895
(symbol "cljs.core" (str sym)))
@@ -3960,14 +3912,14 @@
39603912
#?(:clj (first opname)
39613913
:cljs (.charAt opname 0)))
39623914
(let [[target & args] (next form)]
3963-
(with-meta (list* #?(:clj '. :cljs DOT_SYM) target (symbol (subs opname 1)) args)
3915+
(with-meta (list* #?(:clj '. :cljs impl/DOT_SYM) target (symbol (subs opname 1)) args)
39643916
(meta form)))
39653917

39663918
(identical? \.
39673919
#?(:clj (last opname)
39683920
:cljs (.charAt opname (dec (. opname -length)))))
39693921
(with-meta
3970-
(list* #?(:clj 'new :cljs NEW_SYM) (symbol (subs opname 0 (dec (count opname)))) (next form))
3922+
(list* #?(:clj 'new :cljs impl/NEW_SYM) (symbol (subs opname 0 (dec (count opname)))) (next form))
39713923
(meta form))
39723924

39733925
:else form))
@@ -4222,20 +4174,20 @@
42224174
(defn analyze-form [env form name opts]
42234175
(cond
42244176
(symbol? form) (analyze-symbol env form)
4225-
(and (cljs-seq? form) (some? (seq form))) (analyze-seq env form name opts)
4177+
(and (impl/cljs-seq? form) (some? (seq form))) (analyze-seq env form name opts)
42264178
(record? form) (analyze-record env form)
4227-
(cljs-map? form) (analyze-map env form)
4228-
(cljs-vector? form) (analyze-vector env form)
4229-
(cljs-set? form) (analyze-set env form)
4179+
(impl/cljs-map? form) (analyze-map env form)
4180+
(impl/cljs-vector? form) (analyze-vector env form)
4181+
(impl/cljs-set? form) (analyze-set env form)
42304182
(keyword? form) (analyze-keyword env form)
42314183
(instance? cljs.tagged-literals/JSValue form) (analyze-js-value env form)
42324184
:else
42334185
(let [tag (cond
4234-
(nil? form) CLJ_NIL_SYM
4235-
(number? form) NUMBER_SYM
4236-
(string? form) STRING_SYM
4237-
(true? form) BOOLEAN_SYM
4238-
(false? form) BOOLEAN_SYM
4186+
(nil? form) impl/CLJ_NIL_SYM
4187+
(number? form) impl/NUMBER_SYM
4188+
(string? form) impl/STRING_SYM
4189+
(true? form) impl/BOOLEAN_SYM
4190+
(false? form) impl/BOOLEAN_SYM
42394191
(= () form) 'cljs.core/IList)]
42404192
(cond-> {:op :const :val form :env env :form form}
42414193
tag (assoc :tag tag))))))
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
; Copyright (c) Rich Hickey. All rights reserved.
2+
; The use and distribution terms for this software are covered by the
3+
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4+
; which can be found in the file epl-v10.html at the root of this distribution.
5+
; By using this software in any fashion, you are agreeing to be bound by
6+
; the terms of this license.
7+
; You must not remove this notice, or any other, from this software.
8+
9+
(ns cljs.analyzer.impl)
10+
11+
(def ANY_SYM 'any)
12+
13+
(def BOOLEAN_OR_SEQ '#{boolean seq})
14+
15+
(def BOOLEAN_SYM 'boolean)
16+
17+
#?(:cljs
18+
(def CLJ_NIL_SYM 'clj-nil))
19+
20+
#?(:cljs
21+
(def CLJS_CORE_MACROS_SYM 'cljs.core$macros))
22+
23+
#?(:cljs
24+
(def CLJS_CORE_SYM 'cljs.core))
25+
26+
#?(:cljs
27+
(def DOT_SYM '.))
28+
29+
(def IGNORE_SYM 'ignore)
30+
31+
#?(:cljs
32+
(def JS_STAR_SYM 'js*))
33+
34+
#?(:cljs
35+
(def NEW_SYM 'new))
36+
37+
(def NOT_NATIVE '#{clj not-native})
38+
39+
#?(:cljs
40+
(def NUMBER_SYM 'number))
41+
42+
#?(:cljs
43+
(def STRING_SYM 'string))
44+
45+
#?(:cljs
46+
(defn ^boolean cljs-map? [x]
47+
(implements? IMap x)))
48+
49+
#?(:cljs
50+
(defn ^boolean cljs-seq? [x]
51+
(implements? ISeq x)))
52+
53+
#?(:cljs
54+
(defn ^boolean cljs-vector? [x]
55+
(implements? IVector x)))
56+
57+
#?(:cljs
58+
(defn ^boolean cljs-set? [x]
59+
(implements? ISet x)))

0 commit comments

Comments
 (0)