Skip to content

Commit f43d505

Browse files
committed
Drop support for Base.tail()
This causes invalidations and should not be needed anymore by the upstream ChainRules.
1 parent 0b2ebfe commit f43d505

File tree

6 files changed

+1
-24
lines changed

6 files changed

+1
-24
lines changed

src/tangent_types/abstract_zero.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Base.iterate(x::AbstractZero) = (x, nothing)
1717
Base.iterate(::AbstractZero, ::Any) = nothing
1818

1919
Base.first(x::AbstractZero) = x
20-
Base.tail(x::AbstractZero) = x
2120
Base.last(x::AbstractZero) = x
2221

2322
Base.Broadcast.broadcastable(x::AbstractZero) = Ref(x)

src/tangent_types/structural_tangent.jl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -360,16 +360,6 @@ Base.iszero(::Tangent{<:,Tuple{}}) = true
360360
Base.first(tangent::Tangent{P,T}) where {P,T<:Union{Tuple,NamedTuple}} = first(backing(canonicalize(tangent)))
361361
Base.last(tangent::Tangent{P,T}) where {P,T<:Union{Tuple,NamedTuple}} = last(backing(canonicalize(tangent)))
362362

363-
Base.tail(t::Tangent{P}) where {P<:Tuple} = Tangent{_tailtype(P)}(Base.tail(backing(canonicalize(t)))...)
364-
@generated _tailtype(::Type{P}) where {P<:Tuple} = Tuple{P.parameters[2:end]...}
365-
Base.tail(t::Tangent{<:Tuple{Any}}) = NoTangent()
366-
Base.tail(t::Tangent{<:Tuple{}}) = NoTangent()
367-
368-
Base.tail(t::Tangent{P}) where {P<:NamedTuple} = Tangent{_tailtype(P)}(; Base.tail(backing(canonicalize(t)))...)
369-
_tailtype(::Type{NamedTuple{S,P}}) where {S,P} = NamedTuple{Base.tail(S), _tailtype(P)}
370-
Base.tail(t::Tangent{<:NamedTuple{<:Any, <:Tuple{Any}}}) = NoTangent()
371-
Base.tail(t::Tangent{<:NamedTuple{<:Any, <:Tuple{}}}) = NoTangent()
372-
373363
function Base.getindex(tangent::Tangent{P,T}, idx::Int) where {P,T<:Union{Tuple,NamedTuple}}
374364
back = backing(canonicalize(tangent))
375365
return unthunk(getfield(back, idx))

src/tangent_types/thunks.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ end
3030

3131
Base.first(x::AbstractThunk) = first(unthunk(x))
3232
Base.last(x::AbstractThunk) = last(unthunk(x))
33-
Base.tail(x::AbstractThunk) = Base.tail(unthunk(x))
3433

3534
Base.:(==)(a::AbstractThunk, b::AbstractThunk) = unthunk(a) == unthunk(b)
3635

test/tangent_types/abstract_zero.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100

101101
@test first(z) === z
102102
@test last(z) === z
103-
@test Base.tail(z) === z
104103
end
105104

106105
@testset "NoTangent" begin

test/tangent_types/structural_tangent.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,11 @@ end
8484
@test getindex(Tangent{Tuple{Float64}}(@thunk 2.0^2), 1) == 4.0
8585
@test getproperty(Tangent{Tuple{Float64}}(2.0), 1) == 2.0
8686
@test getproperty(Tangent{Tuple{Float64}}(@thunk 2.0^2), 1) == 4.0
87-
@test NoTangent() === @inferred Base.tail(tang1)
88-
@test NoTangent() === @inferred Base.tail(Tangent{Tuple{}}())
8987

9088
tang3 = Tangent{Tuple{Float64, String, Vector{Float64}}}(1.0, NoTangent(), @thunk [3.0] .+ 4)
9189
@test @inferred(first(tang3)) === tang3[1] === 1.0
9290
@test @inferred(last(tang3)) isa Thunk
9391
@test unthunk(last(tang3)) == [7.0]
94-
@test Tuple(@inferred Base.tail(tang3))[1] === NoTangent()
95-
@test Tuple(Base.tail(tang3))[end] isa Thunk
9692

9793
NT = NamedTuple{(:a, :b),Tuple{Float64,Float64}}
9894
@test getindex(Tangent{NT}(; a=(@thunk 2.0^2)), :a) == 4.0
@@ -109,10 +105,6 @@ end
109105
@test unthunk(first(Tangent{NT}(; a=(@thunk 2.0^2)))) == 4.0
110106
@test last(Tangent{NT}(; a=(@thunk 2.0^2))) isa ZeroTangent
111107

112-
ntang1 = @inferred Base.tail(Tangent{NT}(; b=(@thunk 2.0^2)))
113-
@test ntang1 isa Tangent{<:NamedTuple{(:b,)}}
114-
@test NoTangent() === @inferred Base.tail(ntang1)
115-
116108
# TODO: uncomment this once https://github.com/JuliaLang/julia/issues/35516
117109
# if VERSION >= v"1.8-"
118110
# @test haskey(Tangent{Tuple{Float64}}(2.0), 1) == true

test/tangent_types/thunks.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
@test nothing === iterate(@thunk ()) == iterate(())
1818
end
1919

20-
@testset "first, last, tail" begin
20+
@testset "first, last" begin
2121
@test first(@thunk (1,2,3) .+ 4) === 5
2222
@test last(@thunk (1,2,3) .+ 4) === 7
23-
@test Base.tail(@thunk (1,2,3) .+ 4) === (6, 7)
24-
@test Base.tail(@thunk NoTangent() * 5) === NoTangent()
2523
end
2624

2725
@testset "show" begin

0 commit comments

Comments
 (0)