Skip to content

Commit a5e6f90

Browse files
committed
remove most dynamic call sites
1 parent 401c2a9 commit a5e6f90

File tree

12 files changed

+79
-72
lines changed

12 files changed

+79
-72
lines changed

Clojure/Clojure.Source/clojure/clr/io.clj

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
clojure.clr.io
1414
(:import
1515
(System.IO
16-
Stream BufferedStream
16+
Stream
1717
FileInfo FileStream MemoryStream
1818
FileMode FileShare FileAccess FileOptions
1919
BinaryReader BinaryWriter
@@ -39,16 +39,16 @@
3939
(as-uri [_] nil)
4040

4141
String
42-
(as-file [s] (FileInfo. s))
43-
(as-uri [s] (Uri. s))
42+
(as-file [^String s] (FileInfo. s))
43+
(as-uri [^String s] (Uri. s))
4444

4545
FileInfo
46-
(as-file [f] f)
47-
(as-uri [f] (Uri. (str "file://" (.FullName f))))
46+
(as-file [^FileInfo f] f)
47+
(as-uri [^FileInfo f] (Uri. (str "file://" (.FullName f))))
4848

4949
Uri
50-
(as-uri [u] u)
51-
(as-file [u]
50+
(as-uri [^Uri u] u)
51+
(as-file [^Uri u]
5252
(if (.IsFile u)
5353
(as-file (.LocalPath u))
5454
(throw (ArgumentException. (str "Not a file: " u))))))
@@ -294,7 +294,7 @@
294294
(file-mode :read opts)
295295
(file-access :read opts)
296296
(file-share opts)
297-
(buffer-size opts)
297+
^int (buffer-size opts)
298298
(file-options opts))
299299
opts))
300300
:make-output-stream (fn [^FileInfo x opts]
@@ -303,7 +303,7 @@
303303
(file-mode :write opts)
304304
(file-access :write opts)
305305
(file-share opts)
306-
(buffer-size opts)
306+
^int (buffer-size opts)
307307
(file-options opts))
308308
opts))))
309309

Clojure/Clojure.Source/clojure/core.clj

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@
346346
"Throws a ClassCastException if x is not a c, else returns x."
347347
{:added "1.0"
348348
:static true}
349-
[^Type c x] ;;; changed Class to Type
349+
[^Type c ^Object x] ;;; changed Class to Type
350350
(if (clojure.lang.Util/identical x nil) nil (if (. c (IsInstanceOfType x)) x (throw (InvalidCastException. (.ToString (.GetType x))))))) ;;; original (. c (cast x)))
351351

352352
(defn vector
@@ -826,9 +826,9 @@
826826
compares numbers and collections in a type-independent manner. x
827827
must implement Comparable"
828828
{
829-
:inline (fn [x y] `(. clojure.lang.Util compare ~x ~y))
829+
:inline (fn [^Object x ^Object y] `(clojure.lang.Util/compare ~x ~y))
830830
:added "1.0"}
831-
[x y] (. clojure.lang.Util (compare x y)))
831+
[^Object x ^Object y] (clojure.lang.Util/compare x y))
832832

833833
(defmacro and
834834
"Evaluates exprs one at a time, from left to right. If a form
@@ -1766,7 +1766,7 @@
17661766
(defmacro defmethod
17671767
"Creates and installs a new method of multimethod associated with dispatch-value. "
17681768
{:added "1.0"}
1769-
[multifn dispatch-val & fn-tail]
1769+
[^clojure.lang.MultiFn multifn dispatch-val & fn-tail]
17701770
`(. ~(with-meta multifn {:tag 'clojure.lang.MultiFn}) addMethod ~dispatch-val (fn ~@fn-tail)))
17711771

17721772
(defn remove-all-methods
@@ -1780,15 +1780,15 @@
17801780
"Removes the method of multimethod associated with dispatch-value."
17811781
{:added "1.0"
17821782
:static true}
1783-
[multifn dispatch-val]
1783+
[^clojure.lang.MultiFn multifn dispatch-val]
17841784
(. multifn removeMethod dispatch-val))
17851785

17861786
(defn prefer-method
17871787
"Causes the multimethod to prefer matches of dispatch-val-x over dispatch-val-y
17881788
when there is a conflict"
17891789
{:added "1.0"
17901790
:static true}
1791-
[multifn dispatch-val-x dispatch-val-y]
1791+
[^clojure.lang.MultiFn multifn dispatch-val-x dispatch-val-y]
17921792
(. multifn preferMethod dispatch-val-x dispatch-val-y))
17931793

17941794
(defn methods
@@ -2438,7 +2438,7 @@
24382438
{:added "1.1"
24392439
:static true}
24402440
([^clojure.lang.Ref ref]
2441-
(.getMinHistory ref))
2441+
(.MinHistory ref))
24422442
([^clojure.lang.Ref ref n]
24432443
(.setMinHistory ref n)))
24442444

@@ -2447,7 +2447,7 @@
24472447
{:added "1.1"
24482448
:static true}
24492449
([^clojure.lang.Ref ref]
2450-
(.getMaxHistory ref))
2450+
(.MaxHistory ref))
24512451
([^clojure.lang.Ref ref n]
24522452
(.setMaxHistory ref n)))
24532453

@@ -3598,10 +3598,10 @@
35983598
(instance? clojure.lang.BigInt x) x
35993599
(instance? BigInteger x) (clojure.lang.BigInt/fromBigInteger x)
36003600
(decimal? x) (bigint (.ToBigInteger ^BigDecimal x))
3601-
(float? x) (bigint (BigDecimal/Create (double x))) ;;; (. BigDecimal valueOf (double x))
3601+
(float? x) (bigint (clojure.lang.BigDecimal/Create (double x))) ;;; (. BigDecimal valueOf (double x))
36023602
(ratio? x) (bigint (.BigIntegerValue ^clojure.lang.Ratio x))
3603-
(number? x) (clojure.lang.BigInt/valueOf (long x)) (string? x) (bigint (BigInteger/Parse ^String x)) ;; DM: Added string clause
3604-
:else (bigint (BigInteger. x))))
3603+
(number? x) (clojure.lang.BigInt/valueOf (long x)) (string? x) (bigint (clojure.lang.BigInteger/Parse ^String x)) ;; DM: Added string clause
3604+
:else (bigint (clojure.lang.BigInteger. x))))
36053605

36063606
(defn biginteger
36073607
"Coerce to BigInteger"
@@ -3612,10 +3612,11 @@
36123612
(instance? BigInteger x) x
36133613
(instance? clojure.lang.BigInt x) (.toBigInteger ^clojure.lang.BigInt x)
36143614
(decimal? x) (.ToBigInteger ^BigDecimal x) ;;; toBigInteger
3615-
(float? x) (.ToBigInteger (BigDecimal/Create (double x))) ;;; (.toBigInteger (. BigDecimal valueOf (double x)))
3615+
(float? x) (.ToBigInteger (clojure.lang.BigDecimal/Create (double x))) ;;; (.toBigInteger (. BigDecimal valueOf (double x)))
36163616
(ratio? x) (.BigIntegerValue ^clojure.lang.Ratio x)
3617-
(number? x) (BigInteger/Create (long x)) (string? x) (bigint (BigInteger/Parse ^String x)) ;;;(BigInteger/valueOf (long x)) DM: Added string clause
3618-
:else (BigInteger. x)))
3617+
(number? x) (clojure.lang.BigInteger/Create (long x))
3618+
(string? x) (bigint (clojure.lang.BigInteger/Parse ^String x)) ;;;(BigInteger/valueOf (long x)) DM: Added string clause
3619+
:else (clojure.lang.BigInteger. x)))
36193620

36203621
(defn bigdec
36213622
"Coerce to BigDecimal"
@@ -3624,12 +3625,13 @@
36243625
:static true}
36253626
[x] (cond
36263627
(decimal? x) x
3627-
(float? x) (BigDecimal/Create (double x)) ;;; (. BigDecimal valueOf (double x))
3628-
(ratio? x) (/ (BigDecimal/Create (.numerator ^clojure.lang.Ratio x)) (.denominator ^clojure.lang.Ratio x)) ;;; (/ (BigDecimal. (.numerator ^clojure.lang.Ratio x)) (.denominator ^clojure.lang.Ratio x))
3628+
(float? x) (clojure.lang.BigDecimal/Create (double x)) ;;; (. BigDecimal valueOf (double x))
3629+
(ratio? x) (/ (clojure.lang.BigDecimal/Create (.numerator ^clojure.lang.Ratio x)) (.denominator ^clojure.lang.Ratio x)) ;;; (/ (BigDecimal. (.numerator ^clojure.lang.Ratio x)) (.denominator ^clojure.lang.Ratio x))
36293630
(instance? clojure.lang.BigInt x) (.ToBigDecimal ^clojure.lang.BigInt x) ;;; .ToBigDecimal
3630-
(instance? BigInteger x) (BigDecimal/Create ^BigInteger x) ;;; (BigDecimal. ^BigInteger x)
3631-
(number? x) (BigDecimal/Create (long x)) ;;; (BigDecimal/valueOf (long x))
3632-
:else (BigDecimal/Create x))) ;;; (BigDecimal. x)))
3631+
(instance? BigInteger x) (clojure.lang.BigDecimal/Create ^BigInteger x) ;;; (BigDecimal. ^BigInteger x)
3632+
(number? x) (clojure.lang.BigDecimal/Create (long x)) ;;; (BigDecimal/valueOf (long x))
3633+
:else (throw (InvalidCastException. (str "Cannot cast " (type x) " to BigDecimal.")))
3634+
)) ;;; (BigDecimal. x)))
36333635

36343636
(def ^:dynamic ^{:private true} print-initialized false)
36353637

@@ -3857,25 +3859,25 @@ Note that read can execute code (controlled by *read-eval*),
38573859
(defn aget
38583860
"Returns the value at the index/indices. Works on Java arrays of all
38593861
types."
3860-
{:inline (fn [a i] `(. clojure.lang.RT (aget ~a (int ~i))))
3862+
{:inline (fn [^Array a i] `(. clojure.lang.RT (aget ~a (int ~i))))
38613863
:inline-arities #{2}
38623864
:added "1.0"}
3863-
([array idx]
3864-
(clojure.lang.Reflector/prepRet (.GetElementType (class array)) (. array (GetValue idx)))) ;;; was .getComponentType (. Array (get array idx)))
3865-
([array idx & idxs]
3866-
(apply aget (aget array idx) idxs)))
3865+
([^Array array idx]
3866+
(clojure.lang.Reflector/prepRet (.GetElementType (class array)) (. array (GetValue (int idx))))) ;;; was .getComponentType (. Array (get array idx)))
3867+
([^Array array idx & idxs]
3868+
(apply aget (aget array (int idx)) idxs)))
38673869

38683870
(defn aset
38693871
"Sets the value at the index/indices. Works on Java arrays of
38703872
reference types. Returns val."
38713873
{:inline (fn [a i v] `(. clojure.lang.RT (aset ~a (int ~i) ~v)))
38723874
:inline-arities #{3}
38733875
:added "1.0"}
3874-
([array idx val]
3875-
(. array (SetValue val idx)) ;;; was (. Array (set array idx val))
3876+
([^Array array idx ^Object val]
3877+
(. array (SetValue val (int idx))) ;;; was (. Array (set array idx val))
38763878
val)
3877-
([array idx idx2 & idxv]
3878-
(apply aset (aget array idx) idx2 idxv)))
3879+
([^Array array idx idx2 & idxv]
3880+
(apply aset (aget array (int idx)) idx2 idxv)))
38793881

38803882
(defmacro
38813883
^{:private true}
@@ -3885,8 +3887,8 @@ Note that read can execute code (controlled by *read-eval*),
38853887
([array# idx# val#]
38863888
(. clojure.lang.ArrayHelper (~method array# idx# (~coerce val#))) ;;; Array -> ArrayHelper so we can provide the overloads below.
38873889
val#)
3888-
([array# idx# idx2# & idxv#]
3889-
(apply ~name (aget array# idx#) idx2# idxv#))))
3890+
([^Array array# idx# idx2# & idxv#]
3891+
(apply ~name (aget array# (int idx#)) idx2# idxv#))))
38903892

38913893
(def-aset
38923894
^{:doc "Sets the value at the index/indices. Works on arrays of int. Returns val."
@@ -3937,12 +3939,12 @@ Note that read can execute code (controlled by *read-eval*),
39373939
{:added "1.0"
39383940
:static true}
39393941
([^Type type len] ;;; ^Class
3940-
(. Array (CreateInstance type (int len)))) ;;; newInstance
3942+
(Array/CreateInstance type (int len))) ;;; newInstance
39413943
([^Type type dim & more-dims] ;;; ^Class
3942-
(let [ a (. Array (CreateInstance Array (int dim)))] ;;; [dims (cons dim more-dims)
3944+
(let [^Array a (System.Array/CreateInstance (.MakeArrayType type) (int dim))] ;;; [dims (cons dim more-dims)
39433945
;;; ^"[I" dimarray (make-array (. Integer TYPE) (count dims))]
39443946
(dotimes [i dim] ;;; (dotimes [i (alength dimarray)]
3945-
(aset a i (apply make-array type more-dims))) ;;; (aset-int dimarray i (nth dims i)))
3947+
(aset a (int i) (apply make-array type more-dims))) ;;; (aset-int dimarray i (nth dims i)))
39463948
a))) ;;; (. Array (newInstance type dimarray)))))
39473949

39483950
(defn to-array-2d
@@ -3953,10 +3955,10 @@ Note that read can execute code (controlled by *read-eval*),
39533955
:added "1.0"
39543956
:static true}
39553957
[^System.Collections.ICollection coll] ;;; ^java.util.Collection
3956-
(let [ret (make-array Object (.Count coll))] ;;; NEED BETTER TYPING HERE (make-array (. Class (forName "[Ljava.lang.Object;")) (. coll (size)))]
3958+
(let [^Array ret (make-array Object (.Count coll))] ;;; NEED BETTER TYPING HERE (make-array (. Class (forName "[Ljava.lang.Object;")) (. coll (size)))]
39573959
(loop [i 0 xs (seq coll)]
39583960
(when xs
3959-
(aset ret i (to-array (first xs)))
3961+
(aset ret (int i) (to-array (first xs)))
39603962
(recur (inc i) (next xs))))
39613963
ret))
39623964

@@ -4138,8 +4140,8 @@ Note that read can execute code (controlled by *read-eval*),
41384140
[ns]
41394141
(let [ns (the-ns ns)]
41404142
(filter-key val (fn [ v] (and (instance? clojure.lang.Var v) ;;; removed the tag on v: ^clojure.lang.Var
4141-
(= ns (.ns v))
4142-
(.isPublic v)))
4143+
(= ns (.ns ^clojure.lang.Var v))
4144+
(.isPublic ^clojure.lang.Var v)))
41434145
(ns-map ns))))
41444146

41454147
(defn ns-imports
@@ -4693,9 +4695,9 @@ Note that read can execute code (controlled by *read-eval*),
46934695
"Create an instance of ExceptionInfo, a RuntimeException subclass
46944696
that carries a map of additional data."
46954697
{:added "1.4"}
4696-
([msg map]
4698+
([^String msg ^clojure.lang.IPersistentMap map]
46974699
(ExceptionInfo. msg map))
4698-
([msg map cause]
4700+
([^String msg ^clojure.lang.IPersistentMap map ^Exception cause]
46994701
(ExceptionInfo. msg map cause)))
47004702

47014703
(defn ex-data
@@ -4975,7 +4977,7 @@ Note that read can execute code (controlled by *read-eval*),
49754977
{:private true}
49764978
[^clojure.lang.Sorted sc test key]
49774979
(fn [e]
4978-
(test (.. sc comparator (compare (. sc entryKey e) key)) 0)))
4980+
(test (.. sc comparator (Compare (. sc entryKey e) key)) 0)))
49794981

49804982
(defn subseq
49814983
"sc must be a sorted collection, test(s) one of <, <=, > or
@@ -7651,4 +7653,4 @@ clojure.lang.IKVReduce
76517653
(load-data-readers)
76527654
(catch Exception t ;;; Throwable
76537655
(System.Console/WriteLine (.StackTrace t)) ;;; .printStackTrace
7654-
(throw t)))
7656+
(throw t)))

Clojure/Clojure.Source/clojure/core_deftype.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@
640640

641641
(defn- assert-same-protocol [protocol-var method-syms]
642642
(doseq [m method-syms]
643-
(let [v (resolve m)
644-
p (:protocol (meta v))]
643+
(let [^clojure.lang.Var v (resolve m)
644+
^clojure.lang.Var p (:protocol (meta v))]
645645
(when (and v (bound? v) (not= protocol-var p))
646646
(binding [*out* *err*]
647647
(println "Warning: protocol" protocol-var "is overwriting"
@@ -899,4 +899,4 @@
899899
{:added "1.2"}
900900

901901
[p & specs]
902-
(emit-extend-protocol p specs))
902+
(emit-extend-protocol p specs))

Clojure/Clojure.Source/clojure/data.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@
7878

7979
(extend Object
8080
Diff
81-
{:diff-similar (fn [a b] ((if (.. a GetType IsArray) diff-sequential atom-diff) a b))} ;;; (.. a getClass isArray)
81+
{:diff-similar (fn [^Object a ^Object b] ((if (.. a GetType IsArray) diff-sequential atom-diff) a b))} ;;; (.. a getClass isArray)
8282
EqualityPartition
83-
{:equality-partition (fn [x] (if (.. x GetType IsArray) :sequential :atom))}) ;;; (.. x getClass isArray)
83+
{:equality-partition (fn [^Object x] (if (.. x GetType IsArray) :sequential :atom))}) ;;; (.. x getClass isArray)
8484

8585
(extend-protocol EqualityPartition
8686
nil

Clojure/Clojure.Source/clojure/genclass.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414

1515
(in-ns 'clojure.core)
1616

17-
(import '(System.Reflection ConstructorInfo))
17+
(import '(System.Reflection ConstructorInfo ParameterInfo))
1818

1919
;;; The options-handling code here is taken from the JVM version.
2020

2121

2222
(defn- ctor-sigs [^Type super]
2323
(for [^ConstructorInfo ctor (.GetConstructors super)
2424
:when (not (.IsPrivate ctor))]
25-
(apply vector (map #(.ParameterType %) (.GetParameters ctor)))))
25+
(apply vector (map #(.ParameterType ^ParameterInfo %) (.GetParameters ctor)))))
2626

2727

2828
(def ^{:private true} prim->class
@@ -295,4 +295,4 @@
295295

296296
[& options]
297297
(let [options-map (into1 {} (map vec (partition 2 options))) ]
298-
`'~(generate-interface options-map)))
298+
`'~(generate-interface options-map)))

Clojure/Clojure.Source/clojure/instant.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ with invalid arguments."
262262
(defn- construct-datetimeoffset
263263
"Construct a System.DateTimeOffset, preserving the timezone offset
264264
but truncating the subsecond fraction to milliseconds."
265-
^DateTimeOffset
265+
^System.DateTimeOffset
266266
[years months days hours minutes seconds nanoseconds
267267
offset-sign offset-hours offset-minutes]
268268
(DateTimeOffset. years months days hours minutes seconds

Clojure/Clojure.Source/clojure/main.clj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
(defn get-stack-trace
5252
"Gets the stack trace for an Exception"
53+
^System.Array
5354
[^Exception e]
5455
(.GetFrames (System.Diagnostics.StackTrace. e true)))
5556

@@ -117,7 +118,7 @@
117118
must either be an instance of LineNumberingPushbackReader or duplicate
118119
its behavior of both supporting .unread and collapsing all of CR, LF, and
119120
CRLF to a single \\newline."
120-
[s]
121+
[^clojure.lang.PushbackTextReader s]
121122
(let [c (.Read s)] ;;; .read
122123
(cond
123124
(= c (int \newline)) :line-start
@@ -133,7 +134,7 @@
133134
instance of LineNumberingPushbackReader or duplicate its behavior of both
134135
supporting .unread and collapsing all of CR, LF, and CRLF to a single
135136
\\newline."
136-
[s]
137+
[^clojure.lang.PushbackTextReader s]
137138
(loop [c (.Read s)] ;;; .read
138139
(cond
139140
(= c (int \newline)) :line-start
@@ -162,6 +163,7 @@
162163

163164
(defn repl-exception
164165
"Returns the root cause of throwables"
166+
^System.Exception
165167
[throwable]
166168
(root-cause throwable))
167169

Clojure/Clojure.Source/clojure/reflect/clr.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@
131131
(typesym t))))
132132

133133
(defrecord Constructor
134-
[name declaring-class parameter-types flags])
134+
[^clojure.lang.Symbol name
135+
^clojure.lang.Symbol declaring-class
136+
^clojure.lang.IPersistentVector parameter-types
137+
^clojure.lang.IPersistentSet flags])
135138

136139
(defn- constructor->map
137140
[^System.Reflection.ConstructorInfo constructor]

Clojure/Clojure.Source/clojure/repl.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Example: (source-fn 'filter)"
146146
(with-open [ ^System.IO.TextReader rdr (.OpenText info)] ;;; [rdr (LineNumberReader. (InputStreamReader. strm))]
147147
(dotimes [_ (dec (:line (meta v)))] (.ReadLine rdr)) ;;; .readLine
148148
(let [text (StringBuilder.)
149-
pbr (proxy [clojure.lang.PushbackTextReader] [rdr] ;;; [PushbackReader] [rdr]
149+
pbr (proxy [clojure.lang.PushbackTextReader] [^System.IO.TextReader rdr] ;;; [PushbackReader] [rdr]
150150
(Read [] (let [i (proxy-super Read)] ;;; read read
151151
(.Append text (char i)) ;;; .append
152152
i)))

0 commit comments

Comments
 (0)