@@ -183,16 +183,23 @@ else
183
183
end
184
184
185
185
function Typeof end
186
- (f:: typeof (Typeof))(x:: ANY ) = isa (x,Type) ? Type{x} : typeof (x)
186
+ ccall (:jl_toplevel_eval_in , Any, (Any, Any),
187
+ Core, quote
188
+ (f:: typeof (Typeof))(x) = ($ (_expr (:meta ,:nospecialize ,:x )); isa (x,Type) ? Type{x} : typeof (x))
189
+ end )
190
+
191
+ macro nospecialize (x)
192
+ _expr (:meta , :nospecialize , x)
193
+ end
194
+
195
+ Expr (@nospecialize args... ) = _expr (args... )
187
196
188
197
abstract type Exception end
189
198
mutable struct ErrorException <: Exception
190
199
msg:: AbstractString
191
200
ErrorException (msg:: AbstractString ) = new (msg)
192
201
end
193
202
194
- Expr (args:: ANY... ) = _expr (args... )
195
-
196
203
macro _noinline_meta ()
197
204
Expr (:meta , :noinline )
198
205
end
@@ -201,8 +208,8 @@ struct BoundsError <: Exception
201
208
a:: Any
202
209
i:: Any
203
210
BoundsError () = new ()
204
- BoundsError (a :: ANY ) = (@_noinline_meta ; new (a))
205
- BoundsError (a :: ANY , i) = (@_noinline_meta ; new (a,i))
211
+ BoundsError (@nospecialize (a) ) = (@_noinline_meta ; new (a))
212
+ BoundsError (@nospecialize (a) , i) = (@_noinline_meta ; new (a,i))
206
213
end
207
214
struct DivideError <: Exception end
208
215
struct OverflowError <: Exception end
@@ -218,8 +225,8 @@ struct InterruptException <: Exception end
218
225
struct DomainError <: Exception
219
226
val
220
227
msg
221
- DomainError (val:: ANY ) = (@_noinline_meta ; new (val))
222
- DomainError (val:: ANY , msg:: ANY ) = (@_noinline_meta ; new (val, msg))
228
+ DomainError (@nospecialize ( val) ) = (@_noinline_meta ; new (val))
229
+ DomainError (@nospecialize ( val), @nospecialize ( msg) ) = (@_noinline_meta ; new (val, msg))
223
230
end
224
231
mutable struct TypeError <: Exception
225
232
func:: Symbol
@@ -232,7 +239,7 @@ struct InexactError <: Exception
232
239
T:: Type
233
240
val
234
241
235
- InexactError (f:: Symbol , T :: ANY , val:: ANY ) = (@_noinline_meta ; new (f, T, val))
242
+ InexactError (f:: Symbol , @nospecialize (T), @nospecialize ( val) ) = (@_noinline_meta ; new (f, T, val))
236
243
end
237
244
238
245
abstract type DirectIndexString <: AbstractString end
@@ -244,16 +251,16 @@ getptls() = ccall(:jl_get_ptls_states, Ptr{Void}, ())
244
251
245
252
include (m:: Module , fname:: String ) = ccall (:jl_load_ , Any, (Any, Any), m, fname)
246
253
247
- eval (e :: ANY ) = eval (Main, e)
248
- eval (m:: Module , e :: ANY ) = ccall (:jl_toplevel_eval_in , Any, (Any, Any), m, e)
254
+ eval (@nospecialize (e) ) = eval (Main, e)
255
+ eval (m:: Module , @nospecialize (e) ) = ccall (:jl_toplevel_eval_in , Any, (Any, Any), m, e)
249
256
250
- kwfunc (f :: ANY ) = ccall (:jl_get_keyword_sorter , Any, (Any,), f)
257
+ kwfunc (@nospecialize (f) ) = ccall (:jl_get_keyword_sorter , Any, (Any,), f)
251
258
252
- kwftype (t :: ANY ) = typeof (ccall (:jl_get_kwsorter , Any, (Any,), t))
259
+ kwftype (@nospecialize (t) ) = typeof (ccall (:jl_get_kwsorter , Any, (Any,), t))
253
260
254
261
mutable struct Box
255
262
contents:: Any
256
- Box (x :: ANY ) = new (x)
263
+ Box (@nospecialize (x) ) = new (x)
257
264
Box () = new ()
258
265
end
259
266
@@ -262,18 +269,18 @@ end
262
269
mutable struct WeakRef
263
270
value
264
271
WeakRef () = WeakRef (nothing )
265
- WeakRef (v :: ANY ) = ccall (:jl_gc_new_weakref_th , Ref{WeakRef},
266
- (Ptr{Void}, Any), getptls (), v)
272
+ WeakRef (@nospecialize (v) ) = ccall (:jl_gc_new_weakref_th , Ref{WeakRef},
273
+ (Ptr{Void}, Any), getptls (), v)
267
274
end
268
275
269
276
TypeVar (n:: Symbol ) =
270
277
ccall (:jl_new_typevar , Ref{TypeVar}, (Any, Any, Any), n, Union{}, Any)
271
- TypeVar (n:: Symbol , ub :: ANY ) =
278
+ TypeVar (n:: Symbol , @nospecialize (ub) ) =
272
279
ccall (:jl_new_typevar , Ref{TypeVar}, (Any, Any, Any), n, Union{}, ub)
273
- TypeVar (n:: Symbol , lb :: ANY , ub :: ANY ) =
280
+ TypeVar (n:: Symbol , @nospecialize (lb), @nospecialize (ub) ) =
274
281
ccall (:jl_new_typevar , Ref{TypeVar}, (Any, Any, Any), n, lb, ub)
275
282
276
- UnionAll (v:: TypeVar , t :: ANY ) = ccall (:jl_type_unionall , Any, (Any, Any), v, t)
283
+ UnionAll (v:: TypeVar , @nospecialize (t) ) = ccall (:jl_type_unionall , Any, (Any, Any), v, t)
277
284
278
285
Void () = nothing
279
286
@@ -288,26 +295,26 @@ VecElement(arg::T) where {T} = VecElement{T}(arg)
288
295
# used by lowering of splicing unquote
289
296
splicedexpr (hd:: Symbol , args:: Array{Any,1} ) = (e= Expr (hd); e. args= args; e)
290
297
291
- _new (typ:: Symbol , argty:: Symbol ) = eval (:((:: Type{$typ} )(n:: $argty ) = $ (Expr (:new , typ, :n ))))
298
+ _new (typ:: Symbol , argty:: Symbol ) = eval (Core, :((:: Type{$typ} )(@nospecialize n:: $argty ) = $ (Expr (:new , typ, :n ))))
292
299
_new (:LabelNode , :Int )
293
300
_new (:GotoNode , :Int )
294
301
_new (:NewvarNode , :SlotNumber )
295
- _new (:QuoteNode , :ANY )
302
+ _new (:QuoteNode , :Any )
296
303
_new (:SSAValue , :Int )
297
- eval (:((:: Type{LineNumberNode} )(l:: Int ) = $ (Expr (:new , :LineNumberNode , :l , nothing ))))
298
- eval (:((:: Type{LineNumberNode} )(l:: Int , f :: ANY ) = $ (Expr (:new , :LineNumberNode , :l , :f ))))
299
- eval (:((:: Type{GlobalRef} )(m:: Module , s:: Symbol ) = $ (Expr (:new , :GlobalRef , :m , :s ))))
300
- eval (:((:: Type{SlotNumber} )(n:: Int ) = $ (Expr (:new , :SlotNumber , :n ))))
301
- eval (:((:: Type{TypedSlot} )(n:: Int , t :: ANY ) = $ (Expr (:new , :TypedSlot , :n , :t ))))
304
+ eval (Core, :((:: Type{LineNumberNode} )(l:: Int ) = $ (Expr (:new , :LineNumberNode , :l , nothing ))))
305
+ eval (Core, :((:: Type{LineNumberNode} )(l:: Int , @nospecialize (f) ) = $ (Expr (:new , :LineNumberNode , :l , :f ))))
306
+ eval (Core, :((:: Type{GlobalRef} )(m:: Module , s:: Symbol ) = $ (Expr (:new , :GlobalRef , :m , :s ))))
307
+ eval (Core, :((:: Type{SlotNumber} )(n:: Int ) = $ (Expr (:new , :SlotNumber , :n ))))
308
+ eval (Core, :((:: Type{TypedSlot} )(n:: Int , @nospecialize (t) ) = $ (Expr (:new , :TypedSlot , :n , :t ))))
302
309
303
310
Module (name:: Symbol = :anonymous , std_imports:: Bool = true ) = ccall (:jl_f_new_module , Ref{Module}, (Any, Bool), name, std_imports)
304
311
305
- Task (f :: ANY ) = ccall (:jl_new_task , Ref{Task}, (Any, Int), f, 0 )
312
+ Task (@nospecialize (f) ) = ccall (:jl_new_task , Ref{Task}, (Any, Int), f, 0 )
306
313
307
314
# simple convert for use by constructors of types in Core
308
315
# note that there is no actual conversion defined here,
309
316
# so the methods and ccall's in Core aren't permitted to use convert
310
- convert (:: Type{Any} , x :: ANY ) = x
317
+ convert (:: Type{Any} , @nospecialize (x) ) = x
311
318
convert (:: Type{T} , x:: T ) where {T} = x
312
319
cconvert (:: Type{T} , x) where {T} = convert (T, x)
313
320
unsafe_convert (:: Type{T} , x:: T ) where {T} = x
@@ -382,16 +389,16 @@ function write(io::IO, x::String)
382
389
return nb
383
390
end
384
391
385
- show (io:: IO , x :: ANY ) = ccall (:jl_static_show , Void, (Ptr{Void}, Any), io_pointer (io), x)
392
+ show (io:: IO , @nospecialize x ) = ccall (:jl_static_show , Void, (Ptr{Void}, Any), io_pointer (io), x)
386
393
print (io:: IO , x:: Char ) = ccall (:jl_uv_putc , Void, (Ptr{Void}, Char), io_pointer (io), x)
387
394
print (io:: IO , x:: String ) = (write (io, x); nothing )
388
- print (io:: IO , x :: ANY ) = show (io, x)
389
- print (io:: IO , x :: ANY , a :: ANY ... ) = (print (io, x); print (io, a... ))
395
+ print (io:: IO , @nospecialize x ) = show (io, x)
396
+ print (io:: IO , @nospecialize (x), @nospecialize a ... ) = (print (io, x); print (io, a... ))
390
397
println (io:: IO ) = (write (io, 0x0a ); nothing ) # 0x0a = '\n'
391
- println (io:: IO , x :: ANY ... ) = (print (io, x... ); println (io))
398
+ println (io:: IO , @nospecialize x ... ) = (print (io, x... ); println (io))
392
399
393
- show (a :: ANY ) = show (STDOUT, a)
394
- print (a :: ANY ... ) = print (STDOUT, a... )
395
- println (a :: ANY ... ) = println (STDOUT, a... )
400
+ show (@nospecialize a ) = show (STDOUT, a)
401
+ print (@nospecialize a ... ) = print (STDOUT, a... )
402
+ println (@nospecialize a ... ) = println (STDOUT, a... )
396
403
397
404
ccall (:jl_set_istopmod , Void, (Any, Bool), Core, true )
0 commit comments