Skip to content

Commit

Permalink
use === for comparison to nothing and Symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Nov 4, 2019
1 parent d5d4c69 commit 2497695
Show file tree
Hide file tree
Showing 70 changed files with 295 additions and 295 deletions.
6 changes: 3 additions & 3 deletions base/Enums.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ macro enum(T, syms...)
end
basetype = Int32
typename = T
if isa(T, Expr) && T.head == :(::) && length(T.args) == 2 && isa(T.args[1], Symbol)
if isa(T, Expr) && T.head === :(::) && length(T.args) == 2 && isa(T.args[1], Symbol)
typename = T.args[1]
basetype = Core.eval(__module__, T.args[2])
if !isa(basetype, DataType) || !(basetype <: Integer) || !isbitstype(basetype)
Expand All @@ -137,7 +137,7 @@ macro enum(T, syms...)
i = zero(basetype)
hasexpr = false

if length(syms) == 1 && syms[1] isa Expr && syms[1].head == :block
if length(syms) == 1 && syms[1] isa Expr && syms[1].head === :block
syms = syms[1].args
end
for s in syms
Expand All @@ -147,7 +147,7 @@ macro enum(T, syms...)
throw(ArgumentError("overflow in value \"$s\" of Enum $typename"))
end
elseif isa(s, Expr) &&
(s.head == :(=) || s.head == :kw) &&
(s.head === :(=) || s.head === :kw) &&
length(s.args) == 2 && isa(s.args[1], Symbol)
i = Core.eval(__module__, s.args[2]) # allow exprs, e.g. uint128"1"
if !isa(i, Integer)
Expand Down
4 changes: 2 additions & 2 deletions base/arraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ function +(A::Array, Bs::Array...)
end

for f in (:/, :\, :*)
if f != :/
if f !== :/
@eval ($f)(A::Number, B::AbstractArray) = broadcast_preserving_zero_d($f, A, B)
end
if f != :\
if f !== :\
@eval ($f)(A::AbstractArray, B::Number) = broadcast_preserving_zero_d($f, A, B)
end
end
Expand Down
2 changes: 1 addition & 1 deletion base/atomics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ for typ in atomictypes
ret $lt %rv
""", $typ, Tuple{Ptr{$typ}, $typ}, unsafe_convert(Ptr{$typ}, x), v)
else
rmwop == :xchg || continue
rmwop === :xchg || continue
@eval $fn(x::Atomic{$typ}, v::$typ) =
llvmcall($"""
%iptr = inttoptr i$WORD_SIZE %0 to $ilt*
Expand Down
20 changes: 10 additions & 10 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1144,12 +1144,12 @@ Base.@propagate_inbounds dotview(args...) = Base.maybeview(args...)
dottable(x) = false # avoid dotting spliced objects (e.g. view calls inserted by @view)
# don't add dots to dot operators
dottable(x::Symbol) = (!isoperator(x) || first(string(x)) != '.' || x === :..) && x !== :(:)
dottable(x::Expr) = x.head != :$
dottable(x::Expr) = x.head !== :$
undot(x) = x
function undot(x::Expr)
if x.head == :.=
if x.head === :.=
Expr(:(=), x.args...)
elseif x.head == :block # occurs in for x=..., y=...
elseif x.head === :block # occurs in for x=..., y=...
Expr(:block, map(undot, x.args)...)
else
x
Expand All @@ -1158,22 +1158,22 @@ end
__dot__(x) = x
function __dot__(x::Expr)
dotargs = map(__dot__, x.args)
if x.head == :call && dottable(x.args[1])
if x.head === :call && dottable(x.args[1])
Expr(:., dotargs[1], Expr(:tuple, dotargs[2:end]...))
elseif x.head == :comparison
elseif x.head === :comparison
Expr(:comparison, (iseven(i) && dottable(arg) && arg isa Symbol && isoperator(arg) ?
Symbol('.', arg) : arg for (i, arg) in pairs(dotargs))...)
elseif x.head == :$
elseif x.head === :$
x.args[1]
elseif x.head == :let # don't add dots to `let x=...` assignments
elseif x.head === :let # don't add dots to `let x=...` assignments
Expr(:let, undot(dotargs[1]), dotargs[2])
elseif x.head == :for # don't add dots to for x=... assignments
elseif x.head === :for # don't add dots to for x=... assignments
Expr(:for, undot(dotargs[1]), dotargs[2])
elseif (x.head == :(=) || x.head == :function || x.head == :macro) &&
elseif (x.head === :(=) || x.head === :function || x.head === :macro) &&
Meta.isexpr(x.args[1], :call) # function or macro definition
Expr(x.head, x.args[1], dotargs[2])
else
if x.head == :&& || x.head == :||
if x.head === :&& || x.head === :||
error("""
Using `&&` and `||` is disallowed in `@.` expressions.
Use `&` or `|` for elementwise logical operations.
Expand Down
24 changes: 12 additions & 12 deletions base/cartesian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function _nloops(N::Int, itersym::Symbol, arraysym::Symbol, args::Expr...)
end

function _nloops(N::Int, itersym::Symbol, rangeexpr::Expr, args::Expr...)
if rangeexpr.head != :->
if rangeexpr.head !== :->
throw(ArgumentError("second argument must be an anonymous function expression to compute the range"))
end
if !(1 <= length(args) <= 3)
Expand Down Expand Up @@ -167,7 +167,7 @@ evaluate to `true`.
can be convenient for bounds-checking.
"""
macro nall(N::Int, criterion::Expr)
if criterion.head != :->
if criterion.head !== :->
throw(ArgumentError("second argument must be an anonymous function expression yielding the criterion"))
end
conds = Any[ Expr(:escape, inlineanonymous(criterion, i)) for i = 1:N ]
Expand All @@ -183,7 +183,7 @@ evaluate to `true`.
`@nany 3 d->(i_d > 1)` would generate the expression `(i_1 > 1 || i_2 > 1 || i_3 > 1)`.
"""
macro nany(N::Int, criterion::Expr)
if criterion.head != :->
if criterion.head !== :->
error("Second argument must be an anonymous function expression yielding the criterion")
end
conds = Any[ Expr(:escape, inlineanonymous(criterion, i)) for i = 1:N ]
Expand Down Expand Up @@ -233,7 +233,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 @@ -313,7 +313,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 @@ -333,12 +333,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 @@ -353,7 +353,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 @@ -362,7 +362,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 @@ -378,12 +378,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 @@ -392,7 +392,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
6 changes: 3 additions & 3 deletions base/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mutable struct Channel{T} <: AbstractChannel{T}
cond_wait::Threads.Condition # waiting for data to become maybe available
cond_put::Threads.Condition # waiting for a writeable slot
state::Symbol
excp::Union{Exception, Nothing} # exception to be thrown when state != :open
excp::Union{Exception, Nothing} # exception to be thrown when state !== :open

data::Vector{T}
sz_max::Int # maximum size of channel
Expand Down Expand Up @@ -189,7 +189,7 @@ function close(c::Channel, excp::Exception=closed_exception())
end
nothing
end
isopen(c::Channel) = (c.state == :open)
isopen(c::Channel) = (c.state === :open)

"""
bind(chnl::Channel, task::Task)
Expand Down Expand Up @@ -459,7 +459,7 @@ function iterate(c::Channel, state=nothing)
try
return (take!(c), nothing)
catch e
if isa(e, InvalidStateException) && e.state == :closed
if isa(e, InvalidStateException) && e.state === :closed
return nothing
else
rethrow()
Expand Down
2 changes: 1 addition & 1 deletion base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function scrub_repl_backtrace(bt)
if bt !== nothing && !(bt isa Vector{Any}) # ignore our sentinel value types
bt = stacktrace(bt)
# remove REPL-related frames from interactive printing
eval_ind = findlast(frame -> !frame.from_c && frame.func == :eval, bt)
eval_ind = findlast(frame -> !frame.from_c && frame.func === :eval, bt)
eval_ind === nothing || deleteat!(bt, eval_ind:length(bt))
end
return bt
Expand Down
4 changes: 2 additions & 2 deletions base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function stmt_affects_purity(@nospecialize(stmt), ir)
return !(t Bool)
end
if isa(stmt, Expr)
return stmt.head != :loopinfo && stmt.head != :enter
return stmt.head !== :loopinfo && stmt.head !== :enter
end
return true
end
Expand All @@ -167,7 +167,7 @@ function optimize(opt::OptimizationState, @nospecialize(result))
def = opt.linfo.def
nargs = Int(opt.nargs) - 1
@timeit "optimizer" ir = run_passes(opt.src, nargs, opt)
force_noinline = _any(@nospecialize(x) -> isexpr(x, :meta) && x.args[1] == :noinline, ir.meta)
force_noinline = _any(@nospecialize(x) -> isexpr(x, :meta) && x.args[1] === :noinline, ir.meta)

# compute inlining and other related optimizations
if (isa(result, Const) || isconstType(result))
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/ssair/driver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ end

function normalize(@nospecialize(stmt), meta::Vector{Any})
if isa(stmt, Expr)
if stmt.head == :meta
if stmt.head === :meta
args = stmt.args
if length(args) > 0
push!(meta, stmt)
Expand Down
4 changes: 2 additions & 2 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
end
elseif isa(stmt′, GotoNode)
stmt′ = GotoNode(stmt′.label + bb_offset)
elseif isa(stmt′, Expr) && stmt′.head == :enter
elseif isa(stmt′, Expr) && stmt′.head === :enter
stmt′ = Expr(:enter, stmt′.args[1] + bb_offset)
elseif isa(stmt′, GotoIfNot)
stmt′ = GotoIfNot(stmt′.cond, stmt′.dest + bb_offset)
Expand Down Expand Up @@ -560,7 +560,7 @@ function batch_inline!(todo::Vector{Any}, ir::IRCode, linetable::Vector{LineInfo
end
elseif isa(stmt, GotoNode)
compact[idx] = GotoNode(state.bb_rename[stmt.label])
elseif isa(stmt, Expr) && stmt.head == :enter
elseif isa(stmt, Expr) && stmt.head === :enter
compact[idx] = Expr(:enter, state.bb_rename[stmt.args[1]])
elseif isa(stmt, GotoIfNot)
compact[idx] = GotoIfNot(stmt.cond, state.bb_rename[stmt.dest])
Expand Down
6 changes: 3 additions & 3 deletions base/compiler/ssair/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function basic_blocks_starts(stmts::Vector{Any})
if stmt.head === :leave
# :leave terminates a BB
push!(jump_dests, idx+1)
elseif stmt.head == :enter
elseif stmt.head === :enter
# :enter starts/ends a BB
push!(jump_dests, idx)
push!(jump_dests, idx+1)
Expand Down Expand Up @@ -151,7 +151,7 @@ function compute_basic_blocks(stmts::Vector{Any})
push!(b.succs, block′)
end
elseif isa(terminator, Expr)
if terminator.head == :enter
if terminator.head === :enter
# :enter gets a virtual edge to the exception handler and
# the exception handler gets a virtual edge from outside
# the function.
Expand All @@ -162,7 +162,7 @@ function compute_basic_blocks(stmts::Vector{Any})
push!(blocks[block′].preds, num)
push!(blocks[block′].preds, 0)
push!(b.succs, block′)
elseif terminator.head == :gotoifnot
elseif terminator.head === :gotoifnot
block′ = block_for_inst(basic_block_index, terminator.args[2]::Int)
if block′ == num + 1
# This GotoIfNot acts like a noop - treat it as such.
Expand Down
4 changes: 2 additions & 2 deletions base/compiler/ssair/legacy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function inflate_ir(ci::CodeInfo, sptypes::Vector{Any}, argtypes::Vector{Any})
code[i] = GotoIfNot(stmt.cond, block_for_inst(cfg, stmt.dest))
elseif isa(stmt, PhiNode)
code[i] = PhiNode(Any[block_for_inst(cfg, edge) for edge in stmt.edges], stmt.values)
elseif isa(stmt, Expr) && stmt.head == :enter
elseif isa(stmt, Expr) && stmt.head === :enter
stmt.args[1] = block_for_inst(cfg, stmt.args[1])
code[i] = stmt
else
Expand Down Expand Up @@ -87,7 +87,7 @@ function replace_code_newstyle!(ci::CodeInfo, ir::IRCode, nargs::Int)
else
ci.code[i] = Expr(:unreachable)
end
elseif isa(stmt, Expr) && stmt.head == :enter
elseif isa(stmt, Expr) && stmt.head === :enter
stmt.args[1] = first(ir.cfg.blocks[stmt.args[1]].stmts)
ci.code[i] = stmt
else
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ function getfield_elim_pass!(ir::IRCode, domtree::DomTree)
(isa(c1, Const) && isa(c2, Const)) && continue
lift_comparison!(compact, idx, c1, c2, stmt, lifting_cache)
continue
elseif isexpr(stmt, :call) && stmt.args[1] == :unchecked_getfield
elseif isexpr(stmt, :call) && stmt.args[1] === :unchecked_getfield
is_getfield = true
is_unchecked = true
elseif isexpr(stmt, :foreigncall)
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/ssair/slot2ssa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ function domsort_ssa!(ir::IRCode, domtree::DomTree)
end
result_stmts[inst_range[end]] = GotoIfNot(terminator.cond, bb_rename[terminator.dest])
elseif !isa(terminator, ReturnNode)
if isa(terminator, Expr) && terminator.head == :enter
if isa(terminator, Expr) && terminator.head === :enter
terminator.args[1] = bb_rename[terminator.args[1]]
end
if bb_rename[bb + 1] != new_bb + 1
Expand Down
4 changes: 2 additions & 2 deletions base/compiler/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ function validate_code!(errors::Vector{>:InvalidCodeError}, c::CodeInfo, is_top_
push!(errors, InvalidCodeError(INVALID_RETURN, x.args[1]))
end
validate_val!(x.args[1])
elseif head === :call || head === :invoke || head == :gc_preserve_end || head === :meta ||
elseif head === :call || head === :invoke || head === :gc_preserve_end || head === :meta ||
head === :inbounds || head === :foreigncall || head === :cfunction ||
head === :const || head === :enter || head === :leave || head == :pop_exception ||
head === :const || head === :enter || head === :leave || head === :pop_exception ||
head === :method || head === :global || head === :static_parameter ||
head === :new || head === :splatnew || head === :thunk || head === :loopinfo ||
head === :throw_undef_if_not || head === :unreachable
Expand Down
8 changes: 4 additions & 4 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ macro deprecate(old, new, ex=true)
depwarn($"`$old` is deprecated, use `$new` instead.", Core.Typeof($(esc(old))).name.mt.name)
$(esc(new))(args...)
end))
elseif isa(old, Expr) && (old.head == :call || old.head == :where)
elseif isa(old, Expr) && (old.head === :call || old.head === :where)
remove_linenums!(new)
oldcall = sprint(show_unquoted, old)
newcall = sprint(show_unquoted, new)
# if old.head is a :where, step down one level to the :call to avoid code duplication below
callexpr = old.head == :call ? old : old.args[1]
if callexpr.head == :call
callexpr = old.head === :call ? old : old.args[1]
if callexpr.head === :call
if isa(callexpr.args[1], Symbol)
oldsym = callexpr.args[1]::Symbol
elseif isa(callexpr.args[1], Expr) && callexpr.args[1].head == :curly
elseif isa(callexpr.args[1], Expr) && callexpr.args[1].head === :curly
oldsym = callexpr.args[1].args[1]::Symbol
else
error("invalid usage of @deprecate")
Expand Down
2 changes: 1 addition & 1 deletion base/fastmath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const rewrite_op =
function make_fastmath(expr::Expr)
if expr.head === :quote
return expr
elseif expr.head == :call && expr.args[1] == :^ && expr.args[3] isa Integer
elseif expr.head === :call && expr.args[1] === :^ && expr.args[3] isa Integer
# mimic Julia's literal_pow lowering of literal integer powers
return Expr(:call, :(Base.FastMath.pow_fast), make_fastmath(expr.args[2]), Val{expr.args[3]}())
end
Expand Down
2 changes: 1 addition & 1 deletion base/floatfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ fma_llvm(x::Float64, y::Float64, z::Float64) = fma_float(x, y, z)
# 1.0000000009313226 = 1 + 1/2^30
# If fma_llvm() clobbers the rounding mode, the result of 0.1 + 0.2 will be 0.3
# instead of the properly-rounded 0.30000000000000004; check after calling fma
if (Sys.ARCH != :i686 && fma_llvm(1.0000305f0, 1.0000305f0, -1.0f0) == 6.103609f-5 &&
if (Sys.ARCH !== :i686 && fma_llvm(1.0000305f0, 1.0000305f0, -1.0f0) == 6.103609f-5 &&
(fma_llvm(1.0000000009313226, 1.0000000009313226, -1.0) ==
1.8626451500983188e-9) && 0.1 + 0.2 == 0.30000000000000004)
fma(x::Float32, y::Float32, z::Float32) = fma_llvm(x,y,z)
Expand Down
Loading

0 comments on commit 2497695

Please sign in to comment.