@@ -127,3 +127,39 @@ macro insert_node_here(compact, line, ex, reverse_affinity = false)
127127 insert_node_here! ($ compact, inst, $ reverse_affinity)
128128 end
129129end
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