Skip to content

Commit e45136e

Browse files
committed
Add insert_ssa_debuginfo setting
1 parent 8eac9a9 commit e45136e

File tree

6 files changed

+53
-22
lines changed

6 files changed

+53
-22
lines changed

src/problem_interface.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,24 @@ function DAECProblem(f, init::Union{Vector, Tuple{Vararg{Pair}}}, tspan::Tuple{R
2424
guesses = nothing,
2525
force_inline_all=false,
2626
insert_stmt_debuginfo=false,
27+
insert_ssa_debuginfo=false,
2728
kwargs...)
28-
settings = Settings(; force_inline_all, insert_stmt_debuginfo)
29+
settings = Settings(; force_inline_all, insert_stmt_debuginfo, insert_ssa_debuginfo)
2930
DAECProblem(f, init, guesses, tspan, kwargs, settings, missing, nothing, nothing)
3031
end
3132

3233
function DAECProblem(f, tspan::Tuple{Real, Real} = (0., 1.);
3334
guesses = nothing,
3435
force_inline_all=false,
3536
insert_stmt_debuginfo=false,
37+
insert_ssa_debuginfo=false,
3638
kwargs...)
37-
settings = Settings(; force_inline_all, insert_stmt_debuginfo)
39+
settings = Settings(; force_inline_all, insert_stmt_debuginfo, insert_ssa_debuginfo)
3840
DAECProblem(f, nothing, guesses, tspan, kwargs, settings, missing, nothing, nothing)
3941
end
4042

4143
function DiffEqBase.get_concrete_problem(prob::DAECProblem, isadaptive; kwargs...)
42-
settings = Settings(; mode=prob.init === nothing ? DAE : DAENoInit, prob.settings.force_inline_all, prob.settings.insert_stmt_debuginfo)
44+
settings = Settings(; mode=prob.init === nothing ? DAE : DAENoInit, prob.settings.force_inline_all, prob.settings.insert_stmt_debuginfo, prob.insert_ssa_debuginfo)
4345
(daef, differential_vars) = factory(Val(settings), prob.f)
4446

4547
u0 = zeros(length(differential_vars))
@@ -74,22 +76,24 @@ function ODECProblem(f, init::Union{Vector, Tuple{Vararg{Pair}}}, tspan::Tuple{R
7476
guesses = nothing,
7577
force_inline_all=false,
7678
insert_stmt_debuginfo=false,
79+
insert_ssa_debuginfo=false,
7780
kwargs...)
78-
settings = Settings(; force_inline_all, insert_stmt_debuginfo)
81+
settings = Settings(; force_inline_all, insert_stmt_debuginfo, insert_ssa_debuginfo)
7982
ODECProblem(f, init, guesses, tspan, kwargs, settings, missing, nothing)
8083
end
8184

8285
function ODECProblem(f, tspan::Tuple{Real, Real} = (0., 1.);
8386
guesses = nothing,
8487
force_inline_all=false,
8588
insert_stmt_debuginfo=false,
89+
insert_ssa_debuginfo=false,
8690
kwargs...)
87-
settings = Settings(; force_inline_all, insert_stmt_debuginfo)
91+
settings = Settings(; force_inline_all, insert_stmt_debuginfo, insert_ssa_debuginfo)
8892
ODECProblem(f, nothing, guesses, tspan, kwargs, settings, missing, nothing)
8993
end
9094

9195
function DiffEqBase.get_concrete_problem(prob::ODECProblem, isadaptive; kwargs...)
92-
settings = Settings(; mode=prob.init === nothing ? ODE : ODENoInit, prob.settings.force_inline_all, prob.settings.insert_stmt_debuginfo)
96+
settings = Settings(; mode=prob.init === nothing ? ODE : ODENoInit, prob.settings.force_inline_all, prob.settings.insert_stmt_debuginfo, prob.insert_ssa_debuginfo)
9397
(odef, n) = factory(Val(settings), prob.f)
9498

9599
u0 = zeros(n)

src/reflection.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ end
2626
code_ad_by_type(@nospecialize(tt::Type); kwargs...) =
2727
_code_ad_by_type(tt; kwargs...).inferred.ir
2828

29-
function code_structure_by_type(@nospecialize(tt::Type); world::UInt = Base.tls_world_age(), result = false, matched = false, mode = DAE, force_inline_all = false, insert_stmt_debuginfo = false, kwargs...)
29+
function code_structure_by_type(@nospecialize(tt::Type); world::UInt = Base.tls_world_age(), result = false, matched = false, mode = DAE, force_inline_all = false, insert_stmt_debuginfo = false, insert_ssa_debuginfo = false, kwargs...)
3030
ci = _code_ad_by_type(tt; world, kwargs...)
31-
settings = Settings(; mode, force_inline_all, insert_stmt_debuginfo)
31+
settings = Settings(; mode, force_inline_all, insert_stmt_debuginfo, insert_ssa_debuginfo)
3232
_result = structural_analysis!(ci, world, settings)
3333
isa(_result, UncompilableIPOResult) && throw(_result.error)
3434
!matched && return result ? _result : _result.ir

src/settings.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ struct Settings
1313
mode::GenerationMode
1414
force_inline_all::Bool
1515
insert_stmt_debuginfo::Bool
16-
function Settings(mode, force_inline_all, insert_stmt_debuginfo)
17-
new(mode, force_inline_all, insert_stmt_debuginfo)
18-
end
16+
insert_ssa_debuginfo::Bool
1917
end
20-
Settings(; mode::GenerationMode=DAE, force_inline_all::Bool=false, insert_stmt_debuginfo::Bool=false) = Settings(mode, force_inline_all, insert_stmt_debuginfo)
18+
Settings(; mode::GenerationMode=DAE, force_inline_all::Bool=false, insert_stmt_debuginfo::Bool=false, insert_ssa_debuginfo::Bool=false) = Settings(mode, force_inline_all, insert_stmt_debuginfo, insert_ssa_debuginfo)

src/transform/common.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function ir_to_src(ir::IRCode, settings::Settings; slotnames = nothing)
6464
end
6565

6666
function maybe_rewrite_debuginfo!(ir::IRCode, settings::Settings)
67-
settings.insert_stmt_debuginfo && rewrite_debuginfo!(ir)
67+
settings.insert_ssa_debuginfo && rewrite_debuginfo!(ir)
6868
return ir
6969
end
7070

test/basic.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ sol = solve(DAECProblem(oneeq!, (1,) .=> 1.), IDA())
2424
sol = solve(ODECProblem(oneeq!, (1,) .=> 1.), Rodas5(autodiff=false))
2525
@test all(map((x,y)->isapprox(x[], y, atol=1e-2), sol.u[:, 1], exp.(sol.t)))
2626

27-
# Cover the `debuginfo` rewrite.
28-
sol = solve(DAECProblem(oneeq!, (1,) .=> 1., insert_stmt_debuginfo = true), IDA())
27+
# Cover the `debuginfo` rewrites.
28+
sol = solve(DAECProblem(oneeq!, (1,) .=> 1., insert_stmt_debuginfo = true, insert_ssa_debuginfo = true), IDA())
2929
@test all(map((x,y)->isapprox(x[], y, atol=1e-2), sol.u[:, 1], exp.(sol.t)))
30-
sol = solve(ODECProblem(oneeq!, (1,) .=> 1., insert_stmt_debuginfo = true), Rodas5(autodiff=false))
30+
sol = solve(ODECProblem(oneeq!, (1,) .=> 1., insert_stmt_debuginfo = true, insert_ssa_debuginfo = true), Rodas5(autodiff=false))
3131
@test all(map((x,y)->isapprox(x[], y, atol=1e-2), sol.u[:, 1], exp.(sol.t)))
3232

3333
#= + parameterized =#

test/debugging.jl

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Debugging
33
using Test
44
using DAECompiler
55
using DAECompiler.Intrinsics
6+
using InteractiveUtils: @code_typed
67
using Sundials
78
using SciMLBase
89
using OrdinaryDiffEq
@@ -26,24 +27,52 @@ end
2627
bt = catch_backtrace()
2728
end
2829
@test isa(exc, BoundsError)
29-
buffer = IOBuffer()
30-
Base.show_backtrace(buffer, bt)
31-
output = String(take!(seekstart(buffer)))
32-
@test contains(output, "inferred type: SubArray{Float64")
30+
output = sprint(Base.show_backtrace, bt)
31+
@test contains(output, "inferred type: SubArray{Float64") # insert_ssa_debuginfo
3332
end
3433

3534
# use a short `u0` to trigger an error and get a stacktrace
3635
u0 = Float64[0.0]
3736

38-
settings = DAECompiler.Settings(; mode = DAECompiler.ODENoInit, insert_stmt_debuginfo = true)
37+
settings = DAECompiler.Settings(; mode = DAECompiler.ODENoInit, insert_ssa_debuginfo = true)
3938
odef, _ = DAECompiler.factory(Val(settings), twoeq!)
4039
prob = ODEProblem(odef, u0, (0.0, 1.0))
4140
test_stmt_debuginfo(() -> solve(prob, Rodas5()))
4241

43-
settings = DAECompiler.Settings(; mode = DAECompiler.DAENoInit, insert_stmt_debuginfo = true)
42+
settings = DAECompiler.Settings(; mode = DAECompiler.DAENoInit, insert_ssa_debuginfo = true)
4443
daef, differential_vars = DAECompiler.factory(Val(settings), twoeq!)
4544
prob = DAEProblem(daef, u0, u0, (0.0, 1.0))
4645
test_stmt_debuginfo(() -> solve(prob, IDA()))
4746
end;
4847

48+
@testset "`DebugInfo`" begin
49+
settings = DAECompiler.Settings(; mode = DAECompiler.ODENoInit, insert_ssa_debuginfo = true)
50+
odef, _ = DAECompiler.factory(Val(settings), twoeq!)
51+
src = first(@code_typed debuginfo=:source odef.f(Float64[], Float64[], SciMLBase.NullParameters(), 1.0))
52+
output = sprint(show, src)
53+
@test contains(output, "inferred type:")
54+
55+
settings = DAECompiler.Settings(; mode = DAECompiler.DAENoInit, insert_ssa_debuginfo = true)
56+
daef, _ = DAECompiler.factory(Val(settings), twoeq!)
57+
src = first(@code_typed debuginfo=:source daef.f(Float64[], Float64[], Float64[], SciMLBase.NullParameters(), 1.0))
58+
output = sprint(show, src)
59+
@test contains(output, "inferred type:")
60+
61+
settings = DAECompiler.Settings(; mode = DAECompiler.ODENoInit, insert_stmt_debuginfo = true)
62+
odef, _ = DAECompiler.factory(Val(settings), twoeq!)
63+
src = first(@code_typed debuginfo=:source odef.f(Float64[], Float64[], SciMLBase.NullParameters(), 1.0))
64+
output = sprint(show, src)
65+
@test contains(output, "test/debugging.jl") && contains(output, "twoeq!")
66+
@test contains(output, "ode_factory.jl")
67+
@test contains(output, "intrinsics.jl") && contains(output, "continuous")
68+
69+
settings = DAECompiler.Settings(; mode = DAECompiler.DAENoInit, insert_stmt_debuginfo = true)
70+
daef, _ = DAECompiler.factory(Val(settings), twoeq!)
71+
src = first(@code_typed debuginfo=:source daef.f(Float64[], Float64[], Float64[], SciMLBase.NullParameters(), 1.0))
72+
output = sprint(show, src)
73+
@test contains(output, "test/debugging.jl") && contains(output, "twoeq!")
74+
@test contains(output, "dae_factory.jl")
75+
@test contains(output, "intrinsics.jl") && contains(output, "continuous")
76+
end;
77+
4978
end

0 commit comments

Comments
 (0)