Skip to content

Commit a04a58e

Browse files
committed
Add sshow helper
1 parent 3d7211a commit a04a58e

File tree

6 files changed

+49
-13
lines changed

6 files changed

+49
-13
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/structural.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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/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
@@ -794,10 +794,10 @@ function tearing_schedule!(state::TransformationState, ci::CodeInstance, key::To
794794
cstructure = make_structure_from_ipo(callee_result)
795795
cvar_eq_matching = matching_for_key(callee_result, callee_key, cstructure)
796796
display(StateSelection.MatchedSystemStructure(cstructure, cvar_eq_matching))
797-
@show eq_orders
798-
@show callee_result.total_incidence[callee_eq]
799-
@show total_incidence[caller_eq]
800-
@show callee_var_schedule
797+
@sshow eq_orders
798+
@sshow callee_result.total_incidence[callee_eq]
799+
@sshow total_incidence[caller_eq]
800+
@sshow callee_var_schedule
801801
error("Caller Equation $(caller_eq) (callee equation $(callee_eq)) is not in the callee schedule ($sref)")
802802
end
803803
end
@@ -867,7 +867,7 @@ function tearing_schedule!(state::TransformationState, ci::CodeInstance, key::To
867867
# TODO: Pull this up, if arguments are state-independent
868868
continue
869869
else
870-
@show stmt
870+
@sshow stmt
871871
error()
872872
end
873873
else
@@ -952,9 +952,9 @@ function tearing_schedule!(state::TransformationState, ci::CodeInstance, key::To
952952
error()
953953
else
954954
if !(lin_var in key.diff_states || lin_var in key.alg_states)
955-
@show lin_var
956-
@show ordinal
957-
@show eq_order
955+
@sshow lin_var
956+
@sshow ordinal
957+
@sshow eq_order
958958
display(result.ir)
959959
error("Tried to schedule variable $(lin_var) that we do not have a solution to (but our scheduling should have ensured that we do)")
960960
end

src/utils.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,39 @@ 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(ex, exs...)
140+
static_show(ex, exs...)
141+
end
142+
143+
safe_printf(arg, args...) = @ccall jl_safe_printf(string(arg, args...)::Cstring)::Cvoid
144+
145+
function static_show(ex)
146+
quote
147+
ret = $(esc(ex))
148+
safe_printf($(string(ex)), " = ", repr(ret), '\n')
149+
ret
150+
end
151+
end
152+
153+
function static_show(ex, ex2, exs...)
154+
exs = (ex, ex2, exs...)
155+
ret = Expr(:block)
156+
for (i, ex) in enumerate(exs)
157+
args = []
158+
i > 1 && push!(args, '\n')
159+
push!(args, string(ex), " = ", :(repr($(esc(ex)))))
160+
i == length(exs) && push!(args, '\n')
161+
push!(ret.args, :(safe_printf($(args...))))
162+
end
163+
push!(ret.args, nothing)
164+
ret
165+
end

0 commit comments

Comments
 (0)