diff --git a/base/array.jl b/base/array.jl index 694a3913cacf4..7a923cc2ab608 100644 --- a/base/array.jl +++ b/base/array.jl @@ -168,8 +168,7 @@ julia> Base.isbitsunion(Union{Float64, String}) false ``` """ -isbitsunion(u::Union) = allocatedinline(u) -isbitsunion(x) = false +isbitsunion(@nospecialize x) = isa(x, Union) && allocatedinline(x) function _unsetindex!(A::Array{T}, i::Int) where {T} @inline diff --git a/base/compiler/typeutils.jl b/base/compiler/typeutils.jl index 0950150637b0a..312f1680d0b91 100644 --- a/base/compiler/typeutils.jl +++ b/base/compiler/typeutils.jl @@ -17,14 +17,16 @@ function hasuniquerep(@nospecialize t) isa(t, TypeVar) && return false # TypeVars are identified by address, not equality iskindtype(typeof(t)) || return true # non-types are always compared by egal in the type system isconcretetype(t) && return true # these are also interned and pointer comparable - if isa(t, DataType) && t.name !== Tuple.name && !isvarargtype(t) # invariant DataTypes - return _all(hasuniquerep, t.parameters) + if isa(t, Union) + return hasuniquerep(t.a) && hasuniquerep(t.b) + elseif isa(t, DataType) && t.name !== Tuple.name && !isvarargtype(t) # invariant DataTypes + return all(hasuniquerep, t.parameters) end return false end """ - isTypeDataType(@nospecialize t) -> Bool + isTypeDataType(t) -> Bool For a type `t` test whether ∀S s.t. `isa(S, rewrap_unionall(Type{t}, ...))`, we have `isa(S, DataType)`. In particular, if a statement is typed as `Type{t}` diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index 5adc1a0dc6c4c..c51bb243556cc 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -4709,3 +4709,8 @@ end @Base.constprop :aggressive type_level_recurse2(x...) = type_level_recurse1(x...) type_level_recurse_entry() = Val{type_level_recurse1(1)}() @test Base.return_types(type_level_recurse_entry, ()) |> only == Val{1} + +# `isconstType` for `Union`-types +@test Base.return_types((Type{Union{Int,UInt}},)) do T + Base.allocatedinline(T) ? nothing : missing +end |> only === Nothing