Skip to content
Open
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
40 changes: 17 additions & 23 deletions Compiler/src/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(fun
arginfo::ArgInfo, si::StmtInfo, @nospecialize(atype),
sv::AbsIntState, max_methods::Int)
𝕃ₚ, 𝕃ᵢ = ipo_lattice(interp), typeinf_lattice(interp)
⊑ₚ, ⋤ₚ, ⊔ₚ, ⊔ᵢ = partialorder(𝕃ₚ), strictneqpartialorder(𝕃ₚ), join(𝕃ₚ), join(𝕃ᵢ)
⊑ₚ, ⊔ₚ, ⊔ᵢ = partialorder(𝕃ₚ), join(𝕃ₚ), join(𝕃ᵢ)
argtypes = arginfo.argtypes
if si.saw_latestworld
add_remark!(interp, sv, "Cannot infer call, because we previously saw :latestworld")
Expand Down Expand Up @@ -309,7 +309,7 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(fun
local napplicable = length(applicable)
local multiple_matches = napplicable > 1
while inferidx[] <= napplicable
(; match, edges, edge_idx) = applicable[inferidx[]]
(; match) = applicable[inferidx[]]
inferidx[] += 1
local method = match.method
local sig = match.spec_types
Expand Down Expand Up @@ -343,7 +343,7 @@ function find_method_matches(interp::AbstractInterpreter, argtypes::Vector{Any},
max_union_splitting::Int = InferenceParams(interp).max_union_splitting,
max_methods::Int = InferenceParams(interp).max_methods)
if is_union_split_eligible(typeinf_lattice(interp), argtypes, max_union_splitting)
return find_union_split_method_matches(interp, argtypes, atype, max_methods)
return find_union_split_method_matches(interp, argtypes, max_methods)
end
return find_simple_method_matches(interp, atype, max_methods)
end
Expand All @@ -353,7 +353,7 @@ is_union_split_eligible(𝕃::AbstractLattice, argtypes::Vector{Any}, max_union_
1 < unionsplitcost(𝕃, argtypes) <= max_union_splitting

function find_union_split_method_matches(interp::AbstractInterpreter, argtypes::Vector{Any},
@nospecialize(atype), max_methods::Int)
max_methods::Int)
split_argtypes = switchtupleunion(typeinf_lattice(interp), argtypes)
infos = MethodMatchInfo[]
applicable = MethodMatchTarget[]
Expand Down Expand Up @@ -994,7 +994,7 @@ function collect_const_args(argtypes::Vector{Any}, start::Int)
end

function concrete_eval_call(interp::AbstractInterpreter,
@nospecialize(f), result::MethodCallResult, arginfo::ArgInfo, sv::AbsIntState,
@nospecialize(f), result::MethodCallResult, arginfo::ArgInfo, ::AbsIntState,
invokecall::Union{InvokeCall,Nothing}=nothing)
args = collect_const_args(arginfo, #=start=#2)
if invokecall !== nothing
Expand All @@ -1006,7 +1006,7 @@ function concrete_eval_call(interp::AbstractInterpreter,
edge = result.edge::CodeInstance
value = try
Core._call_in_world_total(world, f, args...)
catch e
catch
# The evaluation threw. By :consistent-cy, we're guaranteed this would have happened at runtime.
# Howevever, at present, :consistency does not mandate the type of the exception
concrete_result = ConcreteResult(edge, result.effects)
Expand Down Expand Up @@ -1368,7 +1368,6 @@ function const_prop_call(interp::AbstractInterpreter,
inf_result.result = concrete_eval_result.rt
inf_result.ipo_effects = concrete_eval_result.effects
end
typ = inf_result.result
return const_prop_result(inf_result)
end

Expand Down Expand Up @@ -1466,7 +1465,7 @@ function ssa_def_slot(@nospecialize(arg), sv::InferenceState)
end

# No slots in irinterp
ssa_def_slot(@nospecialize(arg), sv::IRInterpretationState) = nothing
ssa_def_slot(@nospecialize(arg), ::IRInterpretationState) = nothing

struct AbstractIterationResult
cti::Vector{Any}
Expand Down Expand Up @@ -2262,7 +2261,7 @@ function abstract_invoke(interp::AbstractInterpreter, arginfo::ArgInfo, si::Stmt
end
else
hasintersect(widenconst(types), Union{Method, CodeInstance}) && return Future(CallMeta(Any, Any, Effects(), NoCallInfo()))
(types, isexact, isconcrete, istype) = instanceof_tfunc(argtype_by_index(argtypes, 3), false)
types, isexact, _, _ = instanceof_tfunc(argtype_by_index(argtypes, 3), false)
isexact || return Future(CallMeta(Any, Any, Effects(), NoCallInfo()))
unwrapped = unwrap_unionall(types)
types === Bottom && return Future(CallMeta(Bottom, Any, EFFECTS_THROWS, NoCallInfo()))
Expand Down Expand Up @@ -2344,7 +2343,7 @@ function abstract_finalizer(interp::AbstractInterpreter, argtypes::Vector{Any},
if length(argtypes) == 3
finalizer_argvec = Any[argtypes[2], argtypes[3]]
call = abstract_call(interp, ArgInfo(nothing, finalizer_argvec), StmtInfo(false, false), sv, #=max_methods=#1)::Future
return Future{CallMeta}(call, interp, sv) do call, interp, sv
return Future{CallMeta}(call, interp, sv) do call, _, _
return CallMeta(Nothing, Any, Effects(), FinalizerInfo(call.info, call.effects))
end
end
Expand All @@ -2369,7 +2368,7 @@ function abstract_throw(interp::AbstractInterpreter, argtypes::Vector{Any}, ::Ab
return Future(CallMeta(Union{}, exct, EFFECTS_THROWS, NoCallInfo()))
end

function abstract_throw_methoderror(interp::AbstractInterpreter, argtypes::Vector{Any}, ::AbsIntState)
function abstract_throw_methoderror(::AbstractInterpreter, argtypes::Vector{Any}, ::AbsIntState)
exct = if length(argtypes) == 1
ArgumentError
elseif !isvarargtype(argtypes[2])
Expand Down Expand Up @@ -2579,7 +2578,7 @@ end
function abstract_eval_replaceglobal!(interp::AbstractInterpreter, sv::AbsIntState, saw_latestworld::Bool, argtypes::Vector{Any})
if !isvarargtype(argtypes[end])
if length(argtypes) in (5, 6, 7)
(M, s, x, v) = argtypes[2], argtypes[3], argtypes[4], argtypes[5]
(M, s, v) = argtypes[2], argtypes[3], argtypes[5]
T = nothing
if isa(M, Const) && isa(s, Const)
M, s = M.val, s.val
Expand Down Expand Up @@ -2855,7 +2854,6 @@ function abstract_call_opaque_closure(interp::AbstractInterpreter,
end

function most_general_argtypes(closure::PartialOpaque)
ret = Any[]
cc = widenconst(closure)
argt = (unwrap_unionall(cc)::DataType).parameters[1]
if !isa(argt, DataType) || argt.name !== typename(Tuple)
Expand Down Expand Up @@ -3054,7 +3052,7 @@ function abstract_call(interp::AbstractInterpreter, arginfo::ArgInfo, sstate::St
end
si = StmtInfo(!unused, sstate.saw_latestworld)
call = abstract_call(interp, arginfo, si, sv)::Future
Future{Any}(call, interp, sv) do call, interp, sv
Future{Any}(call, interp, sv) do call, _, sv
# this only is needed for the side-effect, sequenced before any task tries to consume the return value,
# which this will do even without returning this Future
sv.stmt_info[sv.currpc] = call.info
Expand All @@ -3072,7 +3070,7 @@ function abstract_eval_call(interp::AbstractInterpreter, e::Expr, sstate::Statem
end
arginfo = ArgInfo(ea, argtypes)
call = abstract_call(interp, arginfo, sstate, sv)::Future
return Future{RTEffects}(call, interp, sv) do call, interp, sv
return Future{RTEffects}(call, interp, sv) do call, _, _
(; rt, exct, effects, refinements) = call
return RTEffects(rt, exct, effects, refinements)
end
Expand All @@ -3081,7 +3079,7 @@ end
function abstract_eval_new(interp::AbstractInterpreter, e::Expr, sstate::StatementState,
sv::AbsIntState)
𝕃ᵢ = typeinf_lattice(interp)
rt, isexact = instanceof_tfunc(abstract_eval_value(interp, e.args[1], sstate, sv), true)
Copy link
Member

@topolarity topolarity Aug 4, 2025

Choose a reason for hiding this comment

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

Is it worth using a convention that some other languages use and allowing the variable to be unused if it is prefixed with _? (_isexact in this case)

seems a minor shame to lose the info about what this value is just because it is unused, esp. if it becomes used in the future

Copy link
Member

Choose a reason for hiding this comment

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

I'd be OK with this. It doesn't even need to be a real convention, just a JETLS one.

rt, _... = instanceof_tfunc(abstract_eval_value(interp, e.args[1], sstate, sv), true)
ut = unwrap_unionall(rt)
exct = Union{ErrorException,TypeError}
if isa(ut, DataType) && !isabstracttype(ut)
Expand Down Expand Up @@ -3234,7 +3232,7 @@ function abstract_eval_new_opaque_closure(interp::AbstractInterpreter, e::Expr,
pushfirst!(argtypes, rt.env)
callinfo = abstract_call_opaque_closure(interp, rt,
ArgInfo(nothing, argtypes), StmtInfo(true, false), sv, #=check=#false)::Future
Future{Any}(callinfo, interp, sv) do callinfo, interp, sv
Future{Any}(callinfo, interp, sv) do callinfo, _, sv
sv.stmt_info[sv.currpc] = OpaqueClosureCreateInfo(callinfo)
nothing
end
Expand Down Expand Up @@ -3311,7 +3309,7 @@ function abstract_eval_isdefinedglobal(interp::AbstractInterpreter, mod::Module,
end
end

(valid_worlds, rte) = abstract_load_all_consistent_leaf_partitions(interp, gr, sv.world)
(_, rte) = abstract_load_all_consistent_leaf_partitions(interp, gr, sv.world)
if rte.exct == Union{}
rt = Const(true)
elseif rte.rt === Union{} && rte.exct === UndefVarError
Expand Down Expand Up @@ -3554,13 +3552,10 @@ world_range(compact::IncrementalCompact) = world_range(compact.ir)

function abstract_eval_globalref_type(g::GlobalRef, src::Union{CodeInfo, IRCode, IncrementalCompact})
worlds = world_range(src)
partition = lookup_binding_partition(min_world(worlds), g)

(valid_worlds, rte) = abstract_load_all_consistent_leaf_partitions(nothing, g, WorldWithRange(min_world(worlds), worlds))
if min_world(valid_worlds) > min_world(worlds) || max_world(valid_worlds) < max_world(worlds)
return Any
end

return rte.rt
end

Expand Down Expand Up @@ -3677,7 +3672,7 @@ scan_leaf_partitions(query::F, interp::AbstractInterpreter, g::GlobalRef, wwr::W
scan_specified_partitions(query, walk_binding_partition, interp, g, wwr)

function scan_partitions(query::F, interp::AbstractInterpreter, g::GlobalRef, wwr::WorldWithRange) where F
walk_binding_partition = function (b::Core.Binding, partition::Core.BindingPartition, world::UInt)
walk_binding_partition = function (b::Core.Binding, partition::Core.BindingPartition, ::UInt)
Pair{WorldRange, Pair{Core.Binding, Core.BindingPartition}}(
WorldRange(partition.min_world, partition.max_world), b=>partition)
end
Expand Down Expand Up @@ -4436,7 +4431,6 @@ function typeinf(interp::AbstractInterpreter, frame::InferenceState)
nextstates = CurrentState[]
takenext = frame.frameid
minwarn = warnlength
takeprev = 0
while takenext >= frame.frameid
callee = takenext == 0 ? frame : callstack[takenext]::InferenceState
if !isempty(callstack)
Expand Down
1 change: 0 additions & 1 deletion Compiler/src/bootstrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ function bootstrap!()
end
end
starttime = time()
methods = Any[]
world = get_world_counter()
for f in fs
if isa(f, DataType) && f.name === typename(Tuple)
Expand Down
4 changes: 2 additions & 2 deletions Compiler/src/inferenceresult.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

function matching_cache_argtypes(𝕃::AbstractLattice, mi::MethodInstance)
function matching_cache_argtypes(::AbstractLattice, mi::MethodInstance)
(; def, specTypes) = mi
return most_general_argtypes(isa(def, Method) ? def : nothing, specTypes)
end
Expand All @@ -16,7 +16,7 @@ struct WidenedArgtypes
argtypes::Vector{Any}
end

function matching_cache_argtypes(𝕃::AbstractLattice, mi::MethodInstance,
function matching_cache_argtypes(𝕃::AbstractLattice, ::MethodInstance,
simple_argtypes::Union{SimpleArgtypes, WidenedArgtypes},
cache_argtypes::Vector{Any})
(; argtypes) = simple_argtypes
Expand Down
10 changes: 5 additions & 5 deletions Compiler/src/inferencestate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,12 @@ mutable struct InferenceState
ssavalue_uses = find_ssavalue_uses(code, nssavalues)
nstmts = length(code)
edges = []
stmt_info = CallInfo[ NoCallInfo() for i = 1:nstmts ]
stmt_info = CallInfo[ NoCallInfo() for _ = 1:nstmts ]

nslots = length(src.slotflags)
slottypes = Vector{Any}(undef, nslots)
bb_saw_latestworld = Bool[false for i = 1:length(cfg.blocks)]
bb_vartables = Union{Nothing,VarTable}[ nothing for i = 1:length(cfg.blocks) ]
bb_saw_latestworld = Bool[false for _ = 1:length(cfg.blocks)]
bb_vartables = Union{Nothing,VarTable}[ nothing for _ = 1:length(cfg.blocks) ]
bb_vartable1 = bb_vartables[1] = VarTable(undef, nslots)
argtypes = result.argtypes

Expand All @@ -360,7 +360,7 @@ mutable struct InferenceState
slottypes[i] = argtyp
bb_vartable1[i] = VarState(argtyp, i > nargtypes)
end
src.ssavaluetypes = ssavaluetypes = Any[ NOT_FOUND for i = 1:nssavalues ]
src.ssavaluetypes = ssavaluetypes = Any[ NOT_FOUND for _ = 1:nssavalues ]
ssaflags = copy(src.ssaflags)

unreachable = BitSet()
Expand Down Expand Up @@ -549,7 +549,7 @@ function (::ComputeTryCatch{Handler})(code::Vector{Any}, bbs::Union{Vector{Basic
l += 1
end
cur_hand = cur_stacks[1]
for i = 1:l
for _ = 1:l
cur_hand = handler_at[get_enter_idx(handlers[cur_hand])][1]
end
cur_stacks = (cur_hand, cur_stacks[2])
Expand Down
15 changes: 7 additions & 8 deletions Compiler/src/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ is_declared_noinline(@nospecialize src::MaybeCompressed) =
#####################

# return whether this src should be inlined. If so, retrieve_ir_for_inlining must return an IRCode from it
function src_inlining_policy(interp::AbstractInterpreter,
function src_inlining_policy(::AbstractInterpreter,
@nospecialize(src), @nospecialize(info::CallInfo), stmt_flag::UInt32)
isa(src, OptimizationState) && (src = src.src)
if isa(src, MaybeCompressed)
Expand Down Expand Up @@ -227,17 +227,17 @@ function OptimizationState(mi::MethodInstance, src::CodeInfo, interp::AbstractIn
# prepare src for running optimization passes if it isn't already
nssavalues = src.ssavaluetypes
if nssavalues isa Int
src.ssavaluetypes = Any[ Any for i = 1:nssavalues ]
src.ssavaluetypes = Any[ Any for _ = 1:nssavalues ]
else
nssavalues = length(src.ssavaluetypes::Vector{Any})
end
sptypes = sptypes_from_meth_instance(mi)
nslots = length(src.slotflags)
slottypes = src.slottypes
if slottypes === nothing
slottypes = Any[ Any for i = 1:nslots ]
slottypes = Any[ Any for _ = 1:nslots ]
end
stmt_info = CallInfo[ NoCallInfo() for i = 1:nssavalues ]
stmt_info = CallInfo[ NoCallInfo() for _ = 1:nssavalues ]
# cache some useful state computations
def = mi.def
mod = isa(def, Method) ? def.module : def
Expand All @@ -247,7 +247,7 @@ function OptimizationState(mi::MethodInstance, src::CodeInfo, interp::AbstractIn
cfg = compute_basic_blocks(src.code)
unreachable = BitSet()
bb_vartables = Union{VarTable,Nothing}[]
for block = 1:length(cfg.blocks)
for _ = 1:length(cfg.blocks)
push!(bb_vartables, VarState[
VarState(slottypes[slot], src.slotflags[slot] & SLOT_USEDUNDEF != 0)
for slot = 1:nslots
Expand Down Expand Up @@ -543,7 +543,7 @@ abstract_eval_ssavalue(s::SSAValue, src::Union{IRCode,IncrementalCompact}) = typ

Called at the end of optimization to store the resulting IR back into the OptimizationState.
"""
function finishopt!(interp::AbstractInterpreter, opt::OptimizationState, ir::IRCode)
function finishopt!(::AbstractInterpreter, opt::OptimizationState, ir::IRCode)
opt.optresult = OptimizationResult(ir, ccall(:jl_ir_flag_inlining, UInt8, (Any,), opt.src), false)
return nothing
end
Expand Down Expand Up @@ -1002,7 +1002,7 @@ function ipo_dataflow_analysis!(interp::AbstractInterpreter, opt::OptimizationSt
check_inconsistentcy!(sv, scanner)
else
# No longer any dataflow concerns, just scan the flags
scan!(scanner, false) do inst::Instruction, lstmt::Int, bb::Int
scan!(scanner, false) do inst::Instruction, ::Int, ::Int
scan_non_dataflow_flags!(inst, sv)
# bail out early if there are no possibilities to refine the effects
if !any_refinable(sv)
Expand Down Expand Up @@ -1326,7 +1326,6 @@ end

function slot2reg(ir::IRCode, ci::CodeInfo, sv::OptimizationState)
# need `ci` for the slot metadata, IR for the code
svdef = sv.linfo.def
@zone "CC: DOMTREE_1" domtree = construct_domtree(ir)
defuse_insts = scan_slot_def_use(Int(ci.nargs), ci, ir.stmts.stmt)
𝕃ₒ = optimizer_lattice(sv.inlining.interp)
Expand Down
6 changes: 3 additions & 3 deletions Compiler/src/stmtinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function add_one_edge!(edges::Vector{Any}, edge::CodeInstance)
push!(edges, edge)
nothing
end
nsplit_impl(info::MethodMatchInfo) = 1
nsplit_impl(::MethodMatchInfo) = 1
getsplit_impl(info::MethodMatchInfo, idx::Int) = (@assert idx == 1; info.results)
getresult_impl(::MethodMatchInfo, ::Int) = nothing

Expand Down Expand Up @@ -279,7 +279,7 @@ struct InvokeCICallInfo <: CallInfo
end
add_edges_impl(edges::Vector{Any}, info::InvokeCICallInfo) =
add_inlining_edge!(edges, info.edge)
nsplit_impl(info::InvokeCICallInfo) = 0
nsplit_impl(::InvokeCICallInfo) = 0

"""
info::InvokeCallInfo
Expand Down Expand Up @@ -392,7 +392,7 @@ function add_inlining_edge!(edges::Vector{Any}, edge::CodeInstance)
nothing
end

nsplit_impl(info::InvokeCallInfo) = 1
nsplit_impl(::InvokeCallInfo) = 1
getsplit_impl(info::InvokeCallInfo, idx::Int) = (@assert idx == 1; MethodLookupResult(Core.MethodMatch[info.match],
WorldRange(typemin(UInt), typemax(UInt)), false))
getresult_impl(info::InvokeCallInfo, idx::Int) = (@assert idx == 1; info.result)
Expand Down
Loading