diff --git a/Manifest.toml b/Manifest.toml index f066b1d..e469c45 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -2,7 +2,7 @@ julia_version = "1.12.0-DEV" manifest_format = "2.0" -project_hash = "6f020e73f91c8d84d5a5677636dbdbaecdf0c01c" +project_hash = "358357b3116f929c974a76c332ca0867fdfaaa2d" [[deps.ADTypes]] git-tree-sha1 = "5a5eafb8344b81b8c2237f8a6f6b3602b3f6180e" @@ -256,6 +256,14 @@ weakdeps = ["Dates", "LinearAlgebra"] [deps.Compat.extensions] CompatLinearAlgebraExt = "LinearAlgebra" +[[deps.Compiler]] +git-tree-sha1 = "870045695768dbf84ebc7c8a1ec4a8ad30c6b489" +repo-rev = "master" +repo-subdir = "Compiler" +repo-url = "https://github.com/JuliaLang/julia.git" +uuid = "807dbc54-b67e-4c79-8afb-eafe4df6f2e1" +version = "0.0.1" + [[deps.CompilerSupportLibraries_jll]] deps = ["Artifacts", "Libdl"] uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" @@ -322,7 +330,7 @@ uuid = "f68482b8-f384-11e8-15f7-abe071a5a75f" version = "2.15.3" [[deps.DAECompiler]] -deps = ["Accessors", "CentralizedCaches", "ChainRules", "ChainRulesCore", "Cthulhu", "DiffEqBase", "DiffEqCallbacks", "Diffractor", "Distributions", "ExprTools", "ForwardDiff", "Graphs", "LinearAlgebra", "NonlinearSolve", "OrderedCollections", "OrdinaryDiffEq", "PrecompileTools", "Preferences", "REPL", "Random", "SciMLBase", "SciMLSensitivity", "SparseArrays", "StateSelection", "StaticArraysCore", "Sundials", "SymbolicIndexingInterface", "TimerOutputs", "Tracy"] +deps = ["Accessors", "CentralizedCaches", "ChainRules", "ChainRulesCore", "Compiler", "Cthulhu", "DiffEqBase", "DiffEqCallbacks", "Diffractor", "Distributions", "ExprTools", "ForwardDiff", "Graphs", "LinearAlgebra", "NonlinearSolve", "OrderedCollections", "OrdinaryDiffEq", "PrecompileTools", "Preferences", "REPL", "Random", "SciMLBase", "SciMLSensitivity", "SparseArrays", "StateSelection", "StaticArraysCore", "Sundials", "SymbolicIndexingInterface", "TimerOutputs", "Tracy"] path = "." uuid = "32805668-c3d0-42c2-aafd-0d0a9857a104" version = "1.21.0" @@ -443,9 +451,9 @@ uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" version = "1.15.1" [[deps.Diffractor]] -deps = ["AbstractDifferentiation", "ChainRules", "ChainRulesCore", "Combinatorics", "Cthulhu", "InteractiveUtils", "OffsetArrays", "PrecompileTools", "StaticArrays", "StructArrays"] -git-tree-sha1 = "a9a4b544e40f91c770760b4624284188be1fe9bd" -repo-rev = "kf/edgesadjust" +deps = ["AbstractDifferentiation", "ChainRules", "ChainRulesCore", "Combinatorics", "Compiler", "Cthulhu", "InteractiveUtils", "OffsetArrays", "PrecompileTools", "StaticArrays", "StructArrays"] +git-tree-sha1 = "64928a710dfaeda964f447f5e1fc9a5f758d25bb" +repo-rev = "main" repo-url = "https://github.com/JuliaDiff/Diffractor.jl.git" uuid = "9f5e2b26-1114-432f-b630-d3fe2085c51c" version = "0.2.10" diff --git a/Project.toml b/Project.toml index abc42a4..1771c80 100644 --- a/Project.toml +++ b/Project.toml @@ -11,6 +11,7 @@ Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" CentralizedCaches = "d1073d05-2d26-4019-b855-dfa0385fef5e" ChainRules = "082447d4-558c-5d27-93f4-14fc19e9eca2" ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" +Compiler = "807dbc54-b67e-4c79-8afb-eafe4df6f2e1" Cthulhu = "f68482b8-f384-11e8-15f7-abe071a5a75f" DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" DiffEqCallbacks = "459566f4-90b8-5000-8ac3-15dfb0a30def" @@ -33,17 +34,17 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" StateSelection = "64909d44-ed92-46a8-bbd9-f047dfbdc84b" StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" Sundials = "c3572dad-4567-51f8-b174-8c6c989267f4" +SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5" TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" Tracy = "e689c965-62c8-4b79-b2c5-8359227902fd" -SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5" + +[weakdeps] +ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" [sources] SciMLBase = {rev = "os/dae-get-du2", url = "https://github.com/CedarEDA/SciMLBase.jl"} SciMLSensitivity = {rev = "kf/mindep2", url = "https://github.com/CedarEDA/SciMLSensitivity.jl"} -[weakdeps] -ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" - [extensions] DAECompilerModelingToolkitExt = "ModelingToolkit" @@ -52,6 +53,7 @@ Accessors = "0.1.36" CentralizedCaches = "1.1.0" ChainRules = "1.50" ChainRulesCore = "1.20" +Compiler = "0.0.1" Cthulhu = "2.10.1" DiffEqBase = "6.149.2" Diffractor = "0.2.7" diff --git a/src/DAECompiler.jl b/src/DAECompiler.jl index 83ad999..21425f9 100644 --- a/src/DAECompiler.jl +++ b/src/DAECompiler.jl @@ -19,7 +19,8 @@ function reconstruct_sensitivities(args...) error("This method requires SciMLSensitivity") end -const CC = Core.Compiler +import Compiler +const CC = Compiler import .CC: get_inference_world using Base: get_world_counter diff --git a/src/analysis/compiler.jl b/src/analysis/compiler.jl index b2d8884..0816f70 100644 --- a/src/analysis/compiler.jl +++ b/src/analysis/compiler.jl @@ -2,7 +2,7 @@ using ForwardDiff using Base.Meta using Graphs using Core.IR -using Core.Compiler: InferenceState, bbidxiter, dominates, tmerge, typeinf_lattice +using .CC: InferenceState, bbidxiter, dominates, tmerge, typeinf_lattice @breadcrumb "ir_levels" function run_dae_passes( interp::DAEInterpreter, ir::IRCode, debug_config::DebugConfig = DebugConfig()) @@ -317,7 +317,7 @@ has_any_genscope(sc::Scope) = isdefined(sc, :parent) && has_any_genscope(sc.pare has_any_genscope(sc::PartialScope) = false has_any_genscope(sc::PartialStruct) = false # TODO -function _make_argument_lattice_elem(which::Argument, @nospecialize(argt), add_variable!, add_equation!, add_scope!) +function _make_argument_lattice_elem(𝕃, which::Argument, @nospecialize(argt), add_variable!, add_equation!, add_scope!) if isa(argt, Const) #@assert !isa(argt.val, Scope) # Shouldn't have been forwarded return argt @@ -331,7 +331,7 @@ function _make_argument_lattice_elem(which::Argument, @nospecialize(argt), add_v inc = Incidence(add_variable!(which)) return argt === Float64 ? inc : Incidence(argt, inc.row, inc.eps) elseif isa(argt, PartialStruct) - return PartialStruct(argt.typ, Any[make_argument_lattice_elem(which, f, add_variable!, add_equation!, add_scope!) for f in argt.fields]) + return PartialStruct(𝕃, argt.typ, Any[make_argument_lattice_elem(𝕃, which, f, add_variable!, add_equation!, add_scope!) for f in argt.fields]) elseif isabstracttype(argt) || ismutabletype(argt) || !isa(argt, DataType) return nothing else @@ -344,7 +344,7 @@ function _make_argument_lattice_elem(which::Argument, @nospecialize(argt), add_v for i = 1:length(fieldtypes(argt)) # TODO: Can we make this lazy? ft = fieldtype(argt, i) - mft = _make_argument_lattice_elem(which, ft, add_variable!, add_equation!, add_scope!) + mft = _make_argument_lattice_elem(𝕃, which, ft, add_variable!, add_equation!, add_scope!) if mft === nothing push!(fields, Incidence(ft)) else @@ -352,12 +352,12 @@ function _make_argument_lattice_elem(which::Argument, @nospecialize(argt), add_v push!(fields, mft) end end - return any ? PartialStruct(argt, fields) : nothing + return any ? PartialStruct(𝕃, argt, fields) : nothing end end -function make_argument_lattice_elem(which::Argument, @nospecialize(argt), add_variable!, add_equation!, add_scope!) - mft = _make_argument_lattice_elem(which, argt, add_variable!, add_equation!, add_scope!) +function make_argument_lattice_elem(𝕃, which::Argument, @nospecialize(argt), add_variable!, add_equation!, add_scope!) + mft = _make_argument_lattice_elem(𝕃, which, argt, add_variable!, add_equation!, add_scope!) mft === nothing ? Incidence(argt) : mft end @@ -532,7 +532,7 @@ end nexternalvars = 0 # number of variables that we expect to come in nexternaleqs = 0 # number of equation references that we expect to come in if caller !== nothing - argtypes = Any[make_argument_lattice_elem(Argument(i), argt, add_variable!, add_equation!, add_scope!) for (i, argt) in enumerate(ir.argtypes)] + argtypes = Any[make_argument_lattice_elem(CC.typeinf_lattice(interp), Argument(i), argt, add_variable!, add_equation!, add_scope!) for (i, argt) in enumerate(ir.argtypes)] nexternalvars = length(var_to_diff) nexternaleqs = length(eqssas) else @@ -571,7 +571,7 @@ end end end - cur_scope_lattice = PartialStruct(Base.ScopedValues.Scope, + cur_scope_lattice = PartialStruct(CC.typeinf_lattice(interp), Base.ScopedValues.Scope, Any[PartialKeyValue(Incidence(Base.PersistentDict{Base.ScopedValues.ScopedValue, Any}))]) # Scan the IR, computing equations, variables, diffgraph, etc. @@ -1017,7 +1017,7 @@ end for eq = 1:length(result.eq_kind) mapped_eq = mapping.eqs[eq] mapped_eq == 0 && continue - mapped_inc = apply_linear_incidence(result.total_incidence[eq], result, var_to_diff, var_kind, eq_kind, mapping) + mapped_inc = apply_linear_incidence(CC.typeinf_lattice(interp), result.total_incidence[eq], result, var_to_diff, var_kind, eq_kind, mapping) if isassigned(total_incidence, mapped_eq) total_incidence[mapped_eq] = tfunc(Val(Core.Intrinsics.add_float), total_incidence[mapped_eq], @@ -1033,7 +1033,7 @@ end for (ieq, inc) in enumerate(result.total_incidence[(result.nexternaleqs+1):end]) mapping.eqs[ieq] == 0 || continue - push!(total_incidence, apply_linear_incidence(inc, result, var_to_diff, var_kind, eq_kind, mapping)) + push!(total_incidence, apply_linear_incidence(CC.typeinf_lattice(interp), inc, result, var_to_diff, var_kind, eq_kind, mapping)) push!(eq_callee_mapping, [SSAValue(i)=>ieq]) push!(eq_kind, CalleeInternal) mapping.eqs[ieq] = length(total_incidence) @@ -1115,7 +1115,7 @@ end nimplicitoutpairs = 0 if caller !== nothing - ultimate_rt, nimplicitoutpairs = process_ipo_return!(ultimate_rt, eq_kind, var_kind, + ultimate_rt, nimplicitoutpairs = process_ipo_return!(CC.typeinf_lattice(interp), ultimate_rt, eq_kind, var_kind, var_to_diff, total_incidence, eq_callee_mapping) end @@ -1135,7 +1135,7 @@ end Dict{TornCacheKey, CodeInstance}()) end -function process_ipo_return!(ultimate_rt::Incidence, eq_kind, var_kind, var_to_diff, total_incidence, eq_callee_mapping) +function process_ipo_return!(𝕃, ultimate_rt::Incidence, eq_kind, var_kind, var_to_diff, total_incidence, eq_callee_mapping) nonlinrepl = nothing nimplicitoutpairs = 0 function get_nonlinrepl() @@ -1179,20 +1179,20 @@ function process_ipo_return!(ultimate_rt::Incidence, eq_kind, var_kind, var_to_d return ultimate_rt, nimplicitoutpairs end -function process_ipo_return!(ultimate_rt::Eq, eq_kind, args...) +function process_ipo_return!(𝕃, ultimate_rt::Eq, eq_kind, args...) eq_kind[ultimate_rt.id] = External return ultimate_rt, 0 end -process_ipo_return!(ultimate_rt::Union{Type, PartialScope, PartialKeyValue, Const}, args...) = ultimate_rt, 0 -function process_ipo_return!(ultimate_rt::PartialStruct, args...) +process_ipo_return!(𝕃, ultimate_rt::Union{Type, PartialScope, PartialKeyValue, Const}, args...) = ultimate_rt, 0 +function process_ipo_return!(𝕃, ultimate_rt::PartialStruct, args...) nimplicitoutpairs = 0 fields = Any[] for f in ultimate_rt.fields - (rt, n) = process_ipo_return!(f, args...) + (rt, n) = process_ipo_return!(𝕃, f, args...) nimplicitoutpairs += n push!(fields, rt) end - return PartialStruct(ultimate_rt.typ, fields), nimplicitoutpairs + return PartialStruct(𝕃, ultimate_rt.typ, fields), nimplicitoutpairs end function get_variable_name(names::OrderedDict, var_to_diff, var_idx) diff --git a/src/analysis/compiler_reexports.jl b/src/analysis/compiler_reexports.jl index 0a97f41..f61524c 100644 --- a/src/analysis/compiler_reexports.jl +++ b/src/analysis/compiler_reexports.jl @@ -1,27 +1,9 @@ using Core.IR -using Core.Compiler: IRCode, Instruction, InstructionStream, IncrementalCompact, +using .CC: IRCode, Instruction, InstructionStream, IncrementalCompact, NewInstruction, DomTree, BBIdxIter, AnySSAValue, UseRef, UseRefIterator, block_for_inst, cfg_simplify!, is_known_call, argextype, getfield_tfunc, finish, singleton_type, widenconst, dominates_ssa, βŠ‘, userefs -# TODO: This really needs to go into a uniform compiler stdlib. -Base.iterate(compact::IncrementalCompact, state) = Core.Compiler.iterate(compact, state) -Base.iterate(compact::IncrementalCompact) = Core.Compiler.iterate(compact) -Base.iterate(abu::CC.AbsIntStackUnwind, state...) = CC.iterate(abu, state...) - -Base.setindex!(compact::IncrementalCompact, @nospecialize(v), idx::SSAValue) = Core.Compiler.setindex!(compact,v,idx) -Base.setindex!(ir::IRCode, @nospecialize(v), idx::SSAValue) = Core.Compiler.setindex!(ir,v,idx) -Base.setindex!(inst::Instruction, @nospecialize(v), sym::Symbol) = Core.Compiler.setindex!(inst,v,sym) -Base.getindex(compact::IncrementalCompact, idx::AnySSAValue) = Core.Compiler.getindex(compact,idx) - -Base.setindex!(urs::InstructionStream, @nospecialize args...) = Core.Compiler.setindex!(urs, args...) -Base.setindex!(ir::IRCode, @nospecialize args...) = Core.Compiler.setindex!(ir, args...) -Base.getindex(ir::IRCode, @nospecialize args...) = Core.Compiler.getindex(ir, args...) - -Base.IteratorSize(::Type{CC.AbsIntStackUnwind}) = Base.SizeUnknown() - -# TODO: Move this to Core.Compiler -CC.block_for_inst(ir::IRCode, s::SSAValue) = block_for_inst(ir, s.id) function CC.dominates_ssa(ir::IRCode, domtree::DomTree, x::SSAValue, y::SSAValue; dominates_after=false) xb = block_for_inst(ir, x) yb = block_for_inst(ir, y) @@ -82,6 +64,3 @@ function replace_argument!(compact::IncrementalCompact, idx::Int, argn::Argument compact[ssa] = urs[] end -Base.copy(phi::PhiNode) = Core.PhiNode(copy(phi.edges), copy(phi.values)) -Base.push!(bs::CC.BitSet, i::Int) = CC.push!(bs, i) -Base.push!(bs::CC.BitSetBoundedMinPrioritySet, i::Int) = CC.push!(bs, i) \ No newline at end of file diff --git a/src/analysis/interpreter.jl b/src/analysis/interpreter.jl index cdbe75d..222bea0 100644 --- a/src/analysis/interpreter.jl +++ b/src/analysis/interpreter.jl @@ -14,7 +14,7 @@ using StateSelection: DiffGraph using Cthulhu using ChainRulesCore -# similer to `Core.Compiler.Effects` but for DAE-specific information +# similer to `Compiler.Effects` but for DAE-specific information struct DAEInfo has_dae_intrinsics::Bool has_scoperead::Bool @@ -45,19 +45,17 @@ struct DAEGlobalCache end DAEGlobalCache() = @new_cache DAEGlobalCache(IdDict{MethodInstance,CodeInstance}()) Base.empty!(cache::DAEGlobalCache) = empty!(cache.cache) -CC.get(wvc::CC.WorldView{DAEGlobalCache}, key, default) = +Base.get(wvc::CC.WorldView{DAEGlobalCache}, key, default) = Base.get(wvc.cache.cache, key, default) -CC.getindex(wvc::CC.WorldView{DAEGlobalCache}, key) = +Base.getindex(wvc::CC.WorldView{DAEGlobalCache}, key) = Base.getindex(wvc.cache.cache, key) -CC.get(cache::DAEGlobalCache, key, default) = - Base.get(cache.cache, key, default) Base.get(cache::DAEGlobalCache, key, default) = Base.get(cache.cache, key, default) -CC.haskey(wvc::CC.WorldView{DAEGlobalCache}, key) = +Base.haskey(wvc::CC.WorldView{DAEGlobalCache}, key) = Base.haskey(wvc.cache.cache, key) -CC.setindex!(cache::DAEGlobalCache, val, key) = +Base.setindex!(cache::DAEGlobalCache, val, key) = Base.setindex!(cache.cache, val, key) -CC.getindex(cache::DAEGlobalCache, key) = +Base.getindex(cache::DAEGlobalCache, key) = Base.getindex(cache.cache, key) const GLOBAL_CODE_CACHE = @new_cache Dict{UInt, DAEGlobalCache}() @@ -270,9 +268,9 @@ function structural_inc_ddt(var_to_diff::DiffGraph, var_kind::Vector{VarEqKind}, return Incidence(isa(inc.typ, Const) ? Const(zero(inc.typ.val)) : inc.typ, r, inc.eps) end -widenincidence(inc::Incidence) = inc.typ -widenincidence(p::PartialStruct) = PartialStruct(p.typ, Any[widenincidence(f) for f in p.fields]) -widenincidence(@nospecialize(x)) = x +widenincidence(@nospecialize(_), inc::Incidence) = inc.typ +widenincidence(𝕃, p::PartialStruct) = PartialStruct(𝕃, p.typ, Any[widenincidence(𝕃, f) for f in p.fields]) +widenincidence(@nospecialize(_), @nospecialize(x)) = x @override function CC.abstract_call_known(interp::DAEInterpreter, @nospecialize(f), arginfo::ArgInfo, si::StmtInfo, sv::AbsIntState, max_methods::Int) @@ -304,7 +302,7 @@ widenincidence(@nospecialize(x)) = x merge_daeinfo!(interp, sv.result, DAEInfo(; has_scoperead=true)) end end - arginfo = ArgInfo(arginfo.fargs, map(widenincidence, arginfo.argtypes)) + arginfo = ArgInfo(arginfo.fargs, map(x->widenincidence(CC.typeinf_lattice(interp), x), arginfo.argtypes)) return Diffractor.fwd_abstract_call_gf_by_type(interp, f, arginfo, si, sv, ret) end @@ -628,7 +626,7 @@ end end update_incidence(@nospecialize(a)) = a function update_incidence(i::PartialStruct) - return PartialStruct(i.typ, Any[update_incidence(f) for f in i.fields]) + return PartialStruct(CC.typeinf_lattice(interp), i.typ, Any[update_incidence(f) for f in i.fields]) end return update_incidence(valr) @@ -666,7 +664,7 @@ function process_template!(𝕃, coeffs, eq_mapping, applied_scopes, argtypes, t @assert isa(arg, Eq) eq_mapping[idnum(template)] = idnum(arg) elseif CC.is_const_argtype(template) - #@Core.Compiler.show (arg, template) + #@CC.show (arg, template) #@assert CC.is_lattice_equal(DAE_LATTICE, arg, template) elseif isa(template, PartialScope) id = idnum(template) @@ -737,9 +735,9 @@ function compute_missing_coeff!(coeffs, result, caller_var_to_diff, caller_var_k return nothing end -apply_linear_incidence(ret::Type, result::DAEIPOResult, caller_var_to_diff::DiffGraph, caller_var_kind::Vector{VarEqKind}, caller_eq_kind::Vector{VarEqKind}, mapping::CalleeMapping) = ret -apply_linear_incidence(ret::Const, result::DAEIPOResult, caller_var_to_diff::DiffGraph, caller_var_kind::Vector{VarEqKind}, caller_eq_kind::Vector{VarEqKind}, mapping::CalleeMapping) = ret -function apply_linear_incidence(ret::Incidence, result::DAEIPOResult, caller_var_to_diff::DiffGraph, caller_var_kind::Vector{VarEqKind}, caller_eq_kind::Vector{VarEqKind}, mapping::CalleeMapping) +apply_linear_incidence(𝕃, ret::Type, result::DAEIPOResult, caller_var_to_diff::DiffGraph, caller_var_kind::Vector{VarEqKind}, caller_eq_kind::Vector{VarEqKind}, mapping::CalleeMapping) = ret +apply_linear_incidence(𝕃, ret::Const, result::DAEIPOResult, caller_var_to_diff::DiffGraph, caller_var_kind::Vector{VarEqKind}, caller_eq_kind::Vector{VarEqKind}, mapping::CalleeMapping) = ret +function apply_linear_incidence(𝕃, ret::Incidence, result::DAEIPOResult, caller_var_to_diff::DiffGraph, caller_var_kind::Vector{VarEqKind}, caller_eq_kind::Vector{VarEqKind}, mapping::CalleeMapping) coeffs = mapping.var_coeffs const_val = ret.typ @@ -784,7 +782,7 @@ function apply_linear_incidence(ret::Incidence, result::DAEIPOResult, caller_var return Incidence(const_val, new_row, BitSet()) end -function apply_linear_incidence(ret::Eq, result::DAEIPOResult, caller_var_to_diff::DiffGraph, caller_var_kind::Vector{VarEqKind}, caller_eq_kind::Vector{VarEqKind}, mapping::CalleeMapping) +function apply_linear_incidence(𝕃, ret::Eq, result::DAEIPOResult, caller_var_to_diff::DiffGraph, caller_var_kind::Vector{VarEqKind}, caller_eq_kind::Vector{VarEqKind}, mapping::CalleeMapping) eq_mapping = mapping.eqs[ret.id] if eq_mapping == 0 push!(caller_eq_kind, Owned) @@ -793,8 +791,8 @@ function apply_linear_incidence(ret::Eq, result::DAEIPOResult, caller_var_to_dif return Eq(eq_mapping) end -function apply_linear_incidence(ret::PartialStruct, result::DAEIPOResult, caller_var_to_diff::DiffGraph, caller_var_kind::Vector{VarEqKind}, caller_eq_kind::Vector{VarEqKind}, mapping::CalleeMapping) - return PartialStruct(ret.typ, Any[apply_linear_incidence(f, result, caller_var_to_diff, caller_var_kind, caller_eq_kind, mapping) for f in ret.fields]) +function apply_linear_incidence(𝕃, ret::PartialStruct, result::DAEIPOResult, caller_var_to_diff::DiffGraph, caller_var_kind::Vector{VarEqKind}, caller_eq_kind::Vector{VarEqKind}, mapping::CalleeMapping) + return PartialStruct(𝕃, ret.typ, Any[apply_linear_incidence(𝕃, f, result, caller_var_to_diff, caller_var_kind, caller_eq_kind, mapping) for f in ret.fields]) end if isdefined(CC, :abstract_eval_invoke_inst) @@ -878,7 +876,7 @@ function _abstract_eval_invoke_inst(interp::DAEInterpreter, inst::Union{CC.Instr # provide a special placeholder PartialScope. # HACK: This currently assumes there's only one scope # being passed through ScopedValue - return RT(PartialStruct(Tuple{Intrinsics.AbstractScope}, Any[PartialScope(index)]), good_effects) + return RT(PartialStruct(CC.typeinf_lattice(interp), Tuple{Intrinsics.AbstractScope}, Any[PartialScope(index)]), good_effects) end end return RT(Union{Nothing, widenconst(CC.tuple_tfunc(CC.optimizer_lattice(interp), Any[sct]))}, good_effects) @@ -910,7 +908,7 @@ function _abstract_eval_invoke_inst(interp::DAEInterpreter, inst::Union{CC.Instr return RT(nothing, (false, false)) end mapping = CalleeMapping(CC.optimizer_lattice(interp), argtypes, callee_result) - new_rt = apply_linear_incidence(callee_result.extended_rt, callee_result, interp.var_to_diff, interp.var_kind, interp.eq_kind, mapping) + new_rt = apply_linear_incidence(CC.optimizer_lattice(interp), callee_result.extended_rt, callee_result, interp.var_to_diff, interp.var_kind, interp.eq_kind, mapping) # If this callee has no internal equations and at most one non-linear return, then we are guaranteed # never to need to fission this, so we can just treat it as a primitive. @@ -979,7 +977,7 @@ end update_type(t::Incidence) = t update_type(t::Const) = t update_type(t::CC.PartialTypeVar) = t - update_type(t::PartialStruct) = PartialStruct(t.typ, Any[Base.isvarargtype(f) ? f : update_type(f) for f in t.fields]) + update_type(t::PartialStruct) = PartialStruct(CC.typeinf_lattice(interp), t.typ, Any[Base.isvarargtype(f) ? f : update_type(f) for f in t.fields]) update_type(t::CC.Conditional) = CC.Conditional(t.slot, update_type(t.thentype), update_type(t.elsetype)) newrt = update_type(rt) return CC.RTEffects(newrt, exct, effects) @@ -1025,7 +1023,7 @@ function typeinf_dae(@nospecialize(tt), world::UInt=get_world_counter(); isempty(match) && single_match_error(tt) match = only(match) mi = CC.specialize_method(match) - ci = CC.typeinf_ext(interp, mi, Core.Compiler.SOURCE_MODE_ABI) + ci = CC.typeinf_ext(interp, mi, CC.SOURCE_MODE_ABI) return interp, ci end diff --git a/src/analysis/lattice.jl b/src/analysis/lattice.jl index e1b7e4c..b229681 100644 --- a/src/analysis/lattice.jl +++ b/src/analysis/lattice.jl @@ -8,8 +8,8 @@ using SparseArrays This lattice implements the `AbstractLattice` interface. It adjoins `Incidence` and `Eq`. -The DAELattice is one of the key places where DAECompiler extends -Core.Compiler. In compiler parlance, the DAELattice type system can be +The DAELattice is one of the key places where DAECompiler extends `Compiler`. +In compiler parlance, the DAELattice type system can be thought of as a taint analysis sourced at `variable` (with sinks at `variable`, `equation`, etc.). In dynamical systems parlance, one might consider this analysis to compute a structural jacobian. @@ -330,7 +330,7 @@ struct PartialKeyValue end PartialKeyValue(typ) = PartialKeyValue(typ, typ, IdDict{Any, Any}()) -function getkeyvalue_tfunc(𝕃::Core.Compiler.AbstractLattice, +function getkeyvalue_tfunc(𝕃::CC.AbstractLattice, @nospecialize(collection), @nospecialize(key)) isa(key, Const) || return Tuple{Any} if haskey(collection.vals, key.val) diff --git a/src/irodesystem.jl b/src/irodesystem.jl index 8dc6f3c..bc2428d 100644 --- a/src/irodesystem.jl +++ b/src/irodesystem.jl @@ -3,7 +3,7 @@ using StateSelection: DiffGraph, BipartiteGraph using StateSelection: MatchedSystemStructure, TransformationState using StateSelection.BipartiteGraphs using StateSelection.CLIL -using Core.Compiler: IRCode, SSAValue, NewSSAValue, MethodInstance +using .CC: IRCode, SSAValue, NewSSAValue, MethodInstance using TimerOutputs: @timeit, TimerOutput using Tracy: @tracepoint using Preferences: @load_preference @@ -155,7 +155,7 @@ struct IRODESystem debug_config::DebugConfig function IRODESystem(tt::Type{<:Tuple{Any}}; - fallback_interp::AbstractInterpreter = Core.Compiler.NativeInterpreter(), + fallback_interp::AbstractInterpreter = CC.NativeInterpreter(), debug_config = (;), ipo_analysis_mode = false, world::UInt=Base.tls_world_age()) @@ -255,7 +255,7 @@ IR, potentially throwing an exception if the verification fails. function record_ir!(debug_config::DebugConfig, name::String, ir::IRCode, - verification_lattice::Core.Compiler.AbstractLattice = + verification_lattice::CC.AbstractLattice = CC.PartialsLattice(DAELattice())) # If the user provides `""` as the name, we just use the stack as the name. fulllevelname = get_record_ir_leaf_name(name) @@ -285,7 +285,7 @@ function record_ir!(debug_config::DebugConfig, # `UnsupportedIRException` with `ir_levels` bundled in if this fails. if debug_config.verify_ir_levels try - Core.Compiler.verify_ir(ir, false, false, verification_lattice) + CC.verify_ir(ir, false, false, verification_lattice) catch e throw(UnsupportedIRException("IR verification failure", ir)) end diff --git a/src/runtime.jl b/src/runtime.jl index 2585f15..5f03dc0 100644 --- a/src/runtime.jl +++ b/src/runtime.jl @@ -269,7 +269,7 @@ module Intrinsics mutable struct variables{VT} const scope::Scope nt::NamedTuple{names, T} where {N, names, T<:NTuple{N, VT}} - variables(s::Scope) = new{Core.Compiler._return_type(variable, Tuple{})}(s, (;)) + variables(s::Scope) = new{Base._return_type(variable, Tuple{})}(s, (;)) end variables() = variables(root_scope) variables(s::Symbol) = variables(Scope(root_scope, s)) diff --git a/src/transform/dae_finish.jl b/src/transform/dae_finish.jl index bef013e..3d99306 100644 --- a/src/transform/dae_finish.jl +++ b/src/transform/dae_finish.jl @@ -240,7 +240,7 @@ end function ir_to_cache(ir::IRCode) isva = false slotnames = nothing - ir = Core.Compiler.copy(ir) + ir = CC.copy(ir) # if the user didn't specify a definition MethodInstance or filename Symbol to use for the debuginfo, set a filename now ir.debuginfo.def === nothing && (ir.debuginfo.def = :var"generated IR for OpaqueClosure") nargtypes = length(ir.argtypes) @@ -256,7 +256,7 @@ function ir_to_cache(ir::IRCode) end src.slotflags = fill(zero(UInt8), nargtypes) src.slottypes = copy(ir.argtypes) - src = Core.Compiler.ir_to_codeinf!(src, ir) + src = CC.ir_to_codeinf!(src, ir) return src end @@ -450,18 +450,16 @@ function ir_to_src(ir::IRCode) src.isva = false src.slotflags = fill(zero(UInt8), nargtypes) src.slottypes = copy(ir.argtypes) - src = Core.Compiler.ir_to_codeinf!(src, ir) + src = CC.ir_to_codeinf!(src, ir) return src end function dae_factory_gen(world::UInt, source::LineNumberNode, _, @nospecialize(fT)) - @Core.Compiler.show fT - @Core.Compiler.show world sys_ipo = IRODESystem(Tuple{fT}; world, ipo_analysis_mode=true); result = getfield(sys_ipo, :result) interp = getfield(sys_ipo, :interp) - codeinst = Core.Compiler.get(Core.Compiler.code_cache(interp), getfield(sys_ipo, :mi), nothing) + codeinst = CC.get(CC.code_cache(interp), getfield(sys_ipo, :mi), nothing) # For the top-level problem, all external vars are state-invariant, and we do no other fissioning param_vars = BitSet(1:result.nexternalvars) diff --git a/src/transform/dae_transform.jl b/src/transform/dae_transform.jl index 7090927..155f967 100644 --- a/src/transform/dae_transform.jl +++ b/src/transform/dae_transform.jl @@ -1,5 +1,5 @@ using Core: CodeInfo -using Core.Compiler: IRCode, NewInstruction, InliningState, +using .CC: IRCode, NewInstruction, InliningState, adce_pass!, compact!, insert_node!, quoted, sroa_pass!, ssa_inlining_pass! using StateSelection: MatchedSystemStructure using SparseArrays diff --git a/src/transform/tearing_schedule.jl b/src/transform/tearing_schedule.jl index 636978f..11acc1a 100644 --- a/src/transform/tearing_schedule.jl +++ b/src/transform/tearing_schedule.jl @@ -1,5 +1,5 @@ using StateSelection.BipartiteGraphs: DiCMOBiGraph, topological_sort_by_dfs -using Core.Compiler: NewSSAValue, OldSSAValue, Instruction, insert_node_here!, construct_domtree +using .CC: NewSSAValue, OldSSAValue, Instruction, insert_node_here!, construct_domtree function type_contains_taint(@nospecialize(incT), var, available) if isa(incT, Incidence) @@ -62,9 +62,10 @@ end compact = IncrementalCompact(ir) (eqs, vars) = find_eqs_vars(state.structure.graph, compact) - ir = Core.Compiler.finish(compact) + ir = CC.finish(compact) ipo_result = getfield(state.sys, :result) + 𝕃 = CC.typeinf_lattice(getfield(state.sys, :interp)) @may_timeit debug_config "tearing" begin domtree = construct_domtree(ir.cfg.blocks) @@ -152,7 +153,7 @@ end end return Incidence(const_val, new_row, incT.eps) end - remap_incidence(t::PartialStruct, var) = PartialStruct(t.typ, Any[remap_incidence(f, var) for f in t.fields]) + remap_incidence(t::PartialStruct, var) = PartialStruct(𝕃, t.typ, Any[remap_incidence(f, var) for f in t.fields]) remap_incidence(t::PartialKeyValue, var) = PartialKeyValue(remap_incidence(t.typ, var), remap_incidence(t.parent, var), IdDict{Any, Any}(remap_incidence(k, var)=>remap_incidence(v, var) for (k, v) in pairs(t.vals))) remap_incidence(t::Union{Type, Const, Eq}, var) = t @@ -647,7 +648,7 @@ end inst[:info] = remap_info(ir2->remap_ir!(ir2, 0), inst[:info]) end - ir = Core.Compiler.finish(compact) + ir = CC.finish(compact) end record_ir!(state, "", ir) diff --git a/src/transform/tearing_schedule_ipo.jl b/src/transform/tearing_schedule_ipo.jl index 225d4c5..165111e 100644 --- a/src/transform/tearing_schedule_ipo.jl +++ b/src/transform/tearing_schedule_ipo.jl @@ -19,7 +19,7 @@ function ir_mul_const!(compact, line, coeff::Float64, _a) return z end -Base.IteratorSize(::Type{Core.Compiler.UseRefIterator}) = Base.SizeUnknown() +Base.IteratorSize(::Type{CC.UseRefIterator}) = Base.SizeUnknown() struct StateInvariant; end StateSelection.BipartiteGraphs.overview_label(::Type{StateInvariant}) = ('P', "State Invariant / Parameter", :red) @@ -618,7 +618,7 @@ function tearing_schedule!(interp, ci::CodeInstance, key::TornCacheKey) end end - callee_codeinst = Core.Compiler.get(Core.Compiler.code_cache(interp), stmt.args[1], nothing) + callee_codeinst = CC.get(CC.code_cache(interp), stmt.args[1], nothing) callee_sicm_mi = tearing_schedule!(interp, callee_codeinst, callee_key) inst[:type] = Any diff --git a/test/JITOpaqueClosures.jl b/test/JITOpaqueClosures.jl index 0a7dc24..db760cf 100644 --- a/test/JITOpaqueClosures.jl +++ b/test/JITOpaqueClosures.jl @@ -1,32 +1,33 @@ module JITOpaqueClosures using DAECompiler, Test using DAECompiler: JITOpaqueClosure +using Compiler @testset "basic use" begin my_typeof(x) = string(typeof(x)) my_typeof2 = JITOpaqueClosure{:my_typeof2}() do arg_types... input_ir = first(only(Base.code_ircode(my_typeof, Tuple{Any}))) - ir = Core.Compiler.copy(input_ir) - - compact = Core.Compiler.IncrementalCompact(ir) + ir = Compiler.copy(input_ir) + + compact = Compiler.IncrementalCompact(ir) # Force everything to be reinferred for ((_, idx), inst) in compact ssa = Core.SSAValue(idx) if Meta.isexpr(inst, :invoke) - compact[ssa][:inst] = Expr(:call, inst.args[2:end]...) + compact[ssa][:inst] = Expr(:call, inst.args[2:end]...) end compact[ssa][:type] = Any - compact[ssa][:flag] |= Core.Compiler.IR_FLAG_REFINED + compact[ssa][:flag] |= Compiler.IR_FLAG_REFINED end - ir = Core.Compiler.finish(compact) - ir = Core.Compiler.compact!(ir) + ir = Compiler.finish(compact) + ir = Compiler.compact!(ir) empty!(ir.argtypes) push!(ir.argtypes, Tuple{}) append!(ir.argtypes, arg_types) - - interp = Core.Compiler.NativeInterpreter() + + interp = Compiler.NativeInterpreter() mi = DAECompiler.get_toplevel_mi_from_ir(ir, @__MODULE__); DAECompiler.infer_ir!(ir, interp, mi) return Core.OpaqueClosure(ir; do_compile=true) @@ -37,7 +38,7 @@ using DAECompiler: JITOpaqueClosure @test my_typeof2(1.5) == "Float64" @test my_typeof2(2.3) == "Float64" -end +end @testset "threading" begin # Note this is in no way a comprehensive test of thread safety @@ -48,11 +49,11 @@ end sleep(0.5) return identity # Actually just returning a normal function for testing purposes end - + @sync for ii in 1:10 Threads.@spawn foo(42) end - @test builder_called == 1 # make sure only ran the builder function once + @test builder_called == 1 # make sure only ran the builder function once end @testset "goldclass" begin diff --git a/test/Project.toml b/test/Project.toml index 59c6f96..ef7c5e8 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,36 +1,37 @@ [deps] -DAECompiler = "32805668-c3d0-42c2-aafd-0d0a9857a104" +ChainRules = "082447d4-558c-5d27-93f4-14fc19e9eca2" +ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" +Compiler = "807dbc54-b67e-4c79-8afb-eafe4df6f2e1" ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e" +Cthulhu = "f68482b8-f384-11e8-15f7-abe071a5a75f" +DAECompiler = "32805668-c3d0-42c2-aafd-0d0a9857a104" DataInterpolations = "82cc6244-b520-54b8-b5a6-8a565e85f1d0" +Diffractor = "9f5e2b26-1114-432f-b630-d3fe2085c51c" FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41" FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000" +ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" ModelingToolkitStandardLibrary = "16a59e39-deab-5bd0-87e4-056b12336739" OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665" SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" +SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" +SciMLSensitivity = "1ed8b502-d754-442c-8d5d-10ac956f44a1" +SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" +StateSelection = "64909d44-ed92-46a8-bbd9-f047dfbdc84b" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" Sundials = "c3572dad-4567-51f8-b174-8c6c989267f4" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5" -StateSelection = "64909d44-ed92-46a8-bbd9-f047dfbdc84b" -Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -ChainRules = "082447d4-558c-5d27-93f4-14fc19e9eca2" -ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" -Diffractor = "9f5e2b26-1114-432f-b630-d3fe2085c51c" -ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" -SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" -SciMLSensitivity = "1ed8b502-d754-442c-8d5d-10ac956f44a1" -REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" -Cthulhu = "f68482b8-f384-11e8-15f7-abe071a5a75f" -LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" - -[compat] -Roots = "2.0.22" -ModelingToolkitStandardLibrary = "2.6.0" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [sources] ModelingToolkitStandardLibrary = {rev = "ox/dae_compatible5", url = "https://github.com/CedarEDA/ModelingToolkitStandardLibrary.jl"} + +[compat] +ModelingToolkitStandardLibrary = "2.6.0" +Roots = "2.0.22" diff --git a/test/compiler_and_lattice.jl b/test/compiler_and_lattice.jl index 8ab586c..eb8a461 100644 --- a/test/compiler_and_lattice.jl +++ b/test/compiler_and_lattice.jl @@ -1,6 +1,7 @@ module Compiler_and_Lattice -const CC = Core.Compiler +import Compiler +const CC = Compiler using DAECompiler using DAECompiler: aggressive_incidence_join, Incidence, nonlinear, tfunc, Const using Test @@ -10,6 +11,8 @@ using Test @test DAECompiler.idnum(DAECompiler.Eq(4)) == 4 end +const 𝕃 = CC.optimizer_lattice(DAECompiler.DAEInterpreter(Base.get_world_counter())) + @testset "aggressive_incidence_join" begin f4 = tfunc(Val(Core.Intrinsics.mul_float), Incidence(4), Incidence(4)) f4l5 = tfunc(Val(Core.Intrinsics.add_float), f4, Incidence(5)) @@ -23,29 +26,27 @@ end x end - type_differs = Core.PartialStruct(Foo, Any[Incidence(4), - Core.PartialStruct(Foo, Any[Core.PartialStruct(Tuple{Float64}, Any[Incidence(5)])]) + type_differs = Core.PartialStruct(𝕃, Foo, Any[Incidence(4), + Core.PartialStruct(𝕃, Foo, Any[Core.PartialStruct(𝕃, Tuple{Float64}, Any[Incidence(5)])]) ]) @test aggressive_incidence_join(Const(0.0), type_differs.fields) == f4f5 - type_same = Core.PartialStruct(Foo, Any[l4l5, - Core.PartialStruct(Foo, Any[Core.PartialStruct(Tuple{Float64}, Any[l4l5])]) + type_same = Core.PartialStruct(𝕃, Foo, Any[l4l5, + Core.PartialStruct(𝕃, Foo, Any[Core.PartialStruct(𝕃, Tuple{Float64}, Any[l4l5])]) ]) @test aggressive_incidence_join(Const(0.0), type_same.fields) == l4l5 - type_overlaps = Core.PartialStruct(Foo, Any[Incidence(5), - Core.PartialStruct(Foo, Any[Core.PartialStruct(Tuple{Float64}, Any[l4l5])]) + type_overlaps = Core.PartialStruct(𝕃, Foo, Any[Incidence(5), + Core.PartialStruct(𝕃, Foo, Any[Core.PartialStruct(𝕃, Tuple{Float64}, Any[l4l5])]) ]) @test aggressive_incidence_join(Const(0.0), type_overlaps.fields) == f4l5 - type_overlaps_rev = Core.PartialStruct(Foo, Any[l4l5, - Core.PartialStruct(Foo, Any[Core.PartialStruct(Tuple{Float64}, Any[Incidence(5)])]) + type_overlaps_rev = Core.PartialStruct(𝕃, Foo, Any[l4l5, + Core.PartialStruct(𝕃, Foo, Any[Core.PartialStruct(𝕃, Tuple{Float64}, Any[Incidence(5)])]) ]) @test aggressive_incidence_join(Const(0.0), type_overlaps_rev.fields) == f4l5 end -let 𝕃 = CC.optimizer_lattice(DAECompiler.DAEInterpreter(Base.get_world_counter())) - CC.tmeet(𝕃, DAECompiler.Eq(1), DAECompiler.equation) === DAECompiler.Eq(1) -end +@test CC.tmeet(𝕃, DAECompiler.Eq(1), DAECompiler.equation) === DAECompiler.Eq(1) end # module diff --git a/test/control.jl b/test/control.jl index e0e113d..f70449e 100644 --- a/test/control.jl +++ b/test/control.jl @@ -46,7 +46,7 @@ let sys = IRODESystem(Tuple{typeof(control_dependent_taint)}) (; ir) = DAECompiler.StructuralAnalysisResult(sys) for i = 1:length(ir.stmts) inst = ir.stmts[i] - if isa(inst[:inst], Core.Compiler.PhiNode) + if isa(inst[:inst], Core.PhiNode) TT = inst[:type] @test isa(TT, DAECompiler.Incidence) @test !iszero(TT.row[2]) @@ -105,7 +105,7 @@ let sys = IRODESystem(Tuple{typeof(multi_control)}) (; ir) = DAECompiler.StructuralAnalysisResult(sys) for i = 1:length(ir.stmts) inst = ir.stmts[i] - if isa(inst[:inst], Core.Compiler.PhiNode) + if isa(inst[:inst], Core.PhiNode) TT = inst[:type] @test isa(TT, DAECompiler.Incidence) @test !iszero(TT.row[3]) diff --git a/test/interpreter.jl b/test/interpreter.jl index c8b73c7..bc3f8bd 100644 --- a/test/interpreter.jl +++ b/test/interpreter.jl @@ -3,16 +3,18 @@ module interpreter using Test using DAECompiler using DAECompiler: Incidence, DAEInterpreter, get_toplevel_mi_from_ir -using Core.Compiler: IRCode, IncrementalCompact, NewInstruction, Argument, insert_node_here! +import Compiler +const CC = Compiler +using .CC: IRCode, IncrementalCompact, NewInstruction, Argument, insert_node_here! include(joinpath(Base.pkgdir(DAECompiler), "test", "lorenz.jl")) function has_dae_intrinsics(interp::DAEInterpreter, @nospecialize(tt)) match = Base._which(tt) - mi = Core.Compiler.specialize_method(match) + mi = CC.specialize_method(match) return has_dae_intrinsics(interp, mi) end function has_dae_intrinsics(interp::DAEInterpreter, mi::Core.MethodInstance) - codeinst = Core.Compiler.getindex(Core.Compiler.code_cache(interp), mi) + codeinst = CC.getindex(CC.code_cache(interp), mi) inferred = (@atomic :monotonic codeinst.inferred)::DAECompiler.DAECache return inferred.info.has_dae_intrinsics end @@ -27,8 +29,6 @@ end # tfunc tests -const CC = Core.Compiler - """ Returns a MethodInstance and IR corresponding to an abstract call to `f(::types[1], ::types[2], ::types[3], ...)` where types can include diff --git a/test/invalidation.jl b/test/invalidation.jl index 1e34f13..4eb707e 100644 --- a/test/invalidation.jl +++ b/test/invalidation.jl @@ -4,6 +4,7 @@ using Test using DAECompiler, StateSelection, SciMLBase, OrdinaryDiffEq, Sundials using DAECompiler: equation!, state_ddt, variables +import Compiler const results1 = Number[] const results2 = Number[] @@ -57,15 +58,15 @@ function isfunc(name::Symbol) end # check if there are cached analysis results -let cache = Core.Compiler.code_cache(interp) - mi1 = Core.Compiler.specialize_method( +let cache = Compiler.code_cache(interp) + mi1 = Base.specialize_method( only(methods(βŠ–)), Tuple{typeof(βŠ–),Float64,Float64}, Core.svec()) - @test Core.Compiler.haskey(cache, mi1) - @test Core.Compiler.getindex(cache, mi1).max_world == typemax(UInt) - mi2 = Core.Compiler.specialize_method( + @test Compiler.haskey(cache, mi1) + @test Compiler.getindex(cache, mi1).max_world == typemax(UInt) + mi2 = Base.specialize_method( only(methods(⊟)), Tuple{typeof(⊟),Float64,Float64}, Core.svec()) - @test Core.Compiler.haskey(cache, mi2) - @test Core.Compiler.getindex(cache, mi2).max_world == typemax(UInt) + @test Compiler.haskey(cache, mi2) + @test Compiler.getindex(cache, mi2).max_world == typemax(UInt) end x::Number ⊟ y::Number = begin # now redefine it @@ -75,14 +76,14 @@ x::Number ⊟ y::Number = begin # now redefine it end # check if the cached analysis results are invalidated -let cache = Core.Compiler.code_cache(interp) - mi1 = Core.Compiler.specialize_method( +let cache = Compiler.code_cache(interp) + mi1 = Compiler.specialize_method( only(methods(βŠ–)), Tuple{typeof(βŠ–),Float64,Float64}, Core.svec()) - @test Core.Compiler.haskey(cache, mi1) - @test Core.Compiler.getindex(cache, mi1).max_world != typemax(UInt) - mi2 = Core.Compiler.specialize_method( + @test Compiler.haskey(cache, mi1) + @test Compiler.getindex(cache, mi1).max_world != typemax(UInt) + mi2 = Compiler.specialize_method( last(sort(methods(⊟); by=x->x.primary_world)), Tuple{typeof(⊟),Float64,Float64}, Core.svec()) - @test !Core.Compiler.haskey(cache, mi2) + @test !Compiler.haskey(cache, mi2) end empty!(results1); empty!(results2); diff --git a/test/irutils.jl b/test/irutils.jl index 24ad030..2b39243 100644 --- a/test/irutils.jl +++ b/test/irutils.jl @@ -1,9 +1,10 @@ using Core: CodeInfo, ReturnNode, MethodInstance -using Core.Compiler: IRCode, IncrementalCompact, singleton_type, VarState +import Compiler +using Compiler: IRCode, IncrementalCompact, singleton_type, VarState using Base.Meta: isexpr using InteractiveUtils: gen_call_with_extracted_types_and_kwargs -argextype(@nospecialize args...) = Core.Compiler.argextype(args...) +argextype(@nospecialize args...) = Compiler.argextype(args...) argextype(@nospecialize(x), src::CodeInfo) = argextype(x, src, VarState[]) code_typed1(args...; kwargs...) = first(only(code_typed(args...; kwargs...)))::CodeInfo macro code_typed1(ex0...) diff --git a/test/regression.jl b/test/regression.jl index 234c6ae..9df16b2 100644 --- a/test/regression.jl +++ b/test/regression.jl @@ -6,7 +6,8 @@ using DAECompiler.Intrinsics using SciMLBase using OrdinaryDiffEq, Sundials using ForwardDiff -const CC = Core.Compiler +import Compiler +const CC = Compiler include(joinpath(Base.pkgdir(DAECompiler), "test/testutils.jl")) @@ -44,16 +45,16 @@ let sys = IRODESystem(Tuple{typeof(regression_setproperty)}); # tmerge that results in a union let T = CC.tmerge(βΌ•πŸ₯¬, CC.Const(0.0), - CC.PartialStruct(Tuple{Float64, Float64}, Any[DAECompiler.Incidence(1), DAECompiler.Incidence(1)])) + CC.PartialStruct(βΌ•πŸ₯¬, Tuple{Float64, Float64}, Any[DAECompiler.Incidence(1), DAECompiler.Incidence(1)])) @test isa(T, DAECompiler.Incidence) @test T.typ == Union{Float64, Tuple{Float64, Float64}} end # tmerge nested struct that results in union let T = CC.tmerge(βΌ•πŸ₯¬, - CC.PartialStruct(Tuple{Float64, Tuple{Float64}}, + CC.PartialStruct(βΌ•πŸ₯¬, Tuple{Float64, Tuple{Float64}}, Any[DAECompiler.Incidence(1), - CC.PartialStruct(Tuple{Float64}, Any[DAECompiler.Incidence(2)])]), + CC.PartialStruct(βΌ•πŸ₯¬, Tuple{Float64}, Any[DAECompiler.Incidence(2)])]), Core.Const(1.0)) @test isa(T, DAECompiler.Incidence) @test T.typ == Union{Float64, Tuple{Float64, Tuple{Float64}}} @@ -62,8 +63,8 @@ let sys = IRODESystem(Tuple{typeof(regression_setproperty)}); # tmerge for partial structs let T = CC.tmerge(βΌ•πŸ₯¬, - CC.PartialStruct(NTuple{3, Float64}, Any[DAECompiler.Incidence(1), DAECompiler.Incidence(2), Core.Const(0.0)]), - CC.PartialStruct(NTuple{3, Float64}, Any[DAECompiler.Incidence(2), DAECompiler.Incidence(1), Core.Const(0.0)])) + CC.PartialStruct(βΌ•πŸ₯¬, NTuple{3, Float64}, Any[DAECompiler.Incidence(1), DAECompiler.Incidence(2), Core.Const(0.0)]), + CC.PartialStruct(βΌ•πŸ₯¬, NTuple{3, Float64}, Any[DAECompiler.Incidence(2), DAECompiler.Incidence(1), Core.Const(0.0)])) @test isa(T, CC.PartialStruct) && isa(T.fields[1], DAECompiler.Incidence) end @@ -86,7 +87,7 @@ let sys = IRODESystem(Tuple{typeof(regression_setproperty)}); end # tmerge should lose PartialStruct - PT = Core.PartialStruct(Tuple{Float64, Float64}, Any[Core.Const(1.0), Float64]) + PT = Core.PartialStruct(βΌ•πŸ₯¬, Tuple{Float64, Float64}, Any[Core.Const(1.0), Float64]) let T = CC.tmerge(βΌ•πŸ₯¬, Union{}, PT) @test T === PT end diff --git a/test/transform_common.jl b/test/transform_common.jl index fe57a60..abec2c7 100644 --- a/test/transform_common.jl +++ b/test/transform_common.jl @@ -4,6 +4,7 @@ using DAECompiler: IRODESystem, TransformedIRODESystem using DAECompiler.Intrinsics using DAECompiler.Intrinsics: state_ddt using Test +import Compiler @testset "checked_intrinstics_removed + replace_if_intrinsic" begin function foo() @@ -26,12 +27,12 @@ using Test p = nothing t = 0.5 var_assignment = Dict(1=>(1,false), 2=>(2,false)) - compact = Core.Compiler.IncrementalCompact(ir) + compact = Compiler.IncrementalCompact(ir) for ((_, idx), stmt) in compact ssa = Core.SSAValue(idx) DAECompiler.replace_if_intrinsic!(compact, ssa, du, u, p, t, var_assignment) end - ir = Core.Compiler.finish(compact) + ir = Compiler.finish(compact) # the following should not throw anymore @test DAECompiler.check_for_daecompiler_intrinstics(ir) isa Any