Skip to content

Commit

Permalink
Merge pull request #16764 from JuliaLang/jn/notequal
Browse files Browse the repository at this point in the history
change identity comparisons to use isequal
  • Loading branch information
vtjnash committed Jun 8, 2016
2 parents 11e4031 + e6e1312 commit 7c36704
Show file tree
Hide file tree
Showing 26 changed files with 125 additions and 143 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
16 changes: 8 additions & 8 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 @@ -764,7 +764,7 @@ 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))

Expand All @@ -773,7 +773,7 @@ function findprev(A, v, start::Integer)
for i = start:-1:1
A[i] == v && return i
end
0
return 0
end
findlast(A, v) = findprev(A, v, length(A))

Expand All @@ -782,7 +782,7 @@ function findprev(testf::Function, A, start::Integer)
for i = start:-1:1
testf(A[i]) && return i
end
0
return 0
end
findlast(testf::Function, A) = findprev(testf, A, length(A))

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

function find(A)
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
22 changes: 3 additions & 19 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,7 @@ haskey(d::Associative, k) = in(k,keys(d))
function in(p::Pair, a::Associative, valcmp=(==))
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 @@ -964,15 +956,7 @@ function in(key_value::Pair, dict::ImmutableDict, valcmp=(==))
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
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 @@ -393,8 +393,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 @@ -498,7 +498,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
2 changes: 1 addition & 1 deletion base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3152,7 +3152,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
4 changes: 2 additions & 2 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ end
end
@generated function _unsafe_setindex!(B::BitArray, X::Union{BitArray,Array}, I0::Union{Colon,UnitRange{Int}}, I::Union{Int,UnitRange{Int},Colon}...)
N = length(I)
rangeexp = [I[d] == Colon ? :(1:size(B, $(d+1))) : :(I[$d]) for d = 1:N]
rangeexp = [I[d] === Colon ? :(1:size(B, $(d+1))) : :(I[$d]) for d = 1:N]
quote
idxlens = @ncall $N index_lengths B I0 d->I[d]
@ncall $N setindex_shape_check X idxlens[1] d->idxlens[d+1]
Expand Down Expand Up @@ -667,7 +667,7 @@ end
end
@generated function _unsafe_setindex!(B::BitArray, x, I0::Union{Colon,UnitRange{Int}}, I::Union{Int,UnitRange{Int},Colon}...)
N = length(I)
rangeexp = [I[d] == Colon ? :(1:size(B, $(d+1))) : :(I[$d]) for d = 1:N]
rangeexp = [I[d] === Colon ? :(1:size(B, $(d+1))) : :(I[$d]) for d = 1:N]
quote
y = Bool(x)
idxlens = @ncall $N index_lengths B I0 d->I[d]
Expand Down
19 changes: 17 additions & 2 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,22 @@ supertype(T::DataType) = T.super

## generic comparison ##

==(x,y) = x === y

==(x, y) = x === y
isequal(x, y) = x == y

## minimally-invasive changes to test == causing NotComparableError
# export NotComparableError
# =={T}(x::T, y::T) = x === y
# immutable NotComparableError <: Exception end
# const NotComparable = NotComparableError()
# ==(x::ANY, y::ANY) = NotComparable
# !(e::NotComparableError) = throw(e)
# isequal(x, y) = (x == y) === true

## alternative NotComparableError which captures context
# immutable NotComparableError; a; b; end
# ==(x::ANY, y::ANY) = NotComparableError(x, y)

isequal(x::AbstractFloat, y::AbstractFloat) = (isnan(x) & isnan(y)) | (signbit(x) == signbit(y)) & (x == y)
isequal(x::Real, y::AbstractFloat) = (isnan(x) & isnan(y)) | (signbit(x) == signbit(y)) & (x == y)
isequal(x::AbstractFloat, y::Real ) = (isnan(x) & isnan(y)) | (signbit(x) == signbit(y)) & (x == y)
Expand All @@ -27,6 +40,8 @@ function !=(T::Type, S::Type)
@_pure_meta
!(T == S)
end
==(T::TypeVar, S::Type) = false
==(T::Type, S::TypeVar) = false

## comparison fallbacks ##

Expand Down
Loading

0 comments on commit 7c36704

Please sign in to comment.