Skip to content

Commit 88390da

Browse files
committed
Merge branch 'master' of github.com:clojure/clojurescript
2 parents 7c99d37 + f289ffe commit 88390da

File tree

10 files changed

+127
-78
lines changed

10 files changed

+127
-78
lines changed

src/main/cljs/cljs/spec/alpha.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ value of 'cljs.spec.alpha/*runtime-asserts*', or false if not set. You can
551551
toggle check-asserts? with (check-asserts bool)."
552552
[spec x]
553553
`(if *compile-asserts*
554-
(if *runtime-asserts*
554+
(if @#'*runtime-asserts*
555555
(assert* ~spec ~x)
556556
~x)
557557
~x))

src/main/cljs/cljs/spec/test/alpha.cljc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
(when (and (nil? (:const v))
3939
#?(:cljs (nil? (:macro v))))
4040
(swap! instrumented-vars conj (:name v))
41-
`(let [checked# (instrument-1* '~s (var ~s) ~opts)]
41+
`(let [checked# (#'instrument-1* '~s (var ~s) ~opts)]
4242
(when checked# (set! ~s checked#))
4343
'~(:name v)))))
4444

@@ -47,7 +47,7 @@
4747
(when-let [v (ana-api/resolve &env s)]
4848
(when (@instrumented-vars (:name v))
4949
(swap! instrumented-vars disj (:name v))
50-
`(let [raw# (unstrument-1* ~s (var ~s))]
50+
`(let [raw# (#'unstrument-1* '~s (var ~s))]
5151
(when raw# (set! ~s raw#))
5252
'~(:name v)))))
5353

@@ -165,8 +165,8 @@ Returns a collection of syms naming the vars unstrumented."
165165
:sym s# :spec spec#}
166166

167167
(:args spec#)
168-
(let [tcret# (quick-check f# spec# opts#)]
169-
(make-check-result s# spec# tcret#))
168+
(let [tcret# (#'quick-check f# spec# opts#)]
169+
(#'make-check-result s# spec# tcret#))
170170

171171
:default
172172
{:failure (ex-info "No :args spec" {::s/failure :no-args-spec})
@@ -189,7 +189,7 @@ Returns a collection of syms naming the vars unstrumented."
189189
(checkable-syms* nil))
190190
([opts]
191191
(reduce into #{}
192-
[(filter fn-spec-name? (keys @s/registry-ref))
192+
[(filter fn-spec-name? (keys @@#'s/registry-ref))
193193
(keys (:spec opts))])))
194194

195195
(defmacro checkable-syms
@@ -201,7 +201,7 @@ can be checked."
201201
`(let [opts# ~opts]
202202
(validate-check-opts opts#)
203203
(reduce conj #{}
204-
'[~@(filter fn-spec-name? (keys @s/registry-ref))
204+
'[~@(filter fn-spec-name? (keys @@#'s/registry-ref))
205205
~@(keys (:spec opts))]))))
206206

207207
(defmacro check

src/main/cljs/clojure/core/reducers.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
(-kv-reduce coll f init)
4141
(cond
4242
(nil? coll) init
43-
(array? coll) (array-reduce coll f init)
43+
(array? coll) (#'array-reduce coll f init)
4444
:else (-reduce coll f init)))))
4545

4646
(defprotocol CollFold

src/main/clojure/cljs/analyzer.cljc

Lines changed: 92 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
(def ^:dynamic *macro-infer* true)
6363
(def ^:dynamic *passes* nil)
6464
(def ^:dynamic *file-defs* nil)
65+
(def ^:dynamic *private-var-access-nowarn* false)
6566

6667
(def constants-ns-sym
6768
"The namespace of the constants table as a symbol."
@@ -123,6 +124,7 @@
123124
{:preamble-missing true
124125
:unprovided true
125126
:undeclared-var true
127+
:private-var-access true
126128
:undeclared-ns true
127129
:undeclared-ns-form true
128130
:redef true
@@ -305,6 +307,10 @@
305307
"Use of undeclared Var ")
306308
(:prefix info) "/" (:suffix info)))
307309

310+
(defmethod error-message :private-var-access
311+
[warning-type info]
312+
(str "var: " (:sym info) " is not public"))
313+
308314
(defmethod error-message :undeclared-ns
309315
[warning-type {:keys [ns-sym js-provide] :as info}]
310316
(str "No such namespace: " ns-sym
@@ -969,20 +975,20 @@
969975
(node-module-dep? ns) :node
970976
(dep-has-global-exports? ns) :global))
971977

972-
(defmulti resolve* (fn [sym full-ns current-ns] (ns->module-type full-ns)))
978+
(defmulti resolve* (fn [env sym full-ns current-ns] (ns->module-type full-ns)))
973979

974980
(defmethod resolve* :js
975-
[sym full-ns current-ns]
981+
[env sym full-ns current-ns]
976982
{:name (symbol (str full-ns) (str (name sym)))
977983
:ns full-ns})
978984

979985
(defmethod resolve* :node
980-
[sym full-ns current-ns]
986+
[env sym full-ns current-ns]
981987
{:name (symbol (str current-ns) (str (munge-node-lib full-ns) "." (name sym)))
982988
:ns current-ns})
983989

984990
(defmethod resolve* :global
985-
[sym full-ns current-ns]
991+
[env sym full-ns current-ns]
986992
(let [pre (into '[Object] (->> (string/split (name sym) #"\.") (map symbol) vec))]
987993
(when-not (has-extern? pre)
988994
(swap! env/*compiler* update-in
@@ -991,11 +997,26 @@
991997
:ns current-ns
992998
:tag (with-meta 'js {:prefix pre})}))
993999

1000+
(def ^:private private-var-access-exceptions
1001+
"Specially-treated symbols for which we don't trigger :private-var-access warnings."
1002+
'#{cljs.core/checked-aget
1003+
cljs.core/checked-aset
1004+
cljs.core/checked-aget'
1005+
cljs.core/checked-aset'})
1006+
9941007
(defmethod resolve* :default
995-
[sym full-ns current-ns]
996-
(merge (gets @env/*compiler* ::namespaces full-ns :defs (symbol (name sym)))
997-
{:name (symbol (str full-ns) (str (name sym)))
998-
:ns full-ns}))
1008+
[env sym full-ns current-ns]
1009+
(let [sym-ast (gets @env/*compiler* ::namespaces full-ns :defs (symbol (name sym)))
1010+
sym-name (symbol (str full-ns) (str (name sym)))]
1011+
(when (and (not= current-ns full-ns)
1012+
(:private sym-ast)
1013+
(not *private-var-access-nowarn*)
1014+
(not (contains? private-var-access-exceptions sym-name)))
1015+
(warning :private-var-access env
1016+
{:sym sym-name}))
1017+
(merge sym-ast
1018+
{:name sym-name
1019+
:ns full-ns})))
9991020

10001021
(defn required? [ns env]
10011022
(or (contains? (set (vals (gets env :ns :requires))) ns)
@@ -1070,7 +1091,7 @@
10701091
(when (not= current-ns full-ns)
10711092
(confirm-ns env full-ns))
10721093
(confirm env full-ns (symbol (name sym))))
1073-
(resolve* sym full-ns current-ns))
1094+
(resolve* env sym full-ns current-ns))
10741095

10751096
(dotted-symbol? sym)
10761097
(let [idx (.indexOf s ".")
@@ -1090,13 +1111,13 @@
10901111

10911112
(some? (gets @env/*compiler* ::namespaces current-ns :uses sym))
10921113
(let [full-ns (gets @env/*compiler* ::namespaces current-ns :uses sym)]
1093-
(resolve* sym full-ns current-ns))
1114+
(resolve* env sym full-ns current-ns))
10941115

10951116
(some? (gets @env/*compiler* ::namespaces current-ns :renames sym))
10961117
(let [qualified-symbol (gets @env/*compiler* ::namespaces current-ns :renames sym)
10971118
full-ns (symbol (namespace qualified-symbol))
10981119
sym (symbol (name qualified-symbol))]
1099-
(resolve* sym full-ns current-ns))
1120+
(resolve* env sym full-ns current-ns))
11001121

11011122
(some? (gets @env/*compiler* ::namespaces current-ns :imports sym))
11021123
(recur env (gets @env/*compiler* ::namespaces current-ns :imports sym) confirm)
@@ -1359,13 +1380,14 @@
13591380
[env sym]
13601381
;; we need to dissoc locals for the `(let [x 1] (def x x))` case, because we
13611382
;; want the var's AST and `resolve-var` will check locals first. - António Monteiro
1362-
(let [env (dissoc env :locals)
1363-
var (resolve-var env sym (confirm-var-exists-throw))
1364-
expr-env (assoc env :context :expr)]
1365-
(when-some [var-ns (:ns var)]
1366-
{:var (analyze expr-env sym)
1367-
:sym (analyze expr-env `(quote ~(symbol (name var-ns) (name (:name var)))))
1368-
:meta (var-meta var expr-env)})))
1383+
(binding [*private-var-access-nowarn* true]
1384+
(let [env (dissoc env :locals)
1385+
var (resolve-var env sym (confirm-var-exists-throw))
1386+
expr-env (assoc env :context :expr)]
1387+
(when-some [var-ns (:ns var)]
1388+
{:var (analyze expr-env sym)
1389+
:sym (analyze expr-env `(quote ~(symbol (name var-ns) (name (:name var)))))
1390+
:meta (var-meta var expr-env)}))))
13691391

13701392
(defmethod parse 'var
13711393
[op env [_ sym :as form] _ _]
@@ -1619,7 +1641,7 @@
16191641
(analyze (assoc env :context :expr) (:init args) sym))))
16201642
fn-var? (and (some? init-expr) (= (:op init-expr) :fn))
16211643
tag (if fn-var?
1622-
(or (:ret-tag init-expr) tag)
1644+
(or (:ret-tag init-expr) tag (:inferred-ret-tag init-expr))
16231645
(or tag (:tag init-expr)))
16241646
export-as (when-let [export-val (-> sym meta :export)]
16251647
(if (= true export-val) var-name export-val))
@@ -1860,13 +1882,17 @@
18601882
children (if (some? name-var)
18611883
[:local :methods]
18621884
[:methods])
1885+
inferred-ret-tag (let [inferred-tags (map (partial infer-tag env) (map :body methods))]
1886+
(when (apply = inferred-tags)
1887+
(first inferred-tags)))
18631888
ast (merge {:op :fn
18641889
:env env
18651890
:form form
18661891
:name name-var
18671892
:methods methods
18681893
:variadic? variadic
18691894
:tag 'function
1895+
:inferred-ret-tag inferred-ret-tag
18701896
:recur-frames *recur-frames*
18711897
:loop-lets *loop-lets*
18721898
:jsdoc [js-doc]
@@ -2135,49 +2161,50 @@
21352161
[`(. ~target ~val) alt]
21362162
[target val])]
21372163
(disallowing-recur
2138-
(let [enve (assoc env :context :expr)
2139-
texpr (cond
2140-
(symbol? target)
2141-
(do
2142-
(cond
2143-
(and (= target '*unchecked-if*) ;; TODO: proper resolve
2144-
(or (true? val) (false? val)))
2145-
(set! *unchecked-if* val)
2146-
2147-
(and (= target '*unchecked-arrays*) ;; TODO: proper resolve
2148-
(or (true? val) (false? val)))
2149-
(set! *unchecked-arrays* val)
2150-
2151-
(and (= target '*warn-on-infer*)
2152-
(or (true? val) (false? val)))
2153-
(set! *cljs-warnings* (assoc *cljs-warnings* :infer-warning val)))
2154-
(when (some? (:const (resolve-var (dissoc env :locals) target)))
2155-
(throw (error env "Can't set! a constant")))
2156-
(let [local (-> env :locals target)]
2157-
(when-not (or (nil? local)
2158-
(and (:field local)
2159-
(or (:mutable local)
2160-
(:unsynchronized-mutable local)
2161-
(:volatile-mutable local))))
2162-
(throw (error env "Can't set! local var or non-mutable field"))))
2163-
(analyze-symbol enve target))
2164-
2165-
:else
2166-
(when (seq? target)
2167-
(let [texpr (analyze-seq enve target nil)]
2168-
(when (:field texpr)
2169-
texpr))))
2170-
vexpr (analyze enve val)]
2171-
(when-not texpr
2172-
(throw (error env "set! target must be a field or a symbol naming a var")))
2173-
(cond
2174-
(and (not (:def-emits-var env)) ;; non-REPL context
2175-
(some? ('#{*unchecked-if* *unchecked-array* *warn-on-infer*} target)))
2176-
{:env env :op :no-op}
2177-
2178-
:else
2179-
{:env env :op :set! :form form :target texpr :val vexpr
2180-
:children [:target :val]})))))
2164+
(binding [*private-var-access-nowarn* true]
2165+
(let [enve (assoc env :context :expr)
2166+
texpr (cond
2167+
(symbol? target)
2168+
(do
2169+
(cond
2170+
(and (= target '*unchecked-if*) ;; TODO: proper resolve
2171+
(or (true? val) (false? val)))
2172+
(set! *unchecked-if* val)
2173+
2174+
(and (= target '*unchecked-arrays*) ;; TODO: proper resolve
2175+
(or (true? val) (false? val)))
2176+
(set! *unchecked-arrays* val)
2177+
2178+
(and (= target '*warn-on-infer*)
2179+
(or (true? val) (false? val)))
2180+
(set! *cljs-warnings* (assoc *cljs-warnings* :infer-warning val)))
2181+
(when (some? (:const (resolve-var (dissoc env :locals) target)))
2182+
(throw (error env "Can't set! a constant")))
2183+
(let [local (-> env :locals target)]
2184+
(when-not (or (nil? local)
2185+
(and (:field local)
2186+
(or (:mutable local)
2187+
(:unsynchronized-mutable local)
2188+
(:volatile-mutable local))))
2189+
(throw (error env "Can't set! local var or non-mutable field"))))
2190+
(analyze-symbol enve target))
2191+
2192+
:else
2193+
(when (seq? target)
2194+
(let [texpr (analyze-seq enve target nil)]
2195+
(when (:field texpr)
2196+
texpr))))
2197+
vexpr (analyze enve val)]
2198+
(when-not texpr
2199+
(throw (error env "set! target must be a field or a symbol naming a var")))
2200+
(cond
2201+
(and (not (:def-emits-var env)) ;; non-REPL context
2202+
(some? ('#{*unchecked-if* *unchecked-array* *warn-on-infer*} target)))
2203+
{:env env :op :no-op}
2204+
2205+
:else
2206+
{:env env :op :set! :form form :target texpr :val vexpr
2207+
:children [:target :val]}))))))
21812208

21822209
#?(:clj (declare analyze-file))
21832210

@@ -3770,7 +3797,9 @@
37703797
(if (and (not (namespace sym))
37713798
(dotted-symbol? sym))
37723799
sym
3773-
(:name (resolve-var (assoc @env/*compiler* :ns (get-namespace *cljs-ns*)) sym))))
3800+
(:name (binding [*private-var-access-nowarn* true]
3801+
(resolve-var (assoc @env/*compiler* :ns (get-namespace *cljs-ns*))
3802+
sym)))))
37743803

37753804
#?(:clj
37763805
(defn forms-seq*

src/main/clojure/cljs/analyzer/api.cljc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@
148148
[env sym]
149149
{:pre [(map? env) (symbol? sym)]}
150150
(try
151-
(ana/resolve-var env sym
152-
(ana/confirm-var-exists-throw))
151+
(binding [ana/*private-var-access-nowarn* true]
152+
(ana/resolve-var env sym
153+
(ana/confirm-var-exists-throw)))
153154
(catch #?(:clj Exception :cljs :default) e
154155
(ana/resolve-macro-var env sym))))
155156

src/main/clojure/cljs/compiler.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
ss (map rf (string/split ss #"\."))
137137
ss (string/join "." ss)
138138
ms #?(:clj (clojure.lang.Compiler/munge ss)
139-
:cljs (cljs.core/munge-str ss))]
139+
:cljs (#'cljs.core/munge-str ss))]
140140
(if (symbol? s)
141141
(symbol ms)
142142
ms)))))

src/main/clojure/cljs/core.cljc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,7 @@
18641864

18651865
'IPrintWithWriter
18661866
`(~'-pr-writer [this# writer# opts#]
1867-
(let [pr-pair# (fn [keyval#] (pr-sequential-writer writer# pr-writer "" " " "" opts# keyval#))]
1867+
(let [pr-pair# (fn [keyval#] (pr-sequential-writer writer# @#'pr-writer "" " " "" opts# keyval#))]
18681868
(pr-sequential-writer
18691869
writer# pr-pair# ~pr-open ", " "}" opts#
18701870
(concat [~@(map #(core/list `vector (keyword %) %) base-fields)]
@@ -2689,7 +2689,7 @@
26892689
prefer-table# (atom {})
26902690
method-cache# (atom {})
26912691
cached-hierarchy# (atom {})
2692-
hierarchy# (cljs.core/get ~options :hierarchy (cljs.core/get-global-hierarchy))]
2692+
hierarchy# (cljs.core/get ~options :hierarchy (#'cljs.core/get-global-hierarchy))]
26932693
(cljs.core/MultiFn. (cljs.core/symbol ~mm-ns ~(name mm-name)) ~dispatch-fn ~default hierarchy#
26942694
method-table# prefer-table# method-cache# cached-hierarchy#))))))
26952695

src/main/clojure/cljs/tagged_literals.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
(when-not (string? form)
5757
(throw (js/Error. "Instance literal expects a string for its timestamp.")))
5858
(try
59-
(reader/read-date form)
59+
(#'reader/read-date form)
6060
(catch :default e
6161
(throw (js/Error. (. e -message)))))))
6262

src/test/cljs/cljs/pprint_test.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ Usage: *hello*
761761
(doseq [row aseq]
762762
(doseq [col row]
763763
(cl-format *out* "~4D~7,vT" col column-width))
764-
(prn)))
764+
(#'prn)))
765765
(str sb)
766766
;;TODO do we need to extend StringBufferWriter to allow access to underlying StringBuffer?
767767
#_(str (:base @@(:base @@stream)))))

0 commit comments

Comments
 (0)