Skip to content

Commit

Permalink
change identity comparisons to use isequal
Browse files Browse the repository at this point in the history
it would now be possible to make == with non-comparable items an error
since these notions are no longer coupled

fix #9381
ref #15983
  • Loading branch information
vtjnash committed Jun 4, 2016
1 parent 967ef80 commit a2979ec
Show file tree
Hide file tree
Showing 32 changed files with 149 additions and 136 deletions.
12 changes: 6 additions & 6 deletions base/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1494,11 +1494,11 @@ activate(m::ModalInterface, s::MIState, termbuf, term::TextTerminal) =

commit_changes(t::UnixTerminal, termbuf) = write(t, takebuf_array(termbuf.out_stream))
function transition(f::Function, s::MIState, mode)
if mode == :abort
if mode === :abort
s.aborted = true
return
end
if mode == :reset
if mode === :reset
reset_state(s)
return
end
Expand Down Expand Up @@ -1599,16 +1599,16 @@ function prompt!(term, prompt, s = init_state(term, prompt))
warn(e)
state = :done
end
if state == :abort
if state === :abort
return buffer(s), false, false
elseif state == :done
elseif state === :done
return buffer(s), true, false
elseif state == :suspend
elseif state === :suspend
if is_unix()
return buffer(s), true, true
end
else
@assert state == :ok
@assert state === :ok
end
end
finally
Expand Down
16 changes: 8 additions & 8 deletions base/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ end
function mode_idx(hist::REPLHistoryProvider, mode)
c = :julia
for (k,v) in hist.mode_mapping
v == mode && (c = k)
isequal(v, mode) && (c = k)
end
return c
end
Expand All @@ -387,7 +387,7 @@ function add_history(hist::REPLHistoryProvider, s)
isempty(strip(str)) && return
mode = mode_idx(hist, LineEdit.mode(s))
!isempty(hist.history) &&
mode == hist.modes[end] && str == hist.history[end] && return
isequal(mode, hist.modes[end]) && str == hist.history[end] && return
push!(hist.modes, mode)
push!(hist.history, str)
hist.history_file === nothing && return
Expand Down Expand Up @@ -457,13 +457,13 @@ function history_prev(s::LineEdit.MIState, hist::REPLHistoryProvider,
save_idx::Int = hist.cur_idx)
hist.last_idx = -1
m = history_move(s, hist, hist.cur_idx-1, save_idx)
if m == :ok
if m === :ok
LineEdit.move_input_start(s)
LineEdit.reset_key_repeats(s) do
LineEdit.move_line_end(s)
end
LineEdit.refresh_line(s)
elseif m == :skip
elseif m === :skip
hist.cur_idx -= 1
history_prev(s, hist, save_idx)
else
Expand All @@ -481,10 +481,10 @@ function history_next(s::LineEdit.MIState, hist::REPLHistoryProvider,
hist.last_idx = -1
end
m = history_move(s, hist, cur_idx+1, save_idx)
if m == :ok
if m === :ok
LineEdit.move_input_end(s)
LineEdit.refresh_line(s)
elseif m == :skip
elseif m === :skip
hist.cur_idx += 1
history_next(s, hist, save_idx)
else
Expand All @@ -508,7 +508,7 @@ function history_move_prefix(s::LineEdit.PrefixSearchState,
for idx in idxs
if (idx == max_idx) || (startswith(hist.history[idx], prefix) && (hist.history[idx] != cur_response || hist.modes[idx] != LineEdit.mode(s)))
m = history_move(s, hist, idx)
if m == :ok
if m === :ok
if idx == max_idx
# on resuming the in-progress edit, leave the cursor where the user last had it
elseif isempty(prefix)
Expand All @@ -520,7 +520,7 @@ function history_move_prefix(s::LineEdit.PrefixSearchState,
end
LineEdit.refresh_line(s)
return :ok
elseif m == :skip
elseif m === :skip
return history_move_prefix(s,hist,prefix,backwards,idx)
end
end
Expand Down
24 changes: 13 additions & 11 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ end
function lexcmp(a::Array{UInt8,1}, b::Array{UInt8,1})
c = ccall(:memcmp, Int32, (Ptr{UInt8}, Ptr{UInt8}, UInt),
a, b, min(length(a),length(b)))
c < 0 ? -1 : c > 0 ? +1 : cmp(length(a),length(b))
return c < 0 ? -1 : c > 0 ? +1 : cmp(length(a),length(b))
end

function reverse(A::AbstractVector, s=1, n=length(A))
Expand All @@ -664,7 +664,7 @@ function reverse(A::AbstractVector, s=1, n=length(A))
for i = n+1:length(A)
B[i] = A[i]
end
B
return B
end
reverseind(a::AbstractVector, i::Integer) = length(a) + 1 - i

Expand All @@ -680,7 +680,7 @@ function reverse!(v::AbstractVector, s=1, n=length(v))
v[i], v[r] = v[r], v[i]
r -= 1
end
v
return v
end

function vcat{T}(arrays::Vector{T}...)
Expand Down Expand Up @@ -712,7 +712,7 @@ function hcat{T}(V::Vector{T}...)
throw(DimensionMismatch("vectors must have same lengths"))
end
end
[ V[j][i]::T for i=1:length(V[1]), j=1:length(V) ]
return [ V[j][i]::T for i=1:length(V[1]), j=1:length(V) ]
end

hcat(A::Matrix...) = typed_hcat(promote_eltype(A...), A...)
Expand Down Expand Up @@ -740,7 +740,7 @@ findfirst(A) = findnext(A, 1)
# returns the index of the next matching element
function findnext(A, v, start::Integer)
for i = start:length(A)
if A[i] == v
if isequal(A[i], v)
return i
end
end
Expand All @@ -764,25 +764,27 @@ function findprev(A, start::Integer)
for i = start:-1:1
A[i] != 0 && return i
end
0
return 0
end
findlast(A) = findprev(A, length(A))

# returns the index of the matching element, or 0 if no matching
function findprev(A, v, start::Integer)
for i = start:-1:1
A[i] == v && return i
isequal(A[i], v) && return i
end
0
return 0
end
findlast(A, v) = findprev(A, v, length(A))

# returns the index of the previous element for which the function returns true, or zero if it never does
function findprev(testf::Function, A, start::Integer)
for i = start:-1:1
testf(A[i]) && return i
if testf(A[i])
return i
end
end
0
return 0
end
findlast(testf::Function, A) = findprev(testf, A, length(A))

Expand All @@ -797,7 +799,7 @@ function find(testf::Function, A)
end
I = Array{Int}(length(tmpI))
copy!(I, tmpI)
I
return I
end

function find(A)
Expand Down
4 changes: 2 additions & 2 deletions base/cartesian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ function exprresolve(ex::Expr)
can_eval, result = exprresolve_arith(ex)
if can_eval
return result
elseif ex.head == :call && (ex.args[1] == :+ || ex.args[1] == :-) && length(ex.args) == 3 && ex.args[3] == 0
# simplify x+0 and x-0
elseif ex.head == :call && (ex.args[1] === :+ || ex.args[1] === :-) && length(ex.args) == 3 && isequal(ex.args[3], 0)
# simplify x + 0 and x - 0
return ex.args[2]
end
# Resolve array references
Expand Down
14 changes: 11 additions & 3 deletions base/dates/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,17 @@ function DateFormat(f::AbstractString, locale::AbstractString="english")
last_offset = m.offset + width
end

tran = last_offset > endof(f) ? r"(?=\s|$)" : replace(f[last_offset:end], r"\\(.)", s"\1")
if !isempty(params)
slot = tran == "" ? FixedWidthSlot(params...) : DelimitedSlot(params..., tran)
if last_offset > endof(f)
slot = DelimitedSlot(params..., r"(?=\s|$)")
else
tran = replace(f[last_offset:end], r"\\(.)", s"\1")
if tran == ""
slot = FixedWidthSlot(params...)
else
slot = DelimitedSlot(params..., tran)
end
end
push!(slots,slot)
end

Expand Down Expand Up @@ -165,7 +173,7 @@ function parse(x::AbstractString,df::DateFormat)
cursor = 1
for slot in df.slots
cursor, pe = getslot(x,slot,df.locale,cursor)
pe != nothing && (isa(pe,Period) ? push!(periods,pe) : push!(extra,pe))
pe !== nothing && (isa(pe,Period) ? push!(periods,pe) : push!(extra,pe))
cursor > endof(x) && break
end
sort!(periods,rev=true,lt=periodisless)
Expand Down
30 changes: 7 additions & 23 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,10 @@ const secret_table_token = :__c782dbf1cf4d6a2e5e3865d7e95634f2e09b5902__

haskey(d::Associative, k) = in(k,keys(d))

function in(p::Pair, a::Associative, valcmp=(==))
v = get(a,p[1],secret_table_token)
function in(p::Pair, a::Associative, valcmp=isequal)
v = get(a, p[1], secret_table_token)
if !is(v, secret_table_token)
if valcmp === is
is(v, p[2]) && return true
elseif valcmp === (==)
==(v, p[2]) && return true
elseif valcmp === isequal
isequal(v, p[2]) && return true
else
valcmp(v, p[2]) && return true
end
valcmp(v, p[2]) && return true
end
return false
end
Expand All @@ -30,7 +22,7 @@ end

function summary(t::Associative)
n = length(t)
string(typeof(t), " with ", n, (n==1 ? " entry" : " entries"))
return string(typeof(t), " with ", n, (n==1 ? " entry" : " entries"))
end

function _truncate_at_width_or_chars(str, width, chars="", truncmark="")
Expand Down Expand Up @@ -960,19 +952,11 @@ ImmutableDict
ImmutableDict{K,V}(KV::Pair{K,V}) = ImmutableDict{K,V}(KV[1], KV[2])
ImmutableDict{K,V}(t::ImmutableDict{K,V}, KV::Pair) = ImmutableDict{K,V}(t, KV[1], KV[2])

function in(key_value::Pair, dict::ImmutableDict, valcmp=(==))
function in(key_value::Pair, dict::ImmutableDict, valcmp=isequal)
key, value = key_value
while isdefined(dict, :parent)
if dict.key == key
if valcmp === is
is(value, dict.value) && return true
elseif valcmp === (==)
==(value, dict.value) && return true
elseif valcmp === isequal
isequal(value, dict.value) && return true
else
valcmp(value, dict.value) && return true
end
if isequal(dict.key, key)
valcmp(value, dict.value) && return true
end
dict = dict.parent
end
Expand Down
6 changes: 3 additions & 3 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ const keywords = Dict{Symbol, DocStr}()
isdoc(s::AbstractString) = true

isdoc(x) = isexpr(x, :string) ||
(isexpr(x, :macrocall) && x.args[1] == Symbol("@doc_str")) ||
(isexpr(x, :call) && x.args[1] == Base.Markdown.doc_str)
(isexpr(x, :macrocall) && x.args[1] === Symbol("@doc_str")) ||
(isexpr(x, :call) && x.args[1] === Base.Markdown.doc_str)

function unblock(ex)
isexpr(ex, :block) || return ex
Expand Down Expand Up @@ -497,7 +497,7 @@ function moduledoc(meta, def, def′)
docex = Expr(:call, doc!, bindingexpr(name),
docexpr(lazy_iterpolate(meta), metadata(name))
)
if def == nothing
if def === nothing
esc(:(eval($name, $(quot(docex)))))
else
def = unblock(def)
Expand Down
4 changes: 2 additions & 2 deletions base/docs/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function repl(s::Symbol)
end
end

isregex(x) = isexpr(x, :macrocall, 2) && x.args[1] == Symbol("@r_str") && !isempty(x.args[2])
isregex(x) = isexpr(x, :macrocall, 2) && x.args[1] === Symbol("@r_str") && !isempty(x.args[2])

repl(ex::Expr) = isregex(ex) ? :(apropos($ex)) : _repl(ex)

Expand All @@ -154,7 +154,7 @@ function _repl(x)
if isexpr(x, :call)
# Handles function call syntax where each argument is an atom (symbol, number, etc.)
t = Base.gen_call_with_extracted_types(doc, x)
(isexpr(t, :call, 3) && t.args[1] == doc) && (docs = t)
(isexpr(t, :call, 3) && t.args[1] === doc) && (docs = t)
end
if isfield(x)
quote
Expand Down
2 changes: 1 addition & 1 deletion base/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function retry(f::Function, retry_on::Function=DEFAULT_RETRY_ON; n=DEFAULT_RETRY
try
return f(args...)
catch e
if i > n || try retry_on(e) end != true
if i > n || try retry_on(e) end !== true
rethrow(e)
end
end
Expand Down
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export
Irrational,
Matrix,
MergeSort,
NotComparableError,
NTuple,
Nullable,
ObjectIdDict,
Expand Down
6 changes: 3 additions & 3 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2930,10 +2930,10 @@ function inlining_pass(e::Expr, sv, linfo)
basenumtype = Union{corenumtype, Main.Base.Complex64, Main.Base.Complex128, Main.Base.Rational}
if isa(a1,basenumtype) || ((isa(a1,Symbol) || isa(a1,Slot) || isa(a1,SSAValue)) &&
exprtype(a1,sv) basenumtype)
if e.args[3]==2
if isequal(e.args[3], 2)
e.args = Any[GlobalRef(Main.Base,:*), a1, a1]
f = Main.Base.:*; ft = abstract_eval_constant(f)
elseif e.args[3]==3
elseif isequal(e.args[3], 3)
e.args = Any[GlobalRef(Main.Base,:*), a1, a1, a1]
f = Main.Base.:*; ft = abstract_eval_constant(f)
end
Expand Down Expand Up @@ -3171,7 +3171,7 @@ end
# boundscheck context in the method body
function inbounds_meta_elim_pass!(code::Array{Any,1})
if findfirst(x -> isa(x, Expr) &&
((x.head === :inbounds && x.args[1] == true) || x.head === :boundscheck),
((x.head === :inbounds && x.args[1] === true) || x.head === :boundscheck),
code) == 0
filter!(x -> !(isa(x, Expr) && x.head === :inbounds), code)
end
Expand Down
10 changes: 5 additions & 5 deletions base/multi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ end

function test_existing_ref(r::AbstractRemoteRef)
found = getkey(client_refs, r, false)
if !is(found,false)
if found !== false
if client_refs[r] == true
@assert r.where > 0
if isa(r, Future) && isnull(found.v) && !isnull(r.v)
Expand Down Expand Up @@ -640,7 +640,7 @@ function del_client(pg, id, client)
# 14445 is fixed.
@async begin
rv = get(pg.refs, id, false)
if rv != false
if rv !== false
delete!(rv.clientset, client)
if isempty(rv.clientset)
delete!(pg.refs, id)
Expand Down Expand Up @@ -1366,7 +1366,7 @@ function setup_launched_worker(manager, wconfig, launched_q)
# process on the remote machine, with a request to start additional workers of the
# same type. This is done by setting an appropriate value to `WorkerConfig.cnt`.
cnt = get(wconfig.count, 1)
if cnt == :auto
if cnt === :auto
cnt = get(wconfig.environ)[:cpu_cores]
end
cnt = cnt - 1 # Removing self from the requested number
Expand Down Expand Up @@ -1757,12 +1757,12 @@ function terminate_all_workers()

if nprocs() > 1
ret = rmprocs(workers(); waitfor=0.5)
if ret != :ok
if ret !== :ok
warn("Forcibly interrupting busy workers")
# Might be computation bound, interrupt them and try again
interrupt(workers())
ret = rmprocs(workers(); waitfor=0.5)
if ret != :ok
if ret !== :ok
warn("Unable to terminate all workers")
end
end
Expand Down
Loading

0 comments on commit a2979ec

Please sign in to comment.