Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename unshift!/shift! to pushfirst!/popfirst! #25100

Merged
merged 1 commit into from
Dec 21, 2017
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
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,13 @@ Deprecated or removed
`unsafe_get`/`get` can be dropped or replaced with `coalesce`.
`NullException` has been removed.

* `unshift!` and `shift!` have been renamed to `pushfirst!` and `popfirst!` ([#23902])

* `Nullable{T}` has been deprecated and moved to the Nullables package ([#23642]).
Use `Union{T, Void}` instead, or `Union{Some{T}, Void}` if `nothing` is a possible value
(i.e. `Void <: T`). `isnull(x)` can be replaced with `x === nothing`
and `unsafe_get`/`get` can be dropped or replaced with `coalesce`.

* `CartesianRange` has been renamed `CartesianIndices` ([#24715]).

* `sub2ind` and `ind2sub` are deprecated in favor of using `CartesianIndices` and `LinearIndices` ([#24715]).
Expand Down
6 changes: 3 additions & 3 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1933,12 +1933,12 @@ map!(f::F, dest::AbstractArray, As::AbstractArray...) where {F} = map_n!(f, dest
map(f) = f()
map(f, iters...) = collect(Generator(f, iters...))

# multi-item push!, unshift! (built on top of type-specific 1-item version)
# multi-item push!, pushfirst! (built on top of type-specific 1-item version)
# (note: must not cause a dispatch loop when 1-item case is not defined)
push!(A, a, b) = push!(push!(A, a), b)
push!(A, a, b, c...) = push!(push!(A, a, b), c...)
unshift!(A, a, b) = unshift!(unshift!(A, b), a)
unshift!(A, a, b, c...) = unshift!(unshift!(A, c...), a, b)
pushfirst!(A, a, b) = pushfirst!(pushfirst!(A, b), a)
pushfirst!(A, a, b, c...) = pushfirst!(pushfirst!(A, c...), a, b)

## hashing collections ##

Expand Down
16 changes: 8 additions & 8 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ function prepend!(a::Array{<:Any,1}, items::AbstractVector)
end

prepend!(a::Vector, iter) = _prepend!(a, iteratorsize(iter), iter)
unshift!(a::Vector, iter...) = prepend!(a, iter)
pushfirst!(a::Vector, iter...) = prepend!(a, iter)

function _prepend!(a, ::Union{HasLength,HasShape}, iter)
n = length(iter)
Expand All @@ -884,7 +884,7 @@ function _prepend!(a, ::IteratorSize, iter)
n = 0
for item in iter
n += 1
unshift!(a, item)
pushfirst!(a, item)
end
reverse!(a, 1, n)
a
Expand Down Expand Up @@ -990,13 +990,13 @@ function pop!(a::Vector)
end

"""
unshift!(collection, items...) -> collection
pushfirst!(collection, items...) -> collection

Insert one or more `items` at the beginning of `collection`.

# Examples
```jldoctest
julia> unshift!([1, 2, 3, 4], 5, 6)
julia> pushfirst!([1, 2, 3, 4], 5, 6)
6-element Array{Int64,1}:
5
6
Expand All @@ -1006,15 +1006,15 @@ julia> unshift!([1, 2, 3, 4], 5, 6)
4
```
"""
function unshift!(a::Array{T,1}, item) where T
function pushfirst!(a::Array{T,1}, item) where T
item = convert(T, item)
_growbeg!(a, 1)
a[1] = item
return a
end

"""
shift!(collection) -> item
popfirst!(collection) -> item

Remove the first `item` from `collection`.

Expand All @@ -1029,7 +1029,7 @@ julia> A = [1, 2, 3, 4, 5, 6]
5
6

julia> shift!(A)
julia> popfirst!(A)
1

julia> A
Expand All @@ -1041,7 +1041,7 @@ julia> A
6
```
"""
function shift!(a::Vector)
function popfirst!(a::Vector)
if isempty(a)
throw(ArgumentError("array must be non-empty"))
end
Expand Down
4 changes: 2 additions & 2 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ function pop!(B::BitVector)
return item
end

function unshift!(B::BitVector, item)
function pushfirst!(B::BitVector, item)
item = convert(Bool, item)

Bc = B.chunks
Expand All @@ -835,7 +835,7 @@ function unshift!(B::BitVector, item)
return B
end

function shift!(B::BitVector)
function popfirst!(B::BitVector)
isempty(B) && throw(ArgumentError("argument must not be empty"))
@inbounds begin
item = B[1]
Expand Down
2 changes: 1 addition & 1 deletion base/bitset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ end
@inline delete!(s::BitSet, n::Int) = _setint!(s, n, false)
@inline delete!(s::BitSet, n::Integer) = _is_convertible_Int(n) ? delete!(s, Int(n)) : s

shift!(s::BitSet) = pop!(s, first(s))
popfirst!(s::BitSet) = pop!(s, first(s))

function empty!(s::BitSet)
empty!(s.bits)
Expand Down
10 changes: 5 additions & 5 deletions base/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ function put_unbuffered(c::Channel, v)
rethrow(ex)
end
end
taker = shift!(c.takers)
taker = popfirst!(c.takers)
yield(taker, v) # immediately give taker a chance to run, but don't block the current task
return v
end
Expand Down Expand Up @@ -318,23 +318,23 @@ task.
take!(c::Channel) = isbuffered(c) ? take_buffered(c) : take_unbuffered(c)
function take_buffered(c::Channel)
wait(c)
v = shift!(c.data)
v = popfirst!(c.data)
notify(c.cond_put, nothing, false, false) # notify only one, since only one slot has become available for a put!.
v
end

shift!(c::Channel) = take!(c)
popfirst!(c::Channel) = take!(c)

# 0-size channel
function take_unbuffered(c::Channel{T}) where T
check_channel_state(c)
push!(c.takers, current_task())
try
if length(c.putters) > 0
let refputter = Ref(shift!(c.putters))
let refputter = Ref(popfirst!(c.putters))
return Base.try_yieldto(refputter) do putter
# if we fail to start putter, put it back in the queue
putter === current_task || unshift!(c.putters, putter)
putter === current_task || pushfirst!(c.putters, putter)
end::T
end
else
Expand Down
4 changes: 2 additions & 2 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ function process_options(opts::JLOptions)
end

# remove filename from ARGS
global PROGRAM_FILE = arg_is_program ? shift!(ARGS) : ""
global PROGRAM_FILE = arg_is_program ? popfirst!(ARGS) : ""

# Load Distributed module only if any of the Distributed options have been specified.
if (opts.worker == 1) || (opts.nprocs > 0) || (opts.machinefile != C_NULL)
Expand Down Expand Up @@ -350,7 +350,7 @@ interactive sessions; this is useful to customize the interface. The argument of
REPL object. This function should be called from within the `.juliarc.jl` initialization
file.
"""
atreplinit(f::Function) = (unshift!(repl_hooks, f); nothing)
atreplinit(f::Function) = (pushfirst!(repl_hooks, f); nothing)

function __atreplinit(repl)
for f in repl_hooks
Expand Down
7 changes: 6 additions & 1 deletion base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ function produce(v)
empty = true
break
elseif isa(q,Condition) && !isempty(q.waitq)
t = shift!(q.waitq)
t = popfirst!(q.waitq)
empty = isempty(q.waitq)
break
end
Expand Down Expand Up @@ -3427,6 +3427,11 @@ workspace() = error("workspace() is discontinued, check out Revise.jl for an alt
# Issue #12902
@deprecate parentindexes parentindices

# Issue #23902
@deprecate unshift! pushfirst!
@deprecate shift! popfirst!

# Issue #23642
@deprecate_moved Nullable "Nullables"
@deprecate_moved NullException "Nullables"
@deprecate_moved isnull "Nullables"
Expand Down
4 changes: 2 additions & 2 deletions base/docs/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ function matchinds(needle, haystack; acronym = false)
lastc = '\0'
for (i, char) in enumerate(haystack)
isempty(chars) && break
while chars[1] == ' ' shift!(chars) end # skip spaces
while chars[1] == ' ' popfirst!(chars) end # skip spaces
if Unicode.lowercase(char) == Unicode.lowercase(chars[1]) &&
(!acronym || !Unicode.isalpha(lastc))
push!(is, i)
shift!(chars)
popfirst!(chars)
end
lastc = char
end
Expand Down
8 changes: 4 additions & 4 deletions base/event.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function notify(c::Condition, arg, all, error)
empty!(c.waitq)
elseif !isempty(c.waitq)
cnt = 1
t = shift!(c.waitq)
t = popfirst!(c.waitq)
error ? schedule(t, arg, error=error) : schedule(t, arg)
end
cnt
Expand Down Expand Up @@ -223,7 +223,7 @@ function ensure_rescheduled(othertask::Task)
if ct !== othertask && othertask.state == :runnable
# we failed to yield to othertask
# return it to the head of the queue to be scheduled later
unshift!(Workqueue, othertask)
pushfirst!(Workqueue, othertask)
othertask.state = :queued
end
if ct.state == :queued
Expand All @@ -238,14 +238,14 @@ function ensure_rescheduled(othertask::Task)
end

@noinline function poptask()
t = shift!(Workqueue)
t = popfirst!(Workqueue)
if t.state != :queued
# assume this somehow got queued twice,
# probably broken now, but try discarding this switch and keep going
# can't throw here, because it's probably not the fault of the caller to wait
# and don't want to use print() here, because that may try to incur a task switch
ccall(:jl_safe_printf, Cvoid, (Ptr{UInt8}, Int32...),
"\nWARNING: Workqueue inconsistency detected: shift!(Workqueue).state != :queued\n")
"\nWARNING: Workqueue inconsistency detected: popfirst!(Workqueue).state != :queued\n")
return
end
t.state = :runnable
Expand Down
4 changes: 2 additions & 2 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,8 @@ export
prepend!,
push!,
resize!,
shift!,
unshift!,
popfirst!,
pushfirst!,

# collections
all!,
Expand Down
2 changes: 1 addition & 1 deletion base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ function pushmeta!(ex::Expr, sym::Symbol, args::Any...)
push!(exargs[idx].args, tag)
else
body::Expr = inner.args[2]
unshift!(body.args, Expr(:meta, tag))
pushfirst!(body.args, Expr(:meta, tag))
end
ex
end
Expand Down
34 changes: 17 additions & 17 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4494,14 +4494,14 @@ function invoke_NF(argexprs, @nospecialize(etype), atypes::Vector{Any}, sv::Opti
ex.typ = etype
ex.args = copy(argexprs)
invoke_texpr === nothing || insert!(stmts, 2, invoke_texpr)
invoke_fexpr === nothing || unshift!(stmts, invoke_fexpr)
invoke_fexpr === nothing || pushfirst!(stmts, invoke_fexpr)

local ret_var, merge, invoke_ex, spec_hit
ret_var = add_slot!(sv.src, widenconst(etype), false)
merge = genlabel(sv)
invoke_ex = copy(ex)
invoke_ex.head = :invoke
unshift!(invoke_ex.args, nothing)
pushfirst!(invoke_ex.args, nothing)
spec_hit = false

function splitunion(atypes::Vector{Any}, i::Int)
Expand Down Expand Up @@ -4532,8 +4532,8 @@ function invoke_NF(argexprs, @nospecialize(etype), atypes::Vector{Any}, sv::Opti
isa_var = newvar!(sv, Bool)
isa_ty = Expr(:call, GlobalRef(Core, :isa), aei, ty)
isa_ty.typ = Bool
unshift!(match, Expr(:gotoifnot, isa_var, after.label))
unshift!(match, Expr(:(=), isa_var, isa_ty))
pushfirst!(match, Expr(:gotoifnot, isa_var, after.label))
pushfirst!(match, Expr(:(=), isa_var, isa_ty))
append!(stmts, match)
push!(stmts, after)
else
Expand Down Expand Up @@ -4574,7 +4574,7 @@ function invoke_NF(argexprs, @nospecialize(etype), atypes::Vector{Any}, sv::Opti
cache_linfo === nothing && return NF
add_backedge!(cache_linfo, sv)
argexprs = copy(argexprs)
unshift!(argexprs, cache_linfo)
pushfirst!(argexprs, cache_linfo)
ex = Expr(:invoke)
ex.args = argexprs
ex.typ = etype
Expand Down Expand Up @@ -4666,8 +4666,8 @@ function inlineable(@nospecialize(f), @nospecialize(ft), e::Expr, atypes::Vector
argexpr0 = argexprs[2]
atypes = atypes[4:end]
argexprs = argexprs[4:end]
unshift!(atypes, atype0)
unshift!(argexprs, argexpr0)
pushfirst!(atypes, atype0)
pushfirst!(argexprs, argexpr0)
f = isdefined(ft, :instance) ? ft.instance : nothing
elseif isa(f, IntrinsicFunction) || ft ⊑ IntrinsicFunction ||
isa(f, Builtin) || ft ⊑ Builtin
Expand Down Expand Up @@ -4885,7 +4885,7 @@ function inlineable(@nospecialize(f), @nospecialize(ft), e::Expr, atypes::Vector
aei = argexprs[i]
aeitype = argtype = widenconst(exprtype(aei, sv.src, sv.mod))
if i == 1 && !(invoke_texpr === nothing)
unshift!(prelude_stmts, invoke_texpr)
pushfirst!(prelude_stmts, invoke_texpr)
end

# ok for argument to occur more than once if the actual argument
Expand All @@ -4912,15 +4912,15 @@ function inlineable(@nospecialize(f), @nospecialize(ft), e::Expr, atypes::Vector
if occ != 0
vnew = newvar!(sv, aeitype)
argexprs[i] = vnew
unshift!(prelude_stmts, Expr(:(=), vnew, aei))
pushfirst!(prelude_stmts, Expr(:(=), vnew, aei))
stmts_free &= free
elseif !free && !isType(aeitype)
unshift!(prelude_stmts, aei)
pushfirst!(prelude_stmts, aei)
stmts_free = false
end
end
end
invoke_fexpr === nothing || unshift!(prelude_stmts, invoke_fexpr)
invoke_fexpr === nothing || pushfirst!(prelude_stmts, invoke_fexpr)

# re-number the SSAValues and copy their type-info to the new ast
ssavalue_types = src.ssavaluetypes
Expand Down Expand Up @@ -4985,7 +4985,7 @@ function inlineable(@nospecialize(f), @nospecialize(ft), e::Expr, atypes::Vector
retval = add_slot!(sv.src, rettype, false)
end
multiret = true
unshift!(a.args, retval)
pushfirst!(a.args, retval)
a.head = :(=)
push!(stmts, GotoNode(retstmt.label))
end
Expand All @@ -4994,7 +4994,7 @@ function inlineable(@nospecialize(f), @nospecialize(ft), e::Expr, atypes::Vector

if multiret
if lastexpr !== nothing
unshift!(lastexpr.args, retval)
pushfirst!(lastexpr.args, retval)
lastexpr.head = :(=)
push!(stmts, lastexpr)
end
Expand Down Expand Up @@ -5023,7 +5023,7 @@ function inlineable(@nospecialize(f), @nospecialize(ft), e::Expr, atypes::Vector
if !do_coverage && all(inlining_ignore, stmts)
empty!(stmts)
elseif isa(stmts[1], LineNumberNode)
linenode = shift!(stmts)::LineNumberNode
linenode = popfirst!(stmts)::LineNumberNode
line = linenode.line
isa(linenode.file, Symbol) && (file = linenode.file)
end
Expand All @@ -5035,15 +5035,15 @@ function inlineable(@nospecialize(f), @nospecialize(ft), e::Expr, atypes::Vector
# function inlined in it
mod = method.module
if mod === sv.mod
unshift!(stmts, Expr(:meta, :push_loc, file,
pushfirst!(stmts, Expr(:meta, :push_loc, file,
method.name, line))
else
unshift!(stmts, Expr(:meta, :push_loc, file,
pushfirst!(stmts, Expr(:meta, :push_loc, file,
method.name, line, mod))
end
push!(stmts, Expr(:meta, :pop_loc))
elseif !isempty(stmts)
unshift!(stmts, Expr(:meta, :push_loc, file,
pushfirst!(stmts, Expr(:meta, :push_loc, file,
method.name, line))
if isa(stmts[end], LineNumberNode)
stmts[end] = Expr(:meta, :pop_loc)
Expand Down
Loading