From 277937594ca8666b91e4fe78751c9e28da6ea5b7 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Thu, 30 Jul 2020 17:02:29 -0400 Subject: [PATCH] add a constructor for Union{} This often shows up accidentally in method intersections, which can force recompilation of completely unrelated code. Define this explicitly so that the compiler can always ignore this dispatch possibility. --- base/boot.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/base/boot.jl b/base/boot.jl index 86ec4f346ef42..bd554672e4ff7 100644 --- a/base/boot.jl +++ b/base/boot.jl @@ -226,6 +226,10 @@ ccall(:jl_toplevel_eval_in, Any, (Any, Any), (f::typeof(Typeof))(x) = ($(_expr(:meta,:nospecialize,:x)); isa(x,Type) ? Type{x} : typeof(x)) end) +# let the compiler assume that calling Union{} as a constructor does not need +# to be considered ever (which comes up often as Type{<:T}) +Union{}(a...) = throw(MethodError(Union{}, a)) + macro nospecialize(x) _expr(:meta, :nospecialize, x) end