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

WIP: Deprecate undefined == comparisons #18856

Closed
wants to merge 6 commits into from
Closed
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ script:
/tmp/julia/bin/julia-debug --precompiled=no -e 'true'
- /tmp/julia/bin/julia -e 'versioninfo()'
- export JULIA_CPU_CORES=2 && export JULIA_TEST_MAXRSS_MB=600 && cd /tmp/julia/share/julia/test &&
/tmp/julia/bin/julia --check-bounds=yes runtests.jl $TESTSTORUN &&
/tmp/julia/bin/julia --check-bounds=yes runtests.jl libgit2-online pkg
/tmp/julia/bin/julia runtests.jl $TESTSTORUN &&
/tmp/julia/bin/julia runtests.jl libgit2-online pkg
- cd `dirname $TRAVIS_BUILD_DIR` && mv julia2 julia &&
rm -rf julia/deps/scratch/julia-env &&
rm -f julia/deps/scratch/libgit2-*/CMakeFiles/CMakeOutput.log
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ build_script:
test_script:
- usr\bin\julia -e "versioninfo()"
- usr\bin\julia --precompiled=no -e "true"
- cd test && ..\usr\bin\julia --check-bounds=yes runtests.jl all &&
..\usr\bin\julia --check-bounds=yes runtests.jl libgit2-online pkg
- cd test && ..\usr\bin\julia runtests.jl all &&
..\usr\bin\julia runtests.jl libgit2-online pkg
9 changes: 6 additions & 3 deletions base/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ outstream(r::BasicREPL) = r.terminal

function run_frontend(repl::BasicREPL, backend::REPLBackendRef)
d = REPLDisplay(repl)
dopushdisplay = !in(d,Base.Multimedia.displays)
# FIXME: in (and therefore isequal) should work here as everywhere else, but doesn't
dopushdisplay = !any(x->x===d,Base.Multimedia.displays)
dopushdisplay && pushdisplay(d)
repl_channel, response_channel = backend.repl_channel, backend.response_channel
hit_eof = false
Expand Down Expand Up @@ -530,7 +531,8 @@ function history_move_prefix(s::LineEdit.PrefixSearchState,
max_idx = length(hist.history)+1
idxs = backwards ? ((cur_idx-1):-1:1) : ((cur_idx+1):max_idx)
for idx in idxs
if (idx == max_idx) || (startswith(hist.history[idx], prefix) && (hist.history[idx] != cur_response || hist.modes[idx] != LineEdit.mode(s)))
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 idx == max_idx
Expand Down Expand Up @@ -920,7 +922,8 @@ end

function run_frontend(repl::LineEditREPL, backend)
d = REPLDisplay(repl)
dopushdisplay = repl.specialdisplay === nothing && !in(d,Base.Multimedia.displays)
# FIXME: in (and therefore isequal) should work here as everywhere else, but doesn't
dopushdisplay = repl.specialdisplay === nothing && !any(x->x===d,Base.Multimedia.displays)
dopushdisplay && pushdisplay(d)
if !isdefined(repl,:interface)
interface = repl.interface = setup_interface(repl)
Expand Down
46 changes: 26 additions & 20 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,8 @@ end
"""
findnext(A, i::Integer)

Find the next linear index >= `i` of a non-zero element of `A`, or `0` if not found.
Find the next linear index >= `i` of a non-zero element of `A` (determined by
`!isequal(A[i], 0)`), or `0` if not found.

```jldoctest
julia> A = [0 0; 1 0]
Expand All @@ -992,7 +993,7 @@ julia> findnext(A,3)
"""
function findnext(A, start::Integer)
for i = start:length(A)
if A[i] != 0
if !isequal(A[i], 0)
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a recent proposal to make this 'iszero(x)' or zero(T), since == 0 doesn't really work right for some custom types

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would fit well with this PR. Then we would need have the fallback iszero calll isequal (rather than ==). And since isequal(0, -0.0) == false, we should define iszero on floats so that iszero(-0.0) == true

return i
end
end
Expand All @@ -1002,7 +1003,7 @@ end
"""
findfirst(A)

Return the linear index of the first non-zero value in `A` (determined by `A[i]!=0`).
Return the linear index of the first non-zero value in `A` (determined by `!isequal(A[i], 0)`).
Returns `0` if no such value is found.

```jldoctest
Expand All @@ -1020,7 +1021,8 @@ findfirst(A) = findnext(A, 1)
"""
findnext(A, v, i::Integer)

Find the next linear index >= `i` of an element of `A` equal to `v` (using `==`), or `0` if not found.
Find the next linear index >= `i` of an element of `A` equal to `v` (using `isequal`),
or `0` if not found.

```jldoctest
julia> A = [1 4; 2 2]
Expand All @@ -1037,7 +1039,7 @@ julia> findnext(A,4,3)
"""
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 Down Expand Up @@ -1115,7 +1117,8 @@ findfirst(testf::Function, A) = findnext(testf, A, 1)
"""
findprev(A, i::Integer)

Find the previous linear index <= `i` of a non-zero element of `A`, or `0` if not found.
Find the previous linear index <= `i` of a non-zero element of `A` (determined by
`!isequal(A[i], 0)`), or `0` if not found.

```jldoctest
julia> A = [0 0; 1 2]
Expand All @@ -1132,15 +1135,16 @@ julia> findprev(A,1)
"""
function findprev(A, start::Integer)
for i = start:-1:1
A[i] != 0 && return i
!isequal(A[i], 0) && return i
end
return 0
end

"""
findlast(A)

Return the linear index of the last non-zero value in `A` (determined by `A[i]!=0`).
Return the linear index of the last non-zero value in `A` (determined by
`!isequal(A[i], 0)`).
Returns `0` if there is no non-zero value in `A`.

```jldoctest
Expand All @@ -1166,7 +1170,8 @@ findlast(A) = findprev(A, length(A))
"""
findprev(A, v, i::Integer)

Find the previous linear index <= `i` of an element of `A` equal to `v` (using `==`), or `0` if not found.
Find the previous linear index <= `i` of an element of `A` equal to `v` (using `isequal`),
or `0` if not found.

```jldoctest
julia> A = [0 0; 1 2]
Expand All @@ -1183,15 +1188,15 @@ julia> findprev(A, 1, 1)
"""
function findprev(A, v, start::Integer)
for i = start:-1:1
A[i] == v && return i
isequal(A[i], v) && return i
end
return 0
end

"""
findlast(A, v)

Return the linear index of the last element equal to `v` in `A`.
Return the linear index of the last element equal to `v` in `A` (using `isequal`).
Returns `0` if there is no element of `A` equal to `v`.

```jldoctest
Expand Down Expand Up @@ -1297,9 +1302,10 @@ _index_remapper(iter) = Colon() # safe for objects that don't implement length
"""
find(A)

Return a vector of the linear indexes of the non-zeros in `A` (determined by `A[i]!=0`). A
common use of this is to convert a boolean array to an array of indexes of the `true`
elements. If there are no non-zero elements of `A`, `find` returns an empty array.
Return a vector of the linear indexes of the non-zeros in `A` (determined by
`!isequal(A[i], 0)`). A common use of this is to convert a boolean array to an
array of indexes of the `true` elements. If there are no non-zero elements of `A`,
`find` returns an empty array.

```jldoctest
julia> A = [true false; false true]
Expand All @@ -1319,15 +1325,15 @@ function find(A)
count = 1
inds = _index_remapper(A)
for (i,a) in enumerate(A)
if a != 0
if !isequal(a, 0)
I[count] = inds[i]
count += 1
end
end
return I
end

find(x::Number) = x == 0 ? Array{Int,1}(0) : [1]
find(x::Number) = isequal(x, 0) ? Array{Int,1}(0) : [1]
find(testf::Function, x::Number) = !testf(x) ? Array{Int,1}(0) : [1]

findn(A::AbstractVector) = find(A)
Expand All @@ -1336,7 +1342,7 @@ findn(A::AbstractVector) = find(A)
findn(A)

Return a vector of indexes for each dimension giving the locations of the non-zeros in `A`
(determined by `A[i]!=0`).
(determined by `isequal(A[i], 0)`).
If there are no non-zero elements of `A`, `findn` returns a 2-tuple of empty arrays.

```jldoctest
Expand Down Expand Up @@ -1364,7 +1370,7 @@ function findn(A::AbstractMatrix)
J = similar(A, Int, nnzA)
count = 1
for j=indices(A,2), i=indices(A,1)
if A[i,j] != 0
if !isequal(A[i,j], 0)
I[count] = i
J[count] = j
count += 1
Expand All @@ -1377,7 +1383,7 @@ end
findnz(A)

Return a tuple `(I, J, V)` where `I` and `J` are the row and column indexes of the non-zero
values in matrix `A`, and `V` is a vector of the non-zero values.
values in matrix `A` (according to `isequal`), and `V` is a vector of the non-zero values.

```jldoctest
julia> A = [1 2 0; 0 0 3; 0 4 0]
Expand All @@ -1399,7 +1405,7 @@ function findnz{T}(A::AbstractMatrix{T})
if nnzA > 0
for j=indices(A,2), i=indices(A,1)
Aij = A[i,j]
if Aij != 0
if !isequal(Aij, 0)
I[count] = i
J[count] = j
NZs[count] = Aij
Expand Down
2 changes: 1 addition & 1 deletion base/asyncmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type AsyncCollector
end

function AsyncCollector(f, results, c...; ntasks=0)
if ntasks == 0
if isa(ntasks, Integer) && ntasks == 0
ntasks = max(nworkers(), 100)
max_tasks = ()->ntasks
elseif isa(ntasks, Integer)
Expand Down
18 changes: 9 additions & 9 deletions base/cartesian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ end

# Simplify expressions like :(d->3:size(A,d)-3) given an explicit value for d
function inlineanonymous(ex::Expr, val)
if ex.head != :->
if ex.head !== :->
throw(ArgumentError("not an anonymous function"))
end
if !isa(ex.args[1], Symbol)
Expand Down Expand Up @@ -320,7 +320,7 @@ end

function lreplace!(ex::Expr, r::LReplace)
# Curly-brace notation, which acts like parentheses
if ex.head == :curly && length(ex.args) == 2 && isa(ex.args[1], Symbol) && endswith(string(ex.args[1]), "_")
if ex.head === :curly && length(ex.args) == 2 && isa(ex.args[1], Symbol) && endswith(string(ex.args[1]), "_")
excurly = exprresolve(lreplace!(ex.args[2], r))
if isa(excurly, Number)
return Symbol(ex.args[1],excurly)
Expand All @@ -340,12 +340,12 @@ lreplace!(arg, r::LReplace) = arg

poplinenum(arg) = arg
function poplinenum(ex::Expr)
if ex.head == :block
if ex.head === :block
if length(ex.args) == 1
return ex.args[1]
elseif length(ex.args) == 2 && isa(ex.args[1], LineNumberNode)
return ex.args[2]
elseif (length(ex.args) == 2 && isa(ex.args[1], Expr) && ex.args[1].head == :line)
elseif (length(ex.args) == 2 && isa(ex.args[1], Expr) && ex.args[1].head === :line)
return ex.args[2]
end
end
Expand All @@ -360,7 +360,7 @@ const exprresolve_cond_dict = Dict{Symbol,Function}(:(==) => ==,
:(<) => <, :(>) => >, :(<=) => <=, :(>=) => >=)

function exprresolve_arith(ex::Expr)
if ex.head == :call && haskey(exprresolve_arith_dict, ex.args[1]) && all([isa(ex.args[i], Number) for i = 2:length(ex.args)])
if ex.head === :call && haskey(exprresolve_arith_dict, ex.args[1]) && all([isa(ex.args[i], Number) for i = 2:length(ex.args)])
return true, exprresolve_arith_dict[ex.args[1]](ex.args[2:end]...)
end
false, 0
Expand All @@ -369,7 +369,7 @@ exprresolve_arith(arg) = false, 0

exprresolve_conditional(b::Bool) = true, b
function exprresolve_conditional(ex::Expr)
if ex.head == :call && ex.args[1] ∈ keys(exprresolve_cond_dict) && isa(ex.args[2], Number) && isa(ex.args[3], Number)
if ex.head === :call && ex.args[1] ∈ keys(exprresolve_cond_dict) && isa(ex.args[2], Number) && isa(ex.args[3], Number)
return true, exprresolve_cond_dict[ex.args[1]](ex.args[2], ex.args[3])
end
false, false
Expand All @@ -385,12 +385,12 @@ 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
elseif ex.head === :call && (ex.args[1] === :+ || ex.args[1] === :-) && length(ex.args) == 3 && ex.args[3] === 0
# simplify x+0 and x-0
return ex.args[2]
end
# Resolve array references
if ex.head == :ref && isa(ex.args[1], Array)
if ex.head === :ref && isa(ex.args[1], Array)
for i = 2:length(ex.args)
if !isa(ex.args[i], Real)
return ex
Expand All @@ -399,7 +399,7 @@ function exprresolve(ex::Expr)
return ex.args[1][ex.args[2:end]...]
end
# Resolve conditionals
if ex.head == :if
if ex.head === :if
can_eval, tf = exprresolve_conditional(ex.args[1])
if can_eval
ex = tf?ex.args[2]:ex.args[3]
Expand Down
2 changes: 1 addition & 1 deletion base/char.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ start(c::Char) = false
next(c::Char, state) = (c, true)
done(c::Char, state) = state
isempty(c::Char) = false
in(x::Char, y::Char) = x == y
in(x::Char, y::Char) = isequal(x, y)

==(x::Char, y::Char) = UInt32(x) == UInt32(y)
isless(x::Char, y::Char) = UInt32(x) < UInt32(y)
Expand Down
2 changes: 1 addition & 1 deletion base/dates/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Base.steprem{T<:TimeType}(a::T,b::T,c) = b - (a + c*len(a,b,c))
import Base.in
function in{T<:TimeType}(x::T, r::StepRange{T})
n = len(first(r),x,step(r)) + 1
n >= 1 && n <= length(r) && r[n] == x
n >= 1 && n <= length(r) && isequal(r[n], x)
end

Base.start{T<:TimeType}(r::StepRange{T}) = 0
Expand Down
8 changes: 4 additions & 4 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ ImmutableDict{K,V}(t::ImmutableDict{K,V}, KV::Pair) = ImmutableDict{K,V}(t, KV[1
function in(key_value::Pair, dict::ImmutableDict, valcmp=(==))
key, value = key_value
while isdefined(dict, :parent)
if dict.key == key
if isequal(dict.key, key)
valcmp(value, dict.value) && return true
end
dict = dict.parent
Expand All @@ -965,22 +965,22 @@ end

function haskey(dict::ImmutableDict, key)
while isdefined(dict, :parent)
dict.key == key && return true
isequal(dict.key, key) && return true
dict = dict.parent
end
return false
end

function getindex(dict::ImmutableDict, key)
while isdefined(dict, :parent)
dict.key == key && return dict.value
isequal(dict.key, key)&& return dict.value
dict = dict.parent
end
throw(KeyError(key))
end
function get(dict::ImmutableDict, key, default)
while isdefined(dict, :parent)
dict.key == key && return dict.value
isequal(dict.key, key) && return dict.value
dict = dict.parent
end
return default
Expand Down
2 changes: 1 addition & 1 deletion base/libgit2/index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function Base.find(path::String, idx::GitIndex)
pos_ref = Ref{Csize_t}(0)
ret = ccall((:git_index_find, :libgit2), Cint,
(Ref{Csize_t}, Ptr{Void}, Cstring), pos_ref, idx.ptr, path)
ret == Error.ENOTFOUND && return Nullable{Csize_t}()
ret == Cint(Error.ENOTFOUND) && return Nullable{Csize_t}()
return Nullable(pos_ref[]+1)
end

Expand Down
6 changes: 3 additions & 3 deletions base/libgit2/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,9 @@ function transact(f::Function, repo::GitRepo)
end

function set_ssl_cert_locations(cert_loc)
cert_file = isfile(cert_loc) ? cert_loc : Cstring(C_NULL)
cert_dir = isdir(cert_loc) ? cert_loc : Cstring(C_NULL)
cert_file == C_NULL && cert_dir == C_NULL && return
cert_file = isfile(cert_loc) ? cert_loc : C_NULL
cert_dir = isdir(cert_loc) ? cert_loc : C_NULL
cert_file === C_NULL && cert_dir === C_NULL && return
ccall((:git_libgit2_opts, :libgit2), Cint,
(Cint, Cstring, Cstring),
Cint(Consts.SET_SSL_CERT_LOCATIONS), cert_file, cert_dir)
Expand Down
2 changes: 1 addition & 1 deletion base/libgit2/rebase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function Base.next(rb::GitRebase)
(Ptr{Ptr{RebaseOperation}}, Ptr{Void}),
rb_op_ptr_ptr, rb.ptr)
catch err
err.code == Error.ITEROVER && return nothing
err.code == Cint(Error.ITEROVER) && return nothing
rethrow(err)
end
return unsafe_load(convert(Ptr{RebaseOperation}, rb_op_ptr_ptr[]), 1)
Expand Down
2 changes: 1 addition & 1 deletion base/markdown/parse/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function readuntil(stream::IO, delimiter; newlines = false, match = nothing)
end
end
char = read(stream, Char)
char == match && (count += 1)
isequal(char, match) && (count += 1)
!newlines && char == '\n' && break
write(buffer, char)
end
Expand Down
Loading