Skip to content

Commit

Permalink
pure: remove incorrect or unnecessary annotations and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Jul 14, 2020
1 parent f3b5e56 commit d4981b4
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 48 deletions.
6 changes: 1 addition & 5 deletions base/bool.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -696,7 +696,7 @@ julia> f(Val(true))
struct Val{x}
end

Val(x) = (@_pure_meta; Val{x}())
Val(x) = Val{x}()

"""
invokelatest(f, args...; kwargs...)
Expand Down
4 changes: 2 additions & 2 deletions base/promotion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 3 additions & 29 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions base/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ function _compute_eltype(t::Type{<:Tuple})
@nospecialize t
t isa Union && return promote_typejoin(eltype(t.a), eltype(t.b))
= unwrap_unionall(t)
# TODO: handle Union/UnionAll correctly here
r = Union{}
for ti in.parameters
r = promote_typejoin(r, rewrap_unionall(unwrapva(ti), t))
Expand Down
6 changes: 0 additions & 6 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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])"
Expand Down
4 changes: 0 additions & 4 deletions test/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d4981b4

Please sign in to comment.