Skip to content

Improve DebugInfo source provenance #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
569e077
Misc refactors, insert internal stmt debuginfo
serenity4 Jun 4, 2025
7b25b96
Add slotnames info
serenity4 Jun 4, 2025
676875a
Refactor naming of locals for ODE codegen
serenity4 Jun 4, 2025
eadfca7
Add comment
serenity4 Jun 4, 2025
3cd1d4f
Merge branch 'main' of github.com:JuliaComputing/DAECompiler.jl into …
serenity4 Jun 6, 2025
16c19ed
Apply DebugInfo at top-level
serenity4 Jun 6, 2025
21ea3d4
Remove `insert_ssa_debuginfo` setting
serenity4 Jun 6, 2025
866480d
Marshall settings everywhere
serenity4 Jun 6, 2025
427c108
Add maybe_insert_debuginfo
serenity4 Jun 6, 2025
7ad9e5c
Disable crashing tests
serenity4 Jun 6, 2025
b0b188f
Propagate source information for `insert_node_here!(...)`
serenity4 Jun 6, 2025
f0bd023
Add source provenance to DAE/Init codegen
serenity4 Jun 6, 2025
c7328b4
Use `__SOURCE__` macro for `replace_call!`
serenity4 Jun 6, 2025
4781765
Update `replace_call!` with source information in index_lowering.jl
serenity4 Jun 6, 2025
e8cb8ce
Default `insert_stmt_debuginfo` to `false` for reflection tools
serenity4 Jun 6, 2025
1465a81
Remove accidental code inclusion
serenity4 Jun 6, 2025
4196e65
Don't seek previous codeloc
serenity4 Jun 9, 2025
b9cc48a
Merge branch 'main' of github.com:JuliaComputing/DAECompiler.jl into …
serenity4 Jun 9, 2025
72b46bd
Remove unused code
serenity4 Jun 9, 2025
446d80c
Reenable IPO tests
serenity4 Jun 9, 2025
2d423bf
[DO NOT MERGE] Temporarily dev ConstructionBase for CI
serenity4 Jun 9, 2025
1f2fcb4
Work around `invokelatest` issue
serenity4 Jun 9, 2025
8eac9a9
Only wrap `string` call in `try`/`catch`
serenity4 Jun 9, 2025
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: 21 additions & 19 deletions Manifest.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CentralizedCaches = "d1073d05-2d26-4019-b855-dfa0385fef5e"
ChainRules = "082447d4-558c-5d27-93f4-14fc19e9eca2"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Compiler = "807dbc54-b67e-4c79-8afb-eafe4df6f2e1"
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
Cthulhu = "f68482b8-f384-11e8-15f7-abe071a5a75f"
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
DiffEqCallbacks = "459566f4-90b8-5000-8ac3-15dfb0a30def"
Expand Down Expand Up @@ -46,6 +47,7 @@ ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"

[sources]
Compiler = {rev = "master", url = "https://github.com/JuliaLang/BaseCompiler.jl.git"}
ConstructionBase = {rev = "rebase_PR_100", url = "https://github.com/nsajko/ConstructionBase.jl"}
Cthulhu = {rev = "master", url = "https://github.com/JuliaDebug/Cthulhu.jl.git"}
DifferentiationInterface = {rev = "main", subdir = "DifferentiationInterface", url = "https://github.com/Keno/DifferentiationInterface.jl"}
Diffractor = {rev = "main", url = "https://github.com/JuliaDiff/Diffractor.jl.git"}
Expand All @@ -59,6 +61,7 @@ CentralizedCaches = "1.1.0"
ChainRules = "1.50"
ChainRulesCore = "1.20"
Compiler = "0"
ConstructionBase = "1.5.9"
DiffEqBase = "6.149.2"
DifferentiationInterface = "0.6.52"
Diffractor = "0.2.7"
Expand Down
2 changes: 1 addition & 1 deletion src/DAECompiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module DAECompiler
using Diffractor
using OrderedCollections
using Compiler
using Compiler: IRCode, IncrementalCompact, argextype, singleton_type, isexpr, widenconst
using Compiler: IRCode, IncrementalCompact, DebugInfoStream, argextype, singleton_type, isexpr, widenconst
using Core.IR
using SciMLBase
using AutoHashEquals
Expand Down
34 changes: 18 additions & 16 deletions src/analysis/flattening.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function _flatten_parameter!(𝕃, compact, argtypes, ntharg, line)
function _flatten_parameter!(𝕃, compact, argtypes, ntharg, line, settings)
list = Any[]
for (argn, argt) in enumerate(argtypes)
if isa(argt, Const)
Expand All @@ -18,22 +18,20 @@ function _flatten_parameter!(𝕃, compact, argtypes, ntharg, line)
continue
end
this = ntharg(argn)
nthfield(i) = insert_node_here!(compact,
NewInstruction(Expr(:call, getfield, this, i), Compiler.getfield_tfunc(𝕃, argextype(this, compact), Const(i)), line))
nthfield(i) = @insert_node_here compact line settings getfield(this, i)::Compiler.getfield_tfunc(𝕃, argextype(this, compact), Const(i))
if isa(argt, PartialStruct)
fields = _flatten_parameter!(𝕃, compact, argt.fields, nthfield, line)
fields = _flatten_parameter!(𝕃, compact, argt.fields, nthfield, line, settings)
else
fields = _flatten_parameter!(𝕃, compact, fieldtypes(argt), nthfield, line)
fields = _flatten_parameter!(𝕃, compact, fieldtypes(argt), nthfield, line, settings)
end
append!(list, fields)
end
end
return list
end

function flatten_parameter!(𝕃, compact, argtypes, ntharg, line)
return insert_node_here!(compact,
NewInstruction(Expr(:call, tuple, _flatten_parameter!(𝕃, compact, argtypes, ntharg, line)...), Tuple, line))
function flatten_parameter!(𝕃, compact, argtypes, ntharg, line, settings)
return @insert_node_here compact line settings tuple(_flatten_parameter!(𝕃, compact, argtypes, ntharg, line, settings)...)::Tuple
end

# Needs to match flatten_arguments!
Expand Down Expand Up @@ -76,7 +74,7 @@ struct TransformedArg
TransformedArg(@nospecialize(arg), new_offset::Int, new_eqoffset::Int) = new(arg, new_offset, new_eqoffset)
end

function flatten_argument!(compact::Compiler.IncrementalCompact, @nospecialize(argt), offset::Int, eqoffset::Int, argtypes::Vector{Any})::TransformedArg
function flatten_argument!(compact::Compiler.IncrementalCompact, settings::Settings, @nospecialize(argt), offset::Int, eqoffset::Int, argtypes::Vector{Any})::TransformedArg
@assert !isa(argt, Incidence) && !isa(argt, Eq)
if isa(argt, Const)
return TransformedArg(argt.val, offset, eqoffset)
Expand All @@ -86,28 +84,32 @@ function flatten_argument!(compact::Compiler.IncrementalCompact, @nospecialize(a
push!(argtypes, argt)
return TransformedArg(Argument(offset+1), offset+1, eqoffset)
elseif argt === equation
ssa = insert_node_here!(compact, NewInstruction(Expr(:invoke, nothing, InternalIntrinsics.external_equation), Eq(eqoffset+1), compact[Compiler.OldSSAValue(1)][:line]))
line = compact[Compiler.OldSSAValue(1)][:line]
ssa = @insert_node_here compact line settings (:invoke)(nothing, InternalIntrinsics.external_equation)::Eq(eqoffset+1)
return TransformedArg(ssa, offset, eqoffset+1)
elseif isabstracttype(argt) || ismutabletype(argt) || (!isa(argt, DataType) && !isa(argt, PartialStruct))
ssa = insert_node_here!(compact, NewInstruction(Expr(:call, error, "Cannot IPO model arg type $argt"), Union{}, compact[Compiler.OldSSAValue(1)][:line]))
line = compact[Compiler.OldSSAValue(1)][:line]
ssa = @insert_node_here compact line settings error("Cannot IPO model arg type $argt")::Union{}
return TransformedArg(ssa, -1, eqoffset)
else
if !isa(argt, PartialStruct) && Base.datatype_fieldcount(argt) === nothing
ssa = insert_node_here!(compact, NewInstruction(Expr(:call, error, "Cannot IPO model arg type $argt"), Union{}, compact[Compiler.OldSSAValue(1)][:line]))
line = compact[Compiler.OldSSAValue(1)][:line]
ssa = @insert_node_here compact line settings error("Cannot IPO model arg type $argt")::Union{}
return TransformedArg(ssa, -1, eqoffset)
end
(args, _, offset) = flatten_arguments!(compact, isa(argt, PartialStruct) ? argt.fields : collect(Any, fieldtypes(argt)), offset, eqoffset, argtypes)
(args, _, offset) = flatten_arguments!(compact, settings, isa(argt, PartialStruct) ? argt.fields : collect(Any, fieldtypes(argt)), offset, eqoffset, argtypes)
offset == -1 && return TransformedArg(ssa, -1, eqoffset)
this = Expr(:new, isa(argt, PartialStruct) ? argt.typ : argt, args...)
ssa = insert_node_here!(compact, NewInstruction(this, argt, compact[Compiler.OldSSAValue(1)][:line]))
line = compact[Compiler.OldSSAValue(1)][:line]
ssa = @insert_node_here compact line settings this::argt
return TransformedArg(ssa, offset, eqoffset)
end
end

function flatten_arguments!(compact::Compiler.IncrementalCompact, argtypes::Vector{Any}, offset::Int=0, eqoffset::Int=0, new_argtypes::Vector{Any} = Any[])
function flatten_arguments!(compact::Compiler.IncrementalCompact, settings::Settings, argtypes::Vector{Any}, offset::Int=0, eqoffset::Int=0, new_argtypes::Vector{Any} = Any[])
args = Any[]
for argt in argtypes
(; ssa, offset, eqoffset) = flatten_argument!(compact, argt, offset, eqoffset, new_argtypes)
(; ssa, offset, eqoffset) = flatten_argument!(compact, settings, argt, offset, eqoffset, new_argtypes)
offset == -1 && break
push!(args, ssa)
end
Expand Down
3 changes: 2 additions & 1 deletion src/analysis/refiner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ of structural incidence information.
"""
struct StructuralRefiner <: Compiler.AbstractInterpreter
world::UInt
settings::Settings
var_to_diff::DiffGraph
varkinds::Vector{Intrinsics.VarKind}
varclassification::Vector{VarEqClassification}
Expand Down Expand Up @@ -51,7 +52,7 @@ Compiler.cache_owner(::StructuralRefiner) = StructureCache()
end

callee_codeinst = invokee::CodeInstance
callee_result = structural_analysis!(callee_codeinst, Compiler.get_inference_world(interp))
callee_result = structural_analysis!(callee_codeinst, Compiler.get_inference_world(interp), interp.settings)

if isa(callee_result, UncompilableIPOResult) || isa(callee_result.extended_rt, Const) || isa(callee_result.extended_rt, Type)
# If this is uncompilable, we will be notfiying the user in the outer loop - here we just ignore it
Expand Down
Loading