Skip to content

Commit 81f24b8

Browse files
committed
Merge branch 'main' of github.com:JuliaComputing/DAECompiler.jl into incidence-lattice
2 parents fe9b3ad + b3de530 commit 81f24b8

File tree

11 files changed

+280
-21
lines changed

11 files changed

+280
-21
lines changed

src/analysis/ADAnalyzer.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ end
4747
return false
4848
end
4949
if isa(src, Compiler.OptimizationState)
50-
@show src.linfo
51-
@show src.src
50+
@sshow src.linfo
51+
@sshow src.src
5252
error()
5353
end
5454
if isa(src, AnalyzedSource)

src/analysis/refiner.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Compiler.cache_owner(::StructuralRefiner) = StructureCache()
4848
return RT(nothing, (false, true))
4949
end
5050

51-
callee_codeinst = invokee
51+
callee_codeinst = invokee::CodeInstance
5252
callee_result = structural_analysis!(callee_codeinst, Compiler.get_inference_world(interp))
5353

5454
if isa(callee_result, UncompilableIPOResult) || isa(callee_result.extended_rt, Const) || isa(callee_result.extended_rt, Type)

src/analysis/structural.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function _structural_analysis!(ci::CodeInstance, world::UInt)
141141
# every Expr(:new) uniquely corresponds to a scope identity, so this
142142
# is legal here (but not before)
143143
compact[SSAValue(i)][:stmt] = Intrinsics.ScopeIdentity()
144-
compact[SSAValue(i)][:flag] |= CC.IR_FLAG_REFINED
144+
compact[SSAValue(i)][:flag] |= Compiler.IR_FLAG_REFINED
145145
end
146146
continue
147147
elseif isexpr(stmt, :splatnew)
@@ -159,7 +159,7 @@ function _structural_analysis!(ci::CodeInstance, world::UInt)
159159
elseif stmt === nothing
160160
continue
161161
else
162-
@show stmt
162+
@sshow stmt
163163
end
164164
end
165165
ir = Compiler.finish(compact)

src/intrinsics.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ functions are:
1818
module Intrinsics
1919

2020
import ..@defintrmethod
21-
export continuous, discrete, epsilon, variable, equation, always, initial, initialguess, observed,
21+
export Scope, GenScope, continuous, discrete, epsilon, variable, equation, always, initial, initialguess, observed,
2222
always!, initial!, initialguess!, observed!, sim_time, ett!, pre, threshold, ddt
2323

2424
abstract type AbstractScope; end
@@ -303,7 +303,7 @@ module Intrinsics
303303
discrete(name::Symbol) = discrete(Scope(root_scope, name))
304304
discrete() = discrete(root_scope)
305305

306-
always() = equation(root_scope)
306+
always() = equation(Always, root_scope)
307307
always!(val, scope::AbstractScope=root_scope) = always(scope)(val)
308308
always!(val::Number, name::Symbol) = always!(val, Scope(root_scope, name))
309309
initial() = initial(root_scope)

src/reflection.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ 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(), kwargs...)
29+
function code_structure_by_type(@nospecialize(tt::Type); world::UInt = Base.tls_world_age(), result = false, kwargs...)
3030
ci = _code_ad_by_type(tt; world, kwargs...)
3131
# Perform or lookup DAECompiler specific analysis for this system.
32-
result = structural_analysis!(ci, world)
33-
isa(result, UncompilableIPOResult) && throw(result.error)
34-
return result.ir
32+
_result = structural_analysis!(ci, world)
33+
isa(_result, UncompilableIPOResult) && throw(_result.error)
34+
return result ? _result : _result.ir
3535
end
3636

3737

src/transform/codegen/init_uncompress.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function gen_init_uncompress!(
120120

121121
if is_known_invoke(stmt, variable, ir) || is_equation_call(stmt, ir)
122122
display(ir)
123-
@show stmt
123+
@sshow stmt
124124
error()
125125
elseif is_known_invoke(stmt, equation, ir)
126126
# Equation - used, but only as an arg to equation call, which will all get

src/transform/codegen/rhs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ function rhs_finish!(
187187
assgn = var_assignment[varnum]
188188
if assgn == nothing
189189
display(StateSelection.MatchedSystemStructure(structure, var_eq_matching))
190-
@show varnum
190+
@sshow varnum
191191
error("Variable left over in IR that doesn't have an assignment")
192192
end
193193
(kind, slot) = assgn

src/transform/tearing/schedule.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -795,10 +795,10 @@ function tearing_schedule!(state::TransformationState, ci::CodeInstance, key::To
795795
cstructure = make_structure_from_ipo(callee_result)
796796
cvar_eq_matching = matching_for_key(callee_result, callee_key, cstructure)
797797
display(StateSelection.MatchedSystemStructure(cstructure, cvar_eq_matching))
798-
@show eq_orders
799-
@show callee_result.total_incidence[callee_eq]
800-
@show total_incidence[caller_eq]
801-
@show callee_var_schedule
798+
@sshow eq_orders
799+
@sshow callee_result.total_incidence[callee_eq]
800+
@sshow total_incidence[caller_eq]
801+
@sshow callee_var_schedule
802802
error("Caller Equation $(caller_eq) (callee equation $(callee_eq)) is not in the callee schedule ($sref)")
803803
end
804804
end
@@ -868,7 +868,7 @@ function tearing_schedule!(state::TransformationState, ci::CodeInstance, key::To
868868
# TODO: Pull this up, if arguments are state-independent
869869
continue
870870
else
871-
@show stmt
871+
@sshow stmt
872872
error()
873873
end
874874
else
@@ -953,9 +953,9 @@ function tearing_schedule!(state::TransformationState, ci::CodeInstance, key::To
953953
error()
954954
else
955955
if !(lin_var in key.diff_states || lin_var in key.alg_states)
956-
@show lin_var
957-
@show ordinal
958-
@show eq_order
956+
@sshow lin_var
957+
@sshow ordinal
958+
@sshow eq_order
959959
display(result.ir)
960960
error("Tried to schedule variable $(lin_var) that we do not have a solution to (but our scheduling should have ensured that we do)")
961961
end

src/utils.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,21 @@ macro insert_node_here(compact, line, ex, reverse_affinity = false)
127127
insert_node_here!($compact, inst, $reverse_affinity)
128128
end
129129
end
130+
131+
"""
132+
@sshow stmt
133+
@sshow length(ir.stmts) typeof(val)
134+
135+
Drop-in replacement for `@show`, but using `jl_safe_printf` to avoid task switches.
136+
137+
This directly prints to C stdout; `stdout` redirects won't have any effect.
138+
"""
139+
macro sshow(exs...)
140+
blk = Expr(:block)
141+
for ex in exs
142+
push!(blk.args, :(Core.println($(sprint(Base.show_unquoted,ex)*" = "),
143+
repr(begin local value = $(esc(ex)) end))))
144+
end
145+
isempty(exs) || push!(blk.args, :value)
146+
return blk
147+
end

0 commit comments

Comments
 (0)