Skip to content

Commit 0717a94

Browse files
authored
Revert "better type inference for several functions taking NTuple args" (#55375)
Reverts #55124 as this turns out to hurt performance quite a bit Closes #55374
1 parent 1e1e710 commit 0717a94

File tree

4 files changed

+5
-28
lines changed

4 files changed

+5
-28
lines changed

base/essentials.jl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -501,13 +501,7 @@ julia> Base.tail(())
501501
ERROR: ArgumentError: Cannot call tail on an empty tuple.
502502
```
503503
"""
504-
function tail(x::Tuple{Any,Vararg})
505-
y = argtail(x...)::Tuple
506-
if x isa NTuple # help the type inference
507-
y = y::NTuple
508-
end
509-
y
510-
end
504+
tail(x::Tuple) = argtail(x...)
511505
tail(::Tuple{}) = throw(ArgumentError("Cannot call tail on an empty tuple."))
512506

513507
function unwrap_unionall(@nospecialize(a))

base/ntuple.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,5 @@ end
9595
function reverse(t::NTuple{N}) where N
9696
ntuple(Val{N}()) do i
9797
t[end+1-i]
98-
end::NTuple
98+
end
9999
end

base/tuple.jl

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,9 @@ ERROR: ArgumentError: Cannot call front on an empty tuple.
340340
"""
341341
function front(t::Tuple)
342342
@inline
343-
if t === ()
344-
throw(ArgumentError("Cannot call front on an empty tuple."))
345-
end
346-
r = _front(t...)::Tuple
347-
if t isa NTuple # help the type inference
348-
r = r::NTuple
349-
end
350-
r
343+
_front(t...)
351344
end
345+
_front() = throw(ArgumentError("Cannot call front on an empty tuple."))
352346
_front(v) = ()
353347
function _front(v, t...)
354348
@inline
@@ -705,9 +699,5 @@ function circshift(x::Tuple{Any,Any,Any,Vararg{Any,N}}, shift::Integer) where {N
705699
@inline
706700
len = N + 3
707701
j = mod1(shift, len)
708-
y = ntuple(k -> getindex(x, k-j+ifelse(k>j,0,len)), Val(len))::Tuple
709-
if x isa NTuple # help the type inference
710-
y = y::NTuple
711-
end
712-
y
702+
ntuple(k -> getindex(x, k-j+ifelse(k>j,0,len)), Val(len))::Tuple
713703
end

test/tuple.jl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -845,10 +845,3 @@ end
845845
end
846846
end
847847
end
848-
849-
@testset "abstract return type inference for homogeneous tuples" begin
850-
@test NTuple == Core.Compiler.return_type(Base.tail, Tuple{NTuple})
851-
@test NTuple == Core.Compiler.return_type(Base.front, Tuple{NTuple})
852-
@test NTuple == Core.Compiler.return_type(reverse, Tuple{NTuple})
853-
@test NTuple == Core.Compiler.return_type(circshift, Tuple{NTuple,Int})
854-
end

0 commit comments

Comments
 (0)