Skip to content

Commit

Permalink
Revert "better type inference for several functions taking NTuple a…
Browse files Browse the repository at this point in the history
…rgs" (JuliaLang#55375)

Reverts JuliaLang#55124 as this turns out to hurt performance
quite a bit

Closes JuliaLang#55374
  • Loading branch information
vtjnash authored Aug 6, 2024
1 parent 1e1e710 commit 0717a94
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 28 deletions.
8 changes: 1 addition & 7 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -501,13 +501,7 @@ julia> Base.tail(())
ERROR: ArgumentError: Cannot call tail on an empty tuple.
```
"""
function tail(x::Tuple{Any,Vararg})
y = argtail(x...)::Tuple
if x isa NTuple # help the type inference
y = y::NTuple
end
y
end
tail(x::Tuple) = argtail(x...)
tail(::Tuple{}) = throw(ArgumentError("Cannot call tail on an empty tuple."))

function unwrap_unionall(@nospecialize(a))
Expand Down
2 changes: 1 addition & 1 deletion base/ntuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,5 @@ end
function reverse(t::NTuple{N}) where N
ntuple(Val{N}()) do i
t[end+1-i]
end::NTuple
end
end
16 changes: 3 additions & 13 deletions base/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,9 @@ ERROR: ArgumentError: Cannot call front on an empty tuple.
"""
function front(t::Tuple)
@inline
if t === ()
throw(ArgumentError("Cannot call front on an empty tuple."))
end
r = _front(t...)::Tuple
if t isa NTuple # help the type inference
r = r::NTuple
end
r
_front(t...)
end
_front() = throw(ArgumentError("Cannot call front on an empty tuple."))
_front(v) = ()
function _front(v, t...)
@inline
Expand Down Expand Up @@ -705,9 +699,5 @@ function circshift(x::Tuple{Any,Any,Any,Vararg{Any,N}}, shift::Integer) where {N
@inline
len = N + 3
j = mod1(shift, len)
y = ntuple(k -> getindex(x, k-j+ifelse(k>j,0,len)), Val(len))::Tuple
if x isa NTuple # help the type inference
y = y::NTuple
end
y
ntuple(k -> getindex(x, k-j+ifelse(k>j,0,len)), Val(len))::Tuple
end
7 changes: 0 additions & 7 deletions test/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -845,10 +845,3 @@ end
end
end
end

@testset "abstract return type inference for homogeneous tuples" begin
@test NTuple == Core.Compiler.return_type(Base.tail, Tuple{NTuple})
@test NTuple == Core.Compiler.return_type(Base.front, Tuple{NTuple})
@test NTuple == Core.Compiler.return_type(reverse, Tuple{NTuple})
@test NTuple == Core.Compiler.return_type(circshift, Tuple{NTuple,Int})
end

0 comments on commit 0717a94

Please sign in to comment.