Skip to content

Commit 5145ae5

Browse files
committed
Adjust to compiler excision
1 parent f792e6f commit 5145ae5

22 files changed

+162
-168
lines changed

Manifest.toml

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

Project.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
1111
CentralizedCaches = "d1073d05-2d26-4019-b855-dfa0385fef5e"
1212
ChainRules = "082447d4-558c-5d27-93f4-14fc19e9eca2"
1313
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
14+
Compiler = "807dbc54-b67e-4c79-8afb-eafe4df6f2e1"
1415
Cthulhu = "f68482b8-f384-11e8-15f7-abe071a5a75f"
1516
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
1617
DiffEqCallbacks = "459566f4-90b8-5000-8ac3-15dfb0a30def"
@@ -33,17 +34,17 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
3334
StateSelection = "64909d44-ed92-46a8-bbd9-f047dfbdc84b"
3435
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
3536
Sundials = "c3572dad-4567-51f8-b174-8c6c989267f4"
37+
SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5"
3638
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
3739
Tracy = "e689c965-62c8-4b79-b2c5-8359227902fd"
38-
SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5"
40+
41+
[weakdeps]
42+
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
3943

4044
[sources]
4145
SciMLBase = {rev = "os/dae-get-du2", url = "https://github.com/CedarEDA/SciMLBase.jl"}
4246
SciMLSensitivity = {rev = "kf/mindep2", url = "https://github.com/CedarEDA/SciMLSensitivity.jl"}
4347

44-
[weakdeps]
45-
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
46-
4748
[extensions]
4849
DAECompilerModelingToolkitExt = "ModelingToolkit"
4950

@@ -52,6 +53,7 @@ Accessors = "0.1.36"
5253
CentralizedCaches = "1.1.0"
5354
ChainRules = "1.50"
5455
ChainRulesCore = "1.20"
56+
Compiler = "0.0.1"
5557
Cthulhu = "2.10.1"
5658
DiffEqBase = "6.149.2"
5759
Diffractor = "0.2.7"

src/DAECompiler.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ function reconstruct_sensitivities(args...)
1919
error("This method requires SciMLSensitivity")
2020
end
2121

22-
const CC = Core.Compiler
22+
import Compiler
23+
const CC = Compiler
2324
import .CC: get_inference_world
2425
using Base: get_world_counter
2526

src/analysis/compiler.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using ForwardDiff
22
using Base.Meta
33
using Graphs
44
using Core.IR
5-
using Core.Compiler: InferenceState, bbidxiter, dominates, tmerge, typeinf_lattice
5+
using .CC: InferenceState, bbidxiter, dominates, tmerge, typeinf_lattice
66

77
@breadcrumb "ir_levels" function run_dae_passes(
88
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
317317
has_any_genscope(sc::PartialScope) = false
318318
has_any_genscope(sc::PartialStruct) = false # TODO
319319

320-
function _make_argument_lattice_elem(which::Argument, @nospecialize(argt), add_variable!, add_equation!, add_scope!)
320+
function _make_argument_lattice_elem(𝕃, which::Argument, @nospecialize(argt), add_variable!, add_equation!, add_scope!)
321321
if isa(argt, Const)
322322
#@assert !isa(argt.val, Scope) # Shouldn't have been forwarded
323323
return argt
@@ -331,7 +331,7 @@ function _make_argument_lattice_elem(which::Argument, @nospecialize(argt), add_v
331331
inc = Incidence(add_variable!(which))
332332
return argt === Float64 ? inc : Incidence(argt, inc.row, inc.eps)
333333
elseif isa(argt, PartialStruct)
334-
return PartialStruct(argt.typ, Any[make_argument_lattice_elem(which, f, add_variable!, add_equation!, add_scope!) for f in argt.fields])
334+
return PartialStruct(𝕃, argt.typ, Any[make_argument_lattice_elem(𝕃, which, f, add_variable!, add_equation!, add_scope!) for f in argt.fields])
335335
elseif isabstracttype(argt) || ismutabletype(argt) || !isa(argt, DataType)
336336
return nothing
337337
else
@@ -344,20 +344,20 @@ function _make_argument_lattice_elem(which::Argument, @nospecialize(argt), add_v
344344
for i = 1:length(fieldtypes(argt))
345345
# TODO: Can we make this lazy?
346346
ft = fieldtype(argt, i)
347-
mft = _make_argument_lattice_elem(which, ft, add_variable!, add_equation!, add_scope!)
347+
mft = _make_argument_lattice_elem(𝕃, which, ft, add_variable!, add_equation!, add_scope!)
348348
if mft === nothing
349349
push!(fields, Incidence(ft))
350350
else
351351
any = true
352352
push!(fields, mft)
353353
end
354354
end
355-
return any ? PartialStruct(argt, fields) : nothing
355+
return any ? PartialStruct(𝕃, argt, fields) : nothing
356356
end
357357
end
358358

359-
function make_argument_lattice_elem(which::Argument, @nospecialize(argt), add_variable!, add_equation!, add_scope!)
360-
mft = _make_argument_lattice_elem(which, argt, add_variable!, add_equation!, add_scope!)
359+
function make_argument_lattice_elem(𝕃, which::Argument, @nospecialize(argt), add_variable!, add_equation!, add_scope!)
360+
mft = _make_argument_lattice_elem(𝕃, which, argt, add_variable!, add_equation!, add_scope!)
361361
mft === nothing ? Incidence(argt) : mft
362362
end
363363

@@ -532,7 +532,7 @@ end
532532
nexternalvars = 0 # number of variables that we expect to come in
533533
nexternaleqs = 0 # number of equation references that we expect to come in
534534
if caller !== nothing
535-
argtypes = Any[make_argument_lattice_elem(Argument(i), argt, add_variable!, add_equation!, add_scope!) for (i, argt) in enumerate(ir.argtypes)]
535+
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)]
536536
nexternalvars = length(var_to_diff)
537537
nexternaleqs = length(eqssas)
538538
else
@@ -571,7 +571,7 @@ end
571571
end
572572
end
573573

574-
cur_scope_lattice = PartialStruct(Base.ScopedValues.Scope,
574+
cur_scope_lattice = PartialStruct(CC.typeinf_lattice(interp), Base.ScopedValues.Scope,
575575
Any[PartialKeyValue(Incidence(Base.PersistentDict{Base.ScopedValues.ScopedValue, Any}))])
576576

577577
# Scan the IR, computing equations, variables, diffgraph, etc.
@@ -1017,7 +1017,7 @@ end
10171017
for eq = 1:length(result.eq_kind)
10181018
mapped_eq = mapping.eqs[eq]
10191019
mapped_eq == 0 && continue
1020-
mapped_inc = apply_linear_incidence(result.total_incidence[eq], result, var_to_diff, var_kind, eq_kind, mapping)
1020+
mapped_inc = apply_linear_incidence(CC.typeinf_lattice(interp), result.total_incidence[eq], result, var_to_diff, var_kind, eq_kind, mapping)
10211021
if isassigned(total_incidence, mapped_eq)
10221022
total_incidence[mapped_eq] = tfunc(Val(Core.Intrinsics.add_float),
10231023
total_incidence[mapped_eq],
@@ -1033,7 +1033,7 @@ end
10331033

10341034
for (ieq, inc) in enumerate(result.total_incidence[(result.nexternaleqs+1):end])
10351035
mapping.eqs[ieq] == 0 || continue
1036-
push!(total_incidence, apply_linear_incidence(inc, result, var_to_diff, var_kind, eq_kind, mapping))
1036+
push!(total_incidence, apply_linear_incidence(CC.typeinf_lattice(interp), inc, result, var_to_diff, var_kind, eq_kind, mapping))
10371037
push!(eq_callee_mapping, [SSAValue(i)=>ieq])
10381038
push!(eq_kind, CalleeInternal)
10391039
mapping.eqs[ieq] = length(total_incidence)
@@ -1115,7 +1115,7 @@ end
11151115

11161116
nimplicitoutpairs = 0
11171117
if caller !== nothing
1118-
ultimate_rt, nimplicitoutpairs = process_ipo_return!(ultimate_rt, eq_kind, var_kind,
1118+
ultimate_rt, nimplicitoutpairs = process_ipo_return!(CC.typeinf_lattice(interp), ultimate_rt, eq_kind, var_kind,
11191119
var_to_diff, total_incidence, eq_callee_mapping)
11201120
end
11211121

@@ -1135,7 +1135,7 @@ end
11351135
Dict{TornCacheKey, CodeInstance}())
11361136
end
11371137

1138-
function process_ipo_return!(ultimate_rt::Incidence, eq_kind, var_kind, var_to_diff, total_incidence, eq_callee_mapping)
1138+
function process_ipo_return!(𝕃, ultimate_rt::Incidence, eq_kind, var_kind, var_to_diff, total_incidence, eq_callee_mapping)
11391139
nonlinrepl = nothing
11401140
nimplicitoutpairs = 0
11411141
function get_nonlinrepl()
@@ -1179,20 +1179,20 @@ function process_ipo_return!(ultimate_rt::Incidence, eq_kind, var_kind, var_to_d
11791179
return ultimate_rt, nimplicitoutpairs
11801180
end
11811181

1182-
function process_ipo_return!(ultimate_rt::Eq, eq_kind, args...)
1182+
function process_ipo_return!(𝕃, ultimate_rt::Eq, eq_kind, args...)
11831183
eq_kind[ultimate_rt.id] = External
11841184
return ultimate_rt, 0
11851185
end
1186-
process_ipo_return!(ultimate_rt::Union{Type, PartialScope, PartialKeyValue, Const}, args...) = ultimate_rt, 0
1187-
function process_ipo_return!(ultimate_rt::PartialStruct, args...)
1186+
process_ipo_return!(𝕃, ultimate_rt::Union{Type, PartialScope, PartialKeyValue, Const}, args...) = ultimate_rt, 0
1187+
function process_ipo_return!(𝕃, ultimate_rt::PartialStruct, args...)
11881188
nimplicitoutpairs = 0
11891189
fields = Any[]
11901190
for f in ultimate_rt.fields
1191-
(rt, n) = process_ipo_return!(f, args...)
1191+
(rt, n) = process_ipo_return!(𝕃, f, args...)
11921192
nimplicitoutpairs += n
11931193
push!(fields, rt)
11941194
end
1195-
return PartialStruct(ultimate_rt.typ, fields), nimplicitoutpairs
1195+
return PartialStruct(𝕃, ultimate_rt.typ, fields), nimplicitoutpairs
11961196
end
11971197

11981198
function get_variable_name(names::OrderedDict, var_to_diff, var_idx)

src/analysis/compiler_reexports.jl

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,9 @@
11
using Core.IR
2-
using Core.Compiler: IRCode, Instruction, InstructionStream, IncrementalCompact,
2+
using .CC: IRCode, Instruction, InstructionStream, IncrementalCompact,
33
NewInstruction, DomTree, BBIdxIter, AnySSAValue, UseRef, UseRefIterator,
44
block_for_inst, cfg_simplify!, is_known_call, argextype, getfield_tfunc, finish,
55
singleton_type, widenconst, dominates_ssa, , userefs
66

7-
# TODO: This really needs to go into a uniform compiler stdlib.
8-
Base.iterate(compact::IncrementalCompact, state) = Core.Compiler.iterate(compact, state)
9-
Base.iterate(compact::IncrementalCompact) = Core.Compiler.iterate(compact)
10-
Base.iterate(abu::CC.AbsIntStackUnwind, state...) = CC.iterate(abu, state...)
11-
12-
Base.setindex!(compact::IncrementalCompact, @nospecialize(v), idx::SSAValue) = Core.Compiler.setindex!(compact,v,idx)
13-
Base.setindex!(ir::IRCode, @nospecialize(v), idx::SSAValue) = Core.Compiler.setindex!(ir,v,idx)
14-
Base.setindex!(inst::Instruction, @nospecialize(v), sym::Symbol) = Core.Compiler.setindex!(inst,v,sym)
15-
Base.getindex(compact::IncrementalCompact, idx::AnySSAValue) = Core.Compiler.getindex(compact,idx)
16-
17-
Base.setindex!(urs::InstructionStream, @nospecialize args...) = Core.Compiler.setindex!(urs, args...)
18-
Base.setindex!(ir::IRCode, @nospecialize args...) = Core.Compiler.setindex!(ir, args...)
19-
Base.getindex(ir::IRCode, @nospecialize args...) = Core.Compiler.getindex(ir, args...)
20-
21-
Base.IteratorSize(::Type{CC.AbsIntStackUnwind}) = Base.SizeUnknown()
22-
23-
# TODO: Move this to Core.Compiler
24-
CC.block_for_inst(ir::IRCode, s::SSAValue) = block_for_inst(ir, s.id)
257
function CC.dominates_ssa(ir::IRCode, domtree::DomTree, x::SSAValue, y::SSAValue; dominates_after=false)
268
xb = block_for_inst(ir, x)
279
yb = block_for_inst(ir, y)
@@ -82,6 +64,3 @@ function replace_argument!(compact::IncrementalCompact, idx::Int, argn::Argument
8264
compact[ssa] = urs[]
8365
end
8466

85-
Base.copy(phi::PhiNode) = Core.PhiNode(copy(phi.edges), copy(phi.values))
86-
Base.push!(bs::CC.BitSet, i::Int) = CC.push!(bs, i)
87-
Base.push!(bs::CC.BitSetBoundedMinPrioritySet, i::Int) = CC.push!(bs, i)

0 commit comments

Comments
 (0)