@@ -182,26 +182,36 @@ else
182182end
183183
184184function 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 )
186194
187195abstract type Exception end
188196mutable struct ErrorException <: Exception
189197 msg:: AbstractString
190198 ErrorException (msg:: AbstractString ) = new (msg)
191199end
192200
193- Expr (args:: ANY... ) = _expr (args... )
194-
195201macro _noinline_meta ()
196202 Expr (:meta , :noinline )
197203end
198204
205+ macro nospecialize (x)
206+ Expr (:meta , :nospecialize , x)
207+ end
208+
199209struct BoundsError <: Exception
200210 a:: Any
201211 i:: Any
202212 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))
205215end
206216struct DivideError <: Exception end
207217struct DomainError <: Exception end
@@ -232,16 +242,16 @@ getptls() = ccall(:jl_get_ptls_states, Ptr{Void}, ())
232242
233243include (m:: Module , fname:: String ) = ccall (:jl_load_ , Any, (Any, Any), m, fname)
234244
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)
237247
238- kwfunc (f :: ANY ) = ccall (:jl_get_keyword_sorter , Any, (Any,), f)
248+ kwfunc (@nospecialize (f) ) = ccall (:jl_get_keyword_sorter , Any, (Any,), f)
239249
240- kwftype (t :: ANY ) = typeof (ccall (:jl_get_kwsorter , Any, (Any,), t))
250+ kwftype (@nospecialize (t) ) = typeof (ccall (:jl_get_kwsorter , Any, (Any,), t))
241251
242252mutable struct Box
243253 contents:: Any
244- Box (x :: ANY ) = new (x)
254+ Box (@nospecialize (x) ) = new (x)
245255 Box () = new ()
246256end
247257
@@ -250,18 +260,18 @@ end
250260mutable struct WeakRef
251261 value
252262 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)
255265end
256266
257267TypeVar (n:: Symbol ) =
258268 ccall (:jl_new_typevar , Ref{TypeVar}, (Any, Any, Any), n, Union{}, Any)
259- TypeVar (n:: Symbol , ub :: ANY ) =
269+ TypeVar (n:: Symbol , @nospecialize (ub) ) =
260270 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) ) =
262272 ccall (:jl_new_typevar , Ref{TypeVar}, (Any, Any, Any), n, lb, ub)
263273
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)
265275
266276Void () = nothing
267277
@@ -276,26 +286,26 @@ VecElement(arg::T) where {T} = VecElement{T}(arg)
276286# used by lowering of splicing unquote
277287splicedexpr (hd:: Symbol , args:: Array{Any,1} ) = (e= Expr (hd); e. args= args; e)
278288
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 ))))
280290_new (:LabelNode , :Int )
281291_new (:GotoNode , :Int )
282292_new (:NewvarNode , :SlotNumber )
283- _new (:QuoteNode , :ANY )
293+ _new (:QuoteNode , :Any )
284294_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 ))))
290300
291301Module (name:: Symbol = :anonymous , std_imports:: Bool = true ) = ccall (:jl_f_new_module , Ref{Module}, (Any, Bool), name, std_imports)
292302
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 )
294304
295305# simple convert for use by constructors of types in Core
296306# note that there is no actual conversion defined here,
297307# 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
299309convert (:: Type{T} , x:: T ) where {T} = x
300310cconvert (:: Type{T} , x) where {T} = convert (T, x)
301311unsafe_convert (:: Type{T} , x:: T ) where {T} = x
@@ -370,16 +380,16 @@ function write(io::IO, x::String)
370380 return nb
371381end
372382
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)
374384print (io:: IO , x:: Char ) = ccall (:jl_uv_putc , Void, (Ptr{Void}, Char), io_pointer (io), x)
375385print (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... ))
378388println (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))
380390
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... )
384394
385395ccall (:jl_set_istopmod , Void, (Any, Bool), Core, true )
0 commit comments