Skip to content

Commit d711a41

Browse files
committed
attempt some code quality improvements
remove unused type parameters from some functions, add some useful ones to others, and remove the fallback `==` method in Core.Compiler.
1 parent 14cd42d commit d711a41

File tree

16 files changed

+61
-39
lines changed

16 files changed

+61
-39
lines changed

base/Base.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ include("range.jl")
8484
include("error.jl")
8585

8686
# core numeric operations & types
87+
==(x, y) = x === y
8788
include("bool.jl")
8889
include("number.jl")
8990
include("int.jl")

base/array.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ size(a::Array{<:Any,N}) where {N} = (@_inline_meta; ntuple(M -> size(a, M), Val(
158158

159159
asize_from(a::Array, n) = n > ndims(a) ? () : (arraysize(a,n), asize_from(a, n+1)...)
160160

161-
allocatedinline(::Type{T}) where {T} = (@_pure_meta; ccall(:jl_stored_inline, Cint, (Any,), T) != Cint(0))
161+
allocatedinline(T::Type) = (@_pure_meta; ccall(:jl_stored_inline, Cint, (Any,), T) != Cint(0))
162162

163163
"""
164164
Base.isbitsunion(::Type{T})

base/compiler/abstractinterpretation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ function typeinf_local(interp::AbstractInterpreter, frame::InferenceState)
13141314
if isa(fname, Slot)
13151315
changes = StateUpdate(fname, VarState(Any, false), changes)
13161316
end
1317-
elseif hd === :inbounds || hd === :meta || hd === :loopinfo || hd == :code_coverage_effect
1317+
elseif hd === :inbounds || hd === :meta || hd === :loopinfo || hd === :code_coverage_effect
13181318
# these do not generate code
13191319
else
13201320
t = abstract_eval_statement(interp, stmt, changes, frame)

base/compiler/compiler.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ include("expr.jl")
4141
include("error.jl")
4242

4343
# core numeric operations & types
44+
==(x::T, y::T) where {T} = x === y
4445
include("bool.jl")
4546
include("number.jl")
4647
include("int.jl")

base/compiler/inferencestate.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,10 @@ update_valid_age!(edge::InferenceState, sv::InferenceState) = update_valid_age!(
210210
function record_ssa_assign(ssa_id::Int, @nospecialize(new), frame::InferenceState)
211211
old = frame.src.ssavaluetypes[ssa_id]
212212
if old === NOT_FOUND || !(new old)
213-
frame.src.ssavaluetypes[ssa_id] = tmerge(old, new)
213+
# typically, we expect that old ⊑ new (that output information only
214+
# gets less precise with worse input information), but to actually
215+
# guarantee convergence we need to use tmerge here to ensure that is true
216+
frame.src.ssavaluetypes[ssa_id] = old === NOT_FOUND ? new : tmerge(old, new)
214217
W = frame.ip
215218
s = frame.stmt_types
216219
for r in frame.ssavalue_uses[ssa_id]

base/compiler/ssair/inlining.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,9 +839,9 @@ function inline_splatnew!(ir::IRCode, idx::Int)
839839
tup = eargs[2]
840840
tt = argextype(tup, ir, ir.sptypes)
841841
tnf = nfields_tfunc(tt)
842-
# TODO: hoisting this tnf.val == nf.val check into codegen
842+
# TODO: hoisting this tnf.val === nf.val check into codegen
843843
# would enable us to almost always do this transform
844-
if tnf isa Const && tnf.val == nf.val
844+
if tnf isa Const && tnf.val === nf.val
845845
n = tnf.val
846846
new_argexprs = Any[eargs[1]]
847847
for j = 1:n

base/compiler/ssair/passes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ function walk_to_defs(compact::IncrementalCompact, @nospecialize(defssa), @nospe
224224
end
225225
val = new_def
226226
end
227-
if def == val
227+
if def === val
228228
# This shouldn't really ever happen, but
229229
# patterns like this can occur in dead code,
230230
# so bail out.

base/compiler/ssair/slot2ssa.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,13 +692,13 @@ function construct_ssa!(ci::CodeInfo, ir::IRCode, domtree::DomTree, defuse, narg
692692
for (idx, slot) in Iterators.enumerate(phi_slots[item])
693693
ssaval, node = phi_nodes[item][idx]
694694
incoming_val = incoming_vals[slot]
695-
if incoming_val == SSAValue(-1)
695+
if incoming_val === SSAValue(-1)
696696
# Optimistically omit this path.
697697
# Liveness analysis would probably have prevented us from inserting this phi node
698698
continue
699699
end
700700
push!(node.edges, pred)
701-
if incoming_val == undef_token
701+
if incoming_val === undef_token
702702
resize!(node.values, length(node.values)+1)
703703
else
704704
push!(node.values, incoming_val)
@@ -708,7 +708,7 @@ function construct_ssa!(ci::CodeInfo, ir::IRCode, domtree::DomTree, defuse, narg
708708
if isa(incoming_val, NewSSAValue)
709709
push!(type_refine_phi, ssaval.id)
710710
end
711-
typ = incoming_val == undef_token ? MaybeUndef(Union{}) : typ_for_val(incoming_val, ci, sptypes, -1, slottypes)
711+
typ = incoming_val === undef_token ? MaybeUndef(Union{}) : typ_for_val(incoming_val, ci, sptypes, -1, slottypes)
712712
old_entry = new_nodes.stmts[ssaval.id]
713713
if isa(typ, DelayedTyp)
714714
push!(type_refine_phi, ssaval.id)

base/compiler/tfuncs.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ function fieldtype_tfunc(@nospecialize(s0), @nospecialize(name))
894894
if isa(s0, Const) && (!(isa(s0.val, DataType) || isa(s0.val, UnionAll) || isa(s0.val, Union)) || s0.val === Module)
895895
return Bottom
896896
end
897-
if s0 == Type{Module} || s0 == Type{Union{}} || isa(s0, Conditional)
897+
if (s0 isa Type && (s0 == Type{Module} || s0 == Type{Union{}})) || isa(s0, Conditional)
898898
return Bottom
899899
end
900900

@@ -1458,7 +1458,7 @@ function intrinsic_nothrow(f::IntrinsicFunction, argtypes::Array{Any, 1})
14581458
end
14591459
# The remaining intrinsics are math/bits/comparison intrinsics. They work on all
14601460
# primitive types of the same type.
1461-
isshift = f == shl_int || f == lshr_int || f == ashr_int
1461+
isshift = f === shl_int || f === lshr_int || f === ashr_int
14621462
argtype1 = widenconst(argtypes[1])
14631463
isprimitivetype(argtype1) || return false
14641464
for i = 2:length(argtypes)

base/compiler/typelattice.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ struct NotFound end
8484

8585
const NOT_FOUND = NotFound()
8686

87+
const CompilerTypes = Union{Type, MaybeUndef, Const, Conditional, NotFound, PartialStruct}
88+
==(x::CompilerTypes, y::CompilerTypes) = x === y
89+
8790
#################
8891
# lattice logic #
8992
#################
@@ -216,7 +219,8 @@ end
216219
widenconst(m::MaybeUndef) = widenconst(m.typ)
217220
widenconst(c::PartialTypeVar) = TypeVar
218221
widenconst(t::PartialStruct) = t.typ
219-
widenconst(@nospecialize(t)) = t
222+
widenconst(t::Type) = t
223+
widenconst(t::TypeVar) = t
220224

221225
issubstate(a::VarState, b::VarState) = (a.typ b.typ && a.undef <= b.undef)
222226

@@ -234,9 +238,9 @@ end
234238

235239
widenconditional(@nospecialize typ) = typ
236240
function widenconditional(typ::Conditional)
237-
if typ.vtype == Union{}
241+
if typ.vtype === Union{}
238242
return Const(false)
239-
elseif typ.elsetype == Union{}
243+
elseif typ.elsetype === Union{}
240244
return Const(true)
241245
else
242246
return Bool

0 commit comments

Comments
 (0)