Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/namedtuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ end
length(t::NamedTuple) = nfields(t)
iterate(t::NamedTuple, iter=1) = iter > nfields(t) ? nothing : (getfield(t, iter), iter + 1)
rest(t::NamedTuple) = t
@inline rest(t::NamedTuple{names}, i::Int) where {names} = NamedTuple{rest(names,i)}(t)
@inline rest(t::NamedTuple{names}, i) where {names} = NamedTuple{rest(names,i::Int)}(t)
firstindex(t::NamedTuple) = 1
lastindex(t::NamedTuple) = nfields(t)
getindex(t::NamedTuple, i::Int) = getfield(t, i)
Expand Down
8 changes: 6 additions & 2 deletions base/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,12 @@ julia> first, Base.rest(a, state)
"""
function rest end
rest(t::Tuple) = t
rest(t::Tuple, i::Int) = ntuple(x -> getfield(t, x+i-1), length(t)-i+1)
rest(a::Union{Array,Memory,Core.SimpleVector}, i::Int=1) = a[i:end]
function rest(t::Tuple, i)
let i = i::Int
ntuple(x -> getfield(t, x+i-1), length(t)-i+1)
end
end
rest(a::Union{Array,Memory,Core.SimpleVector}, i=1) = a[(i::Int):end]
rest(itr, state...) = Iterators.rest(itr, state...)

"""
Expand Down
19 changes: 19 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8193,6 +8193,25 @@ foo46503(a::Int, b::Nothing) = @invoke foo46503(a::Any, b)
foo46503(@nospecialize(a), b::Union{Nothing, Float64}) = rand() + 10
@test 10 <= foo46503(1, nothing) <= 11

@testset "inference for `rest` with unknown state argument types" begin
@testset "`Array`, `Memory`" begin
for typ in (Vector{Float32}, Matrix{Float32}, Memory{Float32})
@test (isconcretetype ∘ Base.infer_return_type)(Base.rest, Tuple{typ, Any})
for e in (Base.Compiler.is_terminates, Base.Compiler.is_notaskstate, Base.Compiler.is_nonoverlayed)
@test (e ∘ Base.infer_effects)(Base.rest, Tuple{typ, Any})
end
end
end
@testset "`Tuple`" begin
typ = NTuple{5, Float32}
@test Base.infer_return_type(Base.rest, Tuple{typ, Any}) <: Tuple
end
@testset "`NamedTuple`" begin
typ = NamedTuple{(:a, :b, :c, :d, :e), NTuple{5, Float32}}
@test Base.infer_return_type(Base.rest, Tuple{typ, Any}) <: NamedTuple
end
end

@testset "effect override on Symbol(::String)" begin
@test Core.Compiler.is_foldable(Base.infer_effects(Symbol, (String,)))
end
Expand Down