Skip to content

Commit 46813d3

Browse files
authored
optimize Core.Compiler a bit (#49227)
1 parent ff9435c commit 46813d3

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,7 @@ end
20232023
function abstract_call_opaque_closure(interp::AbstractInterpreter,
20242024
closure::PartialOpaque, arginfo::ArgInfo, si::StmtInfo, sv::InferenceState, check::Bool=true)
20252025
sig = argtypes_to_type(arginfo.argtypes)
2026-
result = abstract_call_method(interp, closure.source, sig, Core.svec(), false, si, sv)
2026+
result = abstract_call_method(interp, closure.source::Method, sig, Core.svec(), false, si, sv)
20272027
(; rt, edge, effects) = result
20282028
tt = closure.typ
20292029
sigT = (unwrap_unionall(tt)::DataType).parameters[1]
@@ -2276,7 +2276,9 @@ function abstract_eval_statement_expr(interp::AbstractInterpreter, e::Expr, vtyp
22762276
ismutable = ismutabletype(ut)
22772277
fcount = datatype_fieldcount(ut)
22782278
nargs = length(e.args) - 1
2279-
if fcount === nothing || (fcount > nargs && any(i::Int -> !is_undefref_fieldtype(fieldtype(t, i)), (nargs+1):fcount))
2279+
if (fcount === nothing || (fcount > nargs && (let t = t
2280+
any(i::Int -> !is_undefref_fieldtype(fieldtype(t, i)), (nargs+1):fcount)
2281+
end)))
22802282
# allocation with undefined field leads to undefined behavior and should taint `:consistent`-cy
22812283
consistent = ALWAYS_FALSE
22822284
elseif ismutable
@@ -2335,12 +2337,16 @@ function abstract_eval_statement_expr(interp::AbstractInterpreter, e::Expr, vtyp
23352337
if length(e.args) == 2 && isconcretedispatch(t) && !ismutabletype(t)
23362338
at = abstract_eval_value(interp, e.args[2], vtypes, sv)
23372339
n = fieldcount(t)
2338-
if isa(at, Const) && isa(at.val, Tuple) && n == length(at.val::Tuple) &&
2339-
let t = t, at = at; all(i::Int->getfield(at.val::Tuple, i) isa fieldtype(t, i), 1:n); end
2340+
if (isa(at, Const) && isa(at.val, Tuple) && n == length(at.val::Tuple) &&
2341+
(let t = t, at = at
2342+
all(i::Int->getfield(at.val::Tuple, i) isa fieldtype(t, i), 1:n)
2343+
end))
23402344
nothrow = isexact
23412345
t = Const(ccall(:jl_new_structt, Any, (Any, Any), t, at.val))
2342-
elseif isa(at, PartialStruct) && at ᵢ Tuple && n == length(at.fields::Vector{Any}) &&
2343-
let t = t, at = at; all(i::Int->(at.fields::Vector{Any})[i] fieldtype(t, i), 1:n); end
2346+
elseif (isa(at, PartialStruct) && at ᵢ Tuple && n == length(at.fields::Vector{Any}) &&
2347+
(let t = t, at = at, =
2348+
all(i::Int->(at.fields::Vector{Any})[i] fieldtype(t, i), 1:n)
2349+
end))
23442350
nothrow = isexact
23452351
t = PartialStruct(t, at.fields::Vector{Any})
23462352
end

base/compiler/ssair/ir.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ end
687687
function getindex(compact::IncrementalCompact, ssa::OldSSAValue)
688688
id = ssa.id
689689
if id < compact.idx
690-
new_idx = compact.ssa_rename[id]
690+
new_idx = compact.ssa_rename[id]::Int
691691
return compact.result[new_idx]
692692
elseif id <= length(compact.ir.stmts)
693693
return compact.ir.stmts[id]
@@ -721,7 +721,7 @@ end
721721
function block_for_inst(compact::IncrementalCompact, idx::OldSSAValue)
722722
id = idx.id
723723
if id < compact.idx # if ssa within result
724-
id = compact.ssa_rename[id]
724+
id = compact.ssa_rename[id]::Int
725725
return block_for_inst(compact, SSAValue(id))
726726
else
727727
return block_for_inst(compact.ir.cfg, id)
@@ -962,7 +962,7 @@ end
962962
function setindex!(compact::IncrementalCompact, @nospecialize(v), idx::OldSSAValue)
963963
id = idx.id
964964
if id < compact.idx
965-
new_idx = compact.ssa_rename[id]
965+
new_idx = compact.ssa_rename[id]::Int
966966
(compact.result[new_idx][:inst] === v) && return compact
967967
kill_current_uses!(compact, compact.result[new_idx][:inst])
968968
compact.result[new_idx][:inst] = v

base/compiler/stmtinfo.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,26 @@ nsplit_impl(info::UnionSplitInfo) = length(info.matches)
5656
getsplit_impl(info::UnionSplitInfo, idx::Int) = getsplit_impl(info.matches[idx], 1)
5757
getresult_impl(::UnionSplitInfo, ::Int) = nothing
5858

59-
struct ConstPropResult
59+
abstract type ConstResult end
60+
61+
struct ConstPropResult <: ConstResult
6062
result::InferenceResult
6163
end
6264

63-
struct ConcreteResult
65+
struct ConcreteResult <: ConstResult
6466
mi::MethodInstance
6567
effects::Effects
6668
result
6769
ConcreteResult(mi::MethodInstance, effects::Effects) = new(mi, effects)
6870
ConcreteResult(mi::MethodInstance, effects::Effects, @nospecialize val) = new(mi, effects, val)
6971
end
7072

71-
struct SemiConcreteResult
73+
struct SemiConcreteResult <: ConstResult
7274
mi::MethodInstance
7375
ir::IRCode
7476
effects::Effects
7577
end
7678

77-
const ConstResult = Union{ConstPropResult, ConcreteResult, SemiConcreteResult}
78-
7979
"""
8080
info::ConstCallInfo <: CallInfo
8181

base/compiler/tfuncs.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,12 +1793,12 @@ const _tvarnames = Symbol[:_A, :_B, :_C, :_D, :_E, :_F, :_G, :_H, :_I, :_J, :_K,
17931793
if i == largs && ub === Any
17941794
push!(tparams, Vararg)
17951795
elseif isT
1796-
push!(tparams, rewrap_unionall(unw.parameters[1], ai))
1796+
push!(tparams, rewrap_unionall((unw::DataType).parameters[1], ai))
17971797
else
17981798
push!(tparams, Any)
17991799
end
18001800
elseif isT
1801-
push!(tparams, unw.parameters[1])
1801+
push!(tparams, (unw::DataType).parameters[1])
18021802
while isa(ai, UnionAll)
18031803
push!(outervars, ai.var)
18041804
ai = ai.body
@@ -2633,7 +2633,7 @@ function abstract_applicable(interp::AbstractInterpreter, argtypes::Vector{Any},
26332633
rt = Const(true) # has applicable matches
26342634
for i in 1:napplicable
26352635
match = applicable[i]::MethodMatch
2636-
edge = specialize_method(match)
2636+
edge = specialize_method(match)::MethodInstance
26372637
add_backedge!(sv, edge)
26382638
end
26392639

@@ -2681,7 +2681,7 @@ function _hasmethod_tfunc(interp::AbstractInterpreter, argtypes::Vector{Any}, sv
26812681
add_mt_backedge!(sv, mt, types) # this should actually be an invoke-type backedge
26822682
else
26832683
rt = Const(true)
2684-
edge = specialize_method(match)
2684+
edge = specialize_method(match)::MethodInstance
26852685
add_invoke_backedge!(sv, types, edge)
26862686
end
26872687
return CallMeta(rt, EFFECTS_TOTAL, NoCallInfo())

0 commit comments

Comments
 (0)