Skip to content

Commit 00c9aec

Browse files
rauhsswannodette
authored andcommitted
CLJS-2041: Compiler flag to drop Function.prototype.call invokes
Introduce a new compiler option :fn-invoke-direct that, if true, does not generate .call(null...) calls for unknown functions, but instead directly invoke via f(a0,a1...)
1 parent fa041d9 commit 00c9aec

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
(def ^:dynamic *cljs-file* nil)
4646
#?(:clj (def ^:dynamic *unchecked-if* false))
4747
(def ^:dynamic *cljs-static-fns* false)
48+
(def ^:dynamic *fn-invoke-direct* false)
4849
(def ^:dynamic *cljs-macros-path* "/cljs/core")
4950
(def ^:dynamic *cljs-macros-is-classpath* true)
5051
(def ^:dynamic *cljs-dep-set* (with-meta #{} {:dep-path []}))

src/main/clojure/cljs/closure.clj

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@
166166
:pretty-print :print-input-delimiter :pseudo-names :recompile-dependents :source-map
167167
:source-map-inline :source-map-timestamp :static-fns :target :verbose :warnings
168168
:emit-constants :ups-externs :ups-foreign-libs :ups-libs :warning-handlers :preloads
169-
:browser-repl :cache-analysis-format :infer-externs :closure-generate-exports :npm-deps})
169+
:browser-repl :cache-analysis-format :infer-externs :closure-generate-exports :npm-deps
170+
:fn-invoke-direct})
170171

171172
(def string->charset
172173
{"iso-8859-1" StandardCharsets/ISO_8859_1
@@ -2245,6 +2246,10 @@
22452246
;; we want to warn about NPM dep conflicts before installing the modules
22462247
(check-npm-deps opts)
22472248
(let [compiler-stats (:compiler-stats opts)
2249+
static-fns? (or (and (= (:optimizations opts) :advanced)
2250+
(not (false? (:static-fns opts))))
2251+
(:static-fns opts)
2252+
ana/*cljs-static-fns*)
22482253
all-opts (-> opts
22492254
maybe-install-node-deps!
22502255
add-implicit-options
@@ -2266,11 +2271,10 @@
22662271
(assoc :sources (-find-sources source all-opts))))
22672272
(binding [comp/*recompiled* (when-not (false? (:recompile-dependents opts))
22682273
(atom #{}))
2269-
ana/*cljs-static-fns*
2270-
(or (and (= (:optimizations opts) :advanced)
2271-
(not (false? (:static-fns opts))))
2272-
(:static-fns opts)
2273-
ana/*cljs-static-fns*)
2274+
ana/*cljs-static-fns* static-fns?
2275+
ana/*fn-invoke-direct* (or (and static-fns?
2276+
(:fn-invoke-direct opts))
2277+
ana/*fn-invoke-direct*)
22742278
*assert* (not= (:elide-asserts opts) true)
22752279
ana/*load-tests* (not= (:load-tests opts) false)
22762280
ana/*cljs-warnings*

src/main/clojure/cljs/compiler.cljc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,8 +1039,14 @@
10391039
(if (and ana/*cljs-static-fns* (= (:op f) :var))
10401040
;; higher order case, static information missing
10411041
(let [fprop (str ".cljs$core$IFn$_invoke$arity$" (count args))]
1042-
(emits "(" f fprop " ? " f fprop "(" (comma-sep args) ") : " f ".call(" (comma-sep (cons "null" args)) "))"))
1043-
(emits f ".call(" (comma-sep (cons "null" args)) ")"))))))
1042+
(if ana/*fn-invoke-direct*
1043+
(emits "(" f fprop " ? " f fprop "(" (comma-sep args) ") : "
1044+
f "(" (comma-sep args) "))")
1045+
(emits "(" f fprop " ? " f fprop "(" (comma-sep args) ") : "
1046+
f ".call(" (comma-sep (cons "null" args)) "))")))
1047+
(if ana/*fn-invoke-direct*
1048+
(emits f "(" (comma-sep args) ")")
1049+
(emits f ".call(" (comma-sep (cons "null" args)) ")")))))))
10441050

10451051
(defmethod emit* :new
10461052
[{:keys [ctor args env]}]

0 commit comments

Comments
 (0)