diff --git a/src/stage1/recurse.jl b/src/stage1/recurse.jl index fef5c751..2d65f71f 100644 --- a/src/stage1/recurse.jl +++ b/src/stage1/recurse.jl @@ -273,10 +273,16 @@ function optic_transform!(ci, mi, nargs, N) # SSA conversion meth = mi.def::Method domtree = construct_domtree(ir.cfg.blocks) - stmts = VERSION < v"1.11.0-DEV.258" ? ir.stmts.inst : ir.stmts.stmt + stmts = @static VERSION < v"1.11.0-DEV.258" ? ir.stmts.inst : ir.stmts.stmt defuse_insts = scan_slot_def_use(Int(meth.nargs), ci, stmts) ci.ssavaluetypes = Any[Any for i = 1:ci.ssavaluetypes] - ir = construct_ssa!(ci, ir, domtree, defuse_insts, ci.slottypes, SimpleInferenceLattice.instance) + @static if VERSION > v"1.11.0-DEV.337" + interp = NativeInterpreter() # dummy interpreter (not used by `construct_ssa!`) + opt_state=OptimizationState(mi, ci, interp) + ir = construct_ssa!(ci, ir, opt_state, domtree, defuse_insts, SimpleInferenceLattice.instance) + else + ir = construct_ssa!(ci, ir, domtree, defuse_insts, ci.slottypes, SimpleInferenceLattice.instance) + end ir = compact!(ir) nfixedargs = Int(meth.nargs) diff --git a/src/stage2/abstractinterpret.jl b/src/stage2/abstractinterpret.jl index c655a19b..926a53e9 100644 --- a/src/stage2/abstractinterpret.jl +++ b/src/stage2/abstractinterpret.jl @@ -1,13 +1,13 @@ -import Core.Compiler: abstract_call_gf_by_type, abstract_call -using Core.Compiler: Const, isconstType, argtypes_to_type, tuple_tfunc, Const, - getfield_tfunc, _methods_by_ftype, VarTable, cache_lookup, nfields_tfunc, +import .CC: abstract_call_gf_by_type, abstract_call_opaque_closure +using .CC: Const, isconstType, argtypes_to_type, tuple_tfunc, Const, + getfield_tfunc, _methods_by_ftype, VarTable, nfields_tfunc, ArgInfo, singleton_type, CallMeta, MethodMatchInfo, specialize_method, PartialOpaque, UnionSplitApplyCallInfo, typeof_tfunc, apply_type_tfunc, instanceof_tfunc, StmtInfo using Core: PartialStruct using Base.Meta -function Core.Compiler.abstract_call_gf_by_type(interp::ADInterpreter, @nospecialize(f), +function CC.abstract_call_gf_by_type(interp::ADInterpreter, @nospecialize(f), arginfo::ArgInfo, si::StmtInfo, @nospecialize(atype), sv::InferenceState, max_methods::Int) (;argtypes) = arginfo if interp.backward @@ -25,7 +25,7 @@ function Core.Compiler.abstract_call_gf_by_type(interp::ADInterpreter, @nospecia mi = specialize_method(call.info.results.matches[1], preexisting=true) ci = get(rinterp.unopt[rinterp.current_level], mi, nothing) clos = AbstractCompClosure(rinterp.current_level, 1, call.info, ci.stmt_info) - clos = Core.PartialOpaque(Core.OpaqueClosure{<:Tuple, <:Any}, nothing, sv.linfo, clos) + clos = PartialOpaque(Core.OpaqueClosure{<:Tuple, <:Any}, nothing, sv.linfo, clos) elseif isa(call.info, RRuleInfo) if rinterp.current_level == 1 clos = getfield_tfunc(call.info.rrule_rt, Const(2)) @@ -550,7 +550,7 @@ function infer_prim_closure(interp::ADInterpreter, pc::PrimClosure, @nospecializ error() end -function Core.Compiler.abstract_call_opaque_closure(interp::ADInterpreter, +function CC.abstract_call_opaque_closure(interp::ADInterpreter, closure::PartialOpaque, arginfo::ArgInfo, sv::InferenceState, check::Bool=true) if isa(closure.source, AbstractCompClosure) @@ -565,8 +565,6 @@ function Core.Compiler.abstract_call_opaque_closure(interp::ADInterpreter, return infer_prim_closure(interp, closure.source, argtypes[2], sv) end - rt = invoke(Core.Compiler.abstract_call_opaque_closure, Tuple{AbstractInterpreter, PartialOpaque, ArgInfo, InferenceState, Bool}, - interp, closure, arginfo, sv, check) - - return rt + return @invoke CC.abstract_call_opaque_closure(interp::AbstractInterpreter, + closure::PartialOpaque, arginfo::ArgInfo, sv::InferenceState, check::Bool) end diff --git a/src/stage2/interpreter.jl b/src/stage2/interpreter.jl index e4fd5eda..0a9d995a 100644 --- a/src/stage2/interpreter.jl +++ b/src/stage2/interpreter.jl @@ -260,10 +260,6 @@ CC.get_inference_cache(ei::ADInterpreter) = get_inference_cache(ei.native_interp CC.lock_mi_inference(ei::ADInterpreter, mi::MethodInstance) = nothing CC.unlock_mi_inference(ei::ADInterpreter, mi::MethodInstance) = nothing -struct CodeInfoView - d::Dict{MethodInstance, Any} -end - function CC.code_cache(ei::ADInterpreter) while ei.current_level > lastindex(ei.opt) push!(ei.opt, Dict{MethodInstance, Any}()) @@ -273,16 +269,6 @@ end CC.may_optimize(ei::ADInterpreter) = true CC.may_compress(ei::ADInterpreter) = false CC.may_discard_trees(ei::ADInterpreter) = false -function CC.get(view::CodeInfoView, mi::MethodInstance, default) - r = get(view.d, mi, nothing) - if r === nothing - return default - end - if isa(r, OptimizationState) - r = r.src - end - return r::CodeInfo -end function CC.add_remark!(interp::ADInterpreter, sv::InferenceState, msg) key = CC.any(sv.result.overridden_by_const) ? sv.result : sv.linfo @@ -365,11 +351,17 @@ function CC.optimize(interp::ADInterpreter, opt::OptimizationState, end =# -function CC.finish!(interp::ADInterpreter, caller::InferenceResult) +function _finish!(caller::InferenceResult) effects = caller.ipo_effects caller.src = Cthulhu.create_cthulhu_source(caller.src, effects) end +@static if VERSION ≥ v"1.11.0-DEV.737" +CC.finish!(::ADInterpreter, caller::InferenceState) = _finish!(caller.result) +else +CC.finish!(::ADInterpreter, caller::InferenceResult) = _finish!(caller) +end + function ir2codeinst(ir::IRCode, inst::CodeInstance, ci::CodeInfo) CodeInstance(inst.def, inst.rettype, isdefined(inst, :rettype_const) ? inst.rettype_const : nothing, Cthulhu.OptimizedSource(CC.copy(ir), ci, inst.inferred.isinlineable, CC.decode_effects(inst.purity_bits)),