diff --git a/base/bool.jl b/base/bool.jl index 7d1e7b54970a13..92a27543d2fbc1 100644 --- a/base/bool.jl +++ b/base/bool.jl @@ -30,11 +30,7 @@ julia> .![true false true] 0 1 0 ``` """ -function !(x::Bool) - ## We need a better heuristic to detect this automatically - @_pure_meta - return not_int(x) -end +!(x::Bool) = not_int(x) (~)(x::Bool) = !x (&)(x::Bool, y::Bool) = and_int(x, y) diff --git a/base/essentials.jl b/base/essentials.jl index 1c69e81ceb7de5..d9a8b0b46af8c5 100644 --- a/base/essentials.jl +++ b/base/essentials.jl @@ -248,7 +248,7 @@ end # replace TypeVars in all enclosing UnionAlls with fresh TypeVars function rename_unionall(@nospecialize(u)) - if !isa(u,UnionAll) + if !isa(u, UnionAll) return u end body = rename_unionall(u.body) @@ -692,7 +692,7 @@ julia> f(Val(true)) struct Val{x} end -Val(x) = (@_pure_meta; Val{x}()) +Val(x) = Val{x}() """ invokelatest(f, args...; kwargs...) diff --git a/base/promotion.jl b/base/promotion.jl index bbdf8e651708dc..22768439dd6582 100644 --- a/base/promotion.jl +++ b/base/promotion.jl @@ -9,8 +9,8 @@ Return the closest common ancestor of `T` and `S`, i.e. the narrowest type from which they both inherit. """ -typejoin() = (@_pure_meta; Bottom) -typejoin(@nospecialize(t)) = (@_pure_meta; t) +typejoin() = Bottom +typejoin(@nospecialize(t)) = t typejoin(@nospecialize(t), ts...) = (@_pure_meta; typejoin(t, typejoin(ts...))) function typejoin(@nospecialize(a), @nospecialize(b)) @_pure_meta diff --git a/base/reflection.jl b/base/reflection.jl index 284ff62d181aef..ac301d023619e8 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -534,31 +534,6 @@ struct type with no fields. """ issingletontype(@nospecialize(t)) = (@_pure_meta; isa(t, DataType) && isdefined(t, :instance)) -""" - Base.parameter_upper_bound(t::UnionAll, idx) - -Determine the upper bound of a type parameter in the underlying datatype. -This method should generally not be relied upon: -code instead should usually use static parameters in dispatch to extract these values. - -# Examples -```jldoctest -julia> struct Foo{T<:AbstractFloat, N} - x::Tuple{T, N} - end - -julia> Base.parameter_upper_bound(Foo, 1) -AbstractFloat - -julia> Base.parameter_upper_bound(Foo, 2) -Any -``` -""" -function parameter_upper_bound(t::UnionAll, idx) - @_pure_meta - return rewrap_unionall((unwrap_unionall(t)::DataType).parameters[idx], t) -end - """ typeintersect(T, S) @@ -725,13 +700,12 @@ julia> instances(Color) function instances end function to_tuple_type(@nospecialize(t)) - @_pure_meta - if isa(t,Tuple) || isa(t,AbstractArray) || isa(t,SimpleVector) + if isa(t, Tuple) || isa(t, AbstractArray) || isa(t, SimpleVector) t = Tuple{t...} end - if isa(t,Type) && t<:Tuple + if isa(t, Type) && t <: Tuple for p in unwrap_unionall(t).parameters - if !(isa(p,Type) || isa(p,TypeVar)) + if !(isa(p, Type) || isa(p, TypeVar)) error("argument tuple type must contain only types") end end diff --git a/base/tuple.jl b/base/tuple.jl index 87f885f464548d..f51507b4700c87 100644 --- a/base/tuple.jl +++ b/base/tuple.jl @@ -118,6 +118,7 @@ function _compute_eltype(t::Type{<:Tuple}) @nospecialize t t isa Union && return promote_typejoin(eltype(t.a), eltype(t.b)) t´ = unwrap_unionall(t) + # TODO: handle Union/UnionAll correctly here r = Union{} for ti in t´.parameters r = promote_typejoin(r, rewrap_unionall(unwrapva(ti), t)) diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index d04636b258909c..464c279c917738 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -799,12 +799,6 @@ fUnionAll(::Type{T}) where {T} = Type{S} where S <: T @inferred fUnionAll(Real) == Type{T} where T <: Real @inferred fUnionAll(Rational{T} where T <: AbstractFloat) == Type{T} where T<:(Rational{S} where S <: AbstractFloat) -fComplicatedUnionAll(::Type{T}) where {T} = Type{Tuple{S,rand() >= 0.5 ? Int : Float64}} where S <: T -let pub = Base.parameter_upper_bound, x = fComplicatedUnionAll(Real) - @test pub(pub(x, 1), 1) == Real - @test pub(pub(x, 1), 2) == Int || pub(pub(x, 1), 2) == Float64 -end - # issue #20733 # run this test in a separate process to avoid interfering with `getindex` let def = "Base.getindex(t::NTuple{3,NTuple{2,Int}}, i::Int, j::Int, k::Int) = (t[1][i], t[2][j], t[3][k])" diff --git a/test/reflection.jl b/test/reflection.jl index 5249524e18b48a..9e311d72776703 100644 --- a/test/reflection.jl +++ b/test/reflection.jl @@ -559,10 +559,6 @@ end @test !isstructtype(Int) @test isstructtype(TLayout) -@test Base.parameter_upper_bound(ReflectionExample, 1) === AbstractFloat -@test Base.parameter_upper_bound(ReflectionExample, 2) === Any -@test Base.parameter_upper_bound(ReflectionExample{T, N} where T where N <: Real, 2) === Real - let wrapperT(T) = Base.typename(T).wrapper @test @inferred wrapperT(ReflectionExample{Float64, Int64}) == ReflectionExample