Skip to content

Commit 4045157

Browse files
authored
Adjust to stackless compiler changes (#9)
* Adjust to stackless compiler changes Depends on: - JuliaDiff/Diffractor.jl#295 - JuliaLang/julia#55972 * More compiler adjust
1 parent 54c02c1 commit 4045157

File tree

4 files changed

+59
-57
lines changed

4 files changed

+59
-57
lines changed

Manifest.toml

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/analysis/compiler.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,8 @@ end
717717
record_ir!(debug_config, "pre_incidence_propagation", ir)
718718

719719
# TODO better work here?
720-
method_info = CC.MethodInfo(#=propagate_inbounds=#true, nothing)
720+
(nargs, isva) = isa(mi.def, Method) ? (mi.def.nargs, mi.def.isva) : (0, false)
721+
method_info = CC.SpecInfo(nargs, isva, #=propagate_inbounds=#true, nothing)
721722
min_world = world = get_inference_world(interp)
722723
max_world = get_world_counter()
723724
if caller !== nothing
@@ -726,7 +727,7 @@ end
726727
analysis_interp = DAEInterpreter(interp; var_to_diff, var_kind, eq_kind, in_analysis=interp.ipo_analysis_mode)
727728
irsv = CC.IRInterpretationState(analysis_interp, method_info, ir, mi, argtypes,
728729
world, min_world, max_world)
729-
ultimate_rt, _ = CC._ir_abstract_constant_propagation(analysis_interp, irsv; externally_refined)
730+
ultimate_rt, _ = CC.ir_abstract_constant_propagation(analysis_interp, irsv; externally_refined)
730731
record_ir!(debug_config, "incidence_propagation", ir)
731732

732733
# Encountering a `ddt` during abstract interpretation can add variables,
@@ -745,7 +746,7 @@ end
745746
# recalculate domtree (inference could have changed the cfg)
746747
domtree = CC.construct_domtree(ir.cfg.blocks)
747748

748-
# We use the _ir_abstract_constant_propagation pass for three things:
749+
# We use the ir_abstract_constant_propagation pass for three things:
749750
# 1. To establish incidence
750751
# 2. To constant propagate scope information that may not have been
751752
# available at inference time

src/analysis/interpreter.jl

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using .CC: AbstractInterpreter, NativeInterpreter, InferenceParams, Optimization
77
StmtInfo, MethodCallResult, ConstCallResults, ConstPropResult, MethodTableView,
88
CachedMethodTable, InternalMethodTable, OverlayMethodTable, CallMeta, CallInfo,
99
IRCode, LazyDomtree, IRInterpretationState, set_inlineable!, block_for_inst,
10-
BitSetBoundedMinPrioritySet, AbsIntState
10+
BitSetBoundedMinPrioritySet, AbsIntState, Future
1111
using Base: IdSet
1212
using StateSelection: DiffGraph
1313

@@ -282,13 +282,13 @@ widenincidence(@nospecialize(x)) = x
282282
if length(argtypes) == 2
283283
xarg = argtypes[2]
284284
if isa(xarg, Union{Incidence, Const})
285-
return structural_inc_ddt(interp.var_to_diff, interp.var_kind, xarg)
285+
return Future{CallMeta}(structural_inc_ddt(interp.var_to_diff, interp.var_kind, xarg))
286286
end
287287
end
288288
end
289289
if interp.in_analysis && !isa(f, Core.Builtin) && !isa(f, Core.IntrinsicFunction)
290290
# We don't want to do new inference here
291-
return CallMeta(Any, Any, CC.Effects(), CC.NoCallInfo())
291+
return Future{CallMeta}(CallMeta(Any, Any, CC.Effects(), CC.NoCallInfo()))
292292
end
293293
ret = @invoke CC.abstract_call_known(interp::AbstractInterpreter, f::Any,
294294
arginfo::ArgInfo, si::StmtInfo, sv::AbsIntState, max_methods::Int)
@@ -305,27 +305,27 @@ widenincidence(@nospecialize(x)) = x
305305
end
306306
end
307307
arginfo = ArgInfo(arginfo.fargs, map(widenincidence, arginfo.argtypes))
308-
r = Diffractor.fwd_abstract_call_gf_by_type(interp, f, arginfo, si, sv, ret)
309-
r !== nothing && return r
310-
return ret
308+
return Diffractor.fwd_abstract_call_gf_by_type(interp, f, arginfo, si, sv, ret)
311309
end
312310

313311
@override function CC.abstract_call_method(interp::DAEInterpreter,
314312
method::Method, @nospecialize(sig), sparams::SimpleVector, hardlimit::Bool, si::StmtInfo, sv::InferenceState)
315-
ret = @invoke CC.abstract_call_method(interp::AbstractInterpreter,
313+
mret = @invoke CC.abstract_call_method(interp::AbstractInterpreter,
316314
method::Method, sig::Any, sparams::SimpleVector, hardlimit::Bool, si::StmtInfo, sv::InferenceState)
317-
edge = ret.edge
318-
if edge !== nothing
319-
cache = CC.get(CC.code_cache(interp), edge, nothing)
320-
if cache !== nothing
321-
src = @atomic :monotonic cache.inferred
322-
if isa(src, DAECache)
323-
info = src.info
324-
merge_daeinfo!(interp, sv.result, info)
315+
return Future{MethodCallResult}(mret, interp, sv) do ret, interp, sv
316+
edge = ret.edge
317+
if edge !== nothing
318+
cache = CC.get(CC.code_cache(interp), edge, nothing)
319+
if cache !== nothing
320+
src = @atomic :monotonic cache.inferred
321+
if isa(src, DAECache)
322+
info = src.info
323+
merge_daeinfo!(interp, sv.result, info)
324+
end
325325
end
326326
end
327+
return ret
327328
end
328-
return ret
329329
end
330330

331331
@override function CC.const_prop_call(interp::DAEInterpreter,
@@ -443,9 +443,9 @@ end
443443

444444
# TODO propagate debug configurations here
445445
@override function CC.optimize(interp::DAEInterpreter, opt::OptimizationState, caller::InferenceResult)
446-
ir = CC.run_passes_ipo_safe(opt.src, opt, caller)
446+
ir = CC.run_passes_ipo_safe(opt.src, opt)
447447
ir = run_dae_passes(interp, ir)
448-
CC.ipo_dataflow_analysis!(interp, ir, caller)
448+
CC.ipo_dataflow_analysis!(interp, opt, ir, caller)
449449
if interp.ipo_analysis_mode
450450
result = ipo_dae_analysis!(interp, ir, caller.linfo, caller)
451451
if result !== nothing
@@ -524,14 +524,10 @@ end
524524
src === nothing && return nothing
525525
(; inferred, ir) = src::DAECache
526526
(isa(inferred, CodeInfo) && isa(ir, IRCode)) || return nothing
527-
method_info = CC.MethodInfo(inferred)
527+
method_info = CC.SpecInfo(inferred)
528528
ir = copy(ir)
529529
(; min_world, max_world) = inferred
530-
if Base.__has_internal_change(v"1.12-alpha", :codeinfonargs)
531-
argtypes = CC.va_process_argtypes(CC.optimizer_lattice(interp), argtypes, inferred.nargs, inferred.isva)
532-
elseif VERSION >= v"1.12.0-DEV.341"
533-
argtypes = CC.va_process_argtypes(CC.optimizer_lattice(interp), argtypes, mi)
534-
end
530+
argtypes = CC.va_process_argtypes(CC.optimizer_lattice(interp), argtypes, inferred.nargs, inferred.isva)
535531
return IRInterpretationState(interp, method_info, ir, mi, argtypes,
536532
world, min_world, max_world)
537533
end
@@ -974,34 +970,36 @@ function _abstract_eval_invoke_inst(interp::DAEInterpreter, inst::Union{CC.Instr
974970
end
975971

976972
@override function CC.abstract_eval_statement_expr(interp::DAEInterpreter, inst::Expr, vtypes::Nothing, irsv::IRInterpretationState)
977-
(; rt, exct, effects) = @invoke CC.abstract_eval_statement_expr(interp::AbstractInterpreter, inst::Expr, vtypes::Nothing, irsv::IRInterpretationState)
978-
979-
if (!interp.ipo_analysis_mode || interp.in_analysis) && !isa(rt, Const) && !isa(rt, Incidence) && !CC.isType(rt) && !is_all_inc_or_const(Any[rt])
980-
argtypes = CC.collect_argtypes(interp, inst.args, nothing, irsv)
981-
if argtypes === nothing
982-
return CC.RTEffects(rt, exct, effects)
983-
end
984-
if is_all_inc_or_const(argtypes)
985-
if inst.head in (:call, :invoke) && CC.hasintersect(widenconst(argtypes[inst.head === :call ? 1 : 2]), Union{typeof(variable), typeof(sim_time), typeof(state_ddt)})
986-
# The `variable` and `state_ddt` intrinsics can source Incidence. For all other
987-
# calls, if there's no incidence in the arguments, there cannot be any incidence
988-
# in the result.
973+
ret = @invoke CC.abstract_eval_statement_expr(interp::AbstractInterpreter, inst::Expr, vtypes::Nothing, irsv::IRInterpretationState)
974+
return Future{CC.RTEffects}(ret, interp, irsv) do ret, interp, irsv
975+
(; rt, exct, effects) = ret
976+
if (!interp.ipo_analysis_mode || interp.in_analysis) && !isa(rt, Const) && !isa(rt, Incidence) && !CC.isType(rt) && !is_all_inc_or_const(Any[rt])
977+
argtypes = CC.collect_argtypes(interp, inst.args, nothing, irsv)
978+
if argtypes === nothing
989979
return CC.RTEffects(rt, exct, effects)
990980
end
991-
fb_inci = _fallback_incidence(argtypes)
992-
if fb_inci !== nothing
993-
update_type(t::Type) = Incidence(t, fb_inci.row, fb_inci.eps)
994-
update_type(t::Incidence) = t
995-
update_type(t::Const) = t
996-
update_type(t::CC.PartialTypeVar) = t
997-
update_type(t::PartialStruct) = PartialStruct(t.typ, Any[Base.isvarargtype(f) ? f : update_type(f) for f in t.fields])
998-
update_type(t::CC.Conditional) = CC.Conditional(t.slot, update_type(t.thentype), update_type(t.elsetype))
999-
newrt = update_type(rt)
1000-
return CC.RTEffects(newrt, exct, effects)
981+
if is_all_inc_or_const(argtypes)
982+
if inst.head in (:call, :invoke) && CC.hasintersect(widenconst(argtypes[inst.head === :call ? 1 : 2]), Union{typeof(variable), typeof(sim_time), typeof(state_ddt)})
983+
# The `variable` and `state_ddt` intrinsics can source Incidence. For all other
984+
# calls, if there's no incidence in the arguments, there cannot be any incidence
985+
# in the result.
986+
return CC.RTEffects(rt, exct, effects)
987+
end
988+
fb_inci = _fallback_incidence(argtypes)
989+
if fb_inci !== nothing
990+
update_type(t::Type) = Incidence(t, fb_inci.row, fb_inci.eps)
991+
update_type(t::Incidence) = t
992+
update_type(t::Const) = t
993+
update_type(t::CC.PartialTypeVar) = t
994+
update_type(t::PartialStruct) = PartialStruct(t.typ, Any[Base.isvarargtype(f) ? f : update_type(f) for f in t.fields])
995+
update_type(t::CC.Conditional) = CC.Conditional(t.slot, update_type(t.thentype), update_type(t.elsetype))
996+
newrt = update_type(rt)
997+
return CC.RTEffects(newrt, exct, effects)
998+
end
1001999
end
10021000
end
1001+
return CC.RTEffects(rt, exct, effects)
10031002
end
1004-
return CC.RTEffects(rt, exct, effects)
10051003
end
10061004

10071005
@override function CC.compute_forwarded_argtypes(interp::DAEInterpreter, arginfo::ArgInfo, sv::AbsIntState)
@@ -1218,11 +1216,12 @@ function infer_ir!(ir, interp::AbstractInterpreter, mi::MethodInstance)
12181216
end
12191217
end
12201218

1221-
method_info = CC.MethodInfo(#=propagate_inbounds=#true, nothing)
1219+
(nargs, isva) = isa(mi.def, Method) ? (mi.def.nargs, mi.def.isva) : (0, false)
1220+
method_info = CC.SpecInfo(nargs, isva, #=propagate_inbounds=#true, nothing)
12221221
min_world = world = get_inference_world(interp)
12231222
max_world = get_world_counter()
12241223
irsv = IRInterpretationState(interp, method_info, ir, mi, ir.argtypes, world, min_world, max_world)
1225-
(rt, nothrow) = CC._ir_abstract_constant_propagation(interp, irsv)
1224+
(rt, nothrow) = CC.ir_abstract_constant_propagation(interp, irsv)
12261225
return rt
12271226
end
12281227

src/transform/common.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function remap_info(remap_ir!, info)
5757
if isa(result, CC.SemiConcreteResult)
5858
let ir = copy(result.ir)
5959
remap_ir!(ir)
60-
CC.SemiConcreteResult(result.mi, ir, result.effects)
60+
CC.SemiConcreteResult(result.mi, ir, result.effects, result.spec_info)
6161
end
6262
elseif isa(result, CC.ConstPropResult)
6363
if isa(result.result.src, DAECache)

0 commit comments

Comments
 (0)