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