Skip to content

Commit 088b88a

Browse files
authored
fix IRShow.show of the standard library Compiler (JuliaLang#56542)
Previously, definitions of overloaded `Base.show` and `IRShow.show` were mixed, causing `show` to not function properly for `Compiler` as a standard library. This commit fixes that issue and also includes some minor cleanups.
1 parent 219e674 commit 088b88a

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

src/Compiler.jl

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,7 @@ include("reflection_interface.jl")
169169

170170
if isdefined(Base, :IRShow)
171171
@eval module IRShow
172-
import ..Compiler
173-
using Core.IR
174-
using ..Base
175-
import .Compiler: IRCode, CFG, scan_ssa_use!,
176-
isexpr, compute_basic_blocks, block_for_inst, IncrementalCompact,
177-
Effects, ALWAYS_TRUE, ALWAYS_FALSE, DebugInfoStream, getdebugidx,
178-
VarState, InvalidIRError, argextype, widenconst, singleton_type,
179-
sptypes_from_meth_instance, EMPTY_SPTYPES, InferenceState,
180-
NativeInterpreter, CachedMethodTable, LimitedAccuracy, Timings
172+
using ..Compiler: Compiler
181173
# During bootstrap, Base will later include this into its own "IRShow module"
182174
Compiler.include(IRShow, "ssair/show.jl")
183175
end

src/ssair/show.jl

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33
# This file is not loaded into `Core.Compiler` but rather loaded into the context of
44
# `Base.IRShow` and thus does not participate in bootstrapping.
55

6-
@nospecialize
6+
using Base, Core.IR
7+
8+
import Base: show
9+
using Base: isexpr, prec_decl, show_unquoted, with_output_color
10+
using .Compiler: ALWAYS_FALSE, ALWAYS_TRUE, argextype, BasicBlock, block_for_inst,
11+
CachedMethodTable, CFG, compute_basic_blocks, DebugInfoStream, Effects,
12+
EMPTY_SPTYPES, getdebugidx, IncrementalCompact, InferenceResult, InferenceState,
13+
InvalidIRError, IRCode, LimitedAccuracy, NativeInterpreter, scan_ssa_use!,
14+
singleton_type, sptypes_from_meth_instance, StmtRange, Timings, VarState, widenconst
715

8-
import Base: show_unquoted
9-
using Base: printstyled, with_output_color, prec_decl, @invoke
16+
@nospecialize
1017

1118
function Base.show(io::IO, cfg::CFG)
1219
print(io, "CFG with $(length(cfg.blocks)) blocks:")
@@ -497,15 +504,15 @@ function DILineInfoPrinter(debuginfo, def, showtypes::Bool=false)
497504
started::Bool = false
498505
if !update_line_only && showtypes && !isa(frame.method, Symbol) && nctx != 1
499506
print(io, linestart)
500-
Base.with_output_color(linecolor, io) do io
507+
with_output_color(linecolor, io) do io
501508
print(io, indent(""))
502509
print(io, "┌ invoke ", frame.method)
503510
println(io)
504511
end
505512
started = true
506513
end
507514
print(io, linestart)
508-
Base.with_output_color(linecolor, io) do io
515+
with_output_color(linecolor, io) do io
509516
print(io, indent(""))
510517
push!(context, frame)
511518
if update_line_only
@@ -914,7 +921,7 @@ function show_ir(io::IO, ir::IRCode, config::IRShowConfig=default_config(ir);
914921
pop_new_node! = new_nodes_iter(ir))
915922
used = stmts_used(io, ir)
916923
cfg = ir.cfg
917-
maxssaid = length(ir.stmts) + Compiler.length(ir.new_nodes)
924+
maxssaid = length(ir.stmts) + length(ir.new_nodes)
918925
let io = IOContext(io, :maxssaid=>maxssaid)
919926
show_ir_stmts(io, ir, 1:length(ir.stmts), config, ir.sptypes, used, cfg, 1; pop_new_node!)
920927
end
@@ -971,13 +978,13 @@ function show_ir(io::IO, compact::IncrementalCompact, config::IRShowConfig=defau
971978
still_to_be_inserted = (last(input_bb.stmts) - compact.idx) + count
972979

973980
result_bb = result_bbs[compact.active_result_bb]
974-
result_bbs[compact.active_result_bb] = Compiler.BasicBlock(result_bb,
975-
Compiler.StmtRange(first(result_bb.stmts), compact.result_idx+still_to_be_inserted))
981+
result_bbs[compact.active_result_bb] = BasicBlock(result_bb,
982+
StmtRange(first(result_bb.stmts), compact.result_idx+still_to_be_inserted))
976983
end
977984
compact_cfg = CFG(result_bbs, Int[first(result_bbs[i].stmts) for i in 2:length(result_bbs)])
978985

979986
pop_new_node! = new_nodes_iter(compact)
980-
maxssaid = length(compact.result) + Compiler.length(compact.new_new_nodes)
987+
maxssaid = length(compact.result) + length(compact.new_new_nodes)
981988
bb_idx = let io = IOContext(io, :maxssaid=>maxssaid)
982989
show_ir_stmts(io, compact, 1:compact.result_idx-1, config, compact.ir.sptypes,
983990
used_compacted, compact_cfg, 1; pop_new_node!)
@@ -998,16 +1005,16 @@ function show_ir(io::IO, compact::IncrementalCompact, config::IRShowConfig=defau
9981005
inputs_bbs = copy(cfg.blocks)
9991006
for (i, bb) in enumerate(inputs_bbs)
10001007
if bb.stmts.stop < bb.stmts.start
1001-
inputs_bbs[i] = Compiler.BasicBlock(bb,
1002-
Compiler.StmtRange(last(bb.stmts), last(bb.stmts)))
1008+
inputs_bbs[i] = BasicBlock(bb,
1009+
StmtRange(last(bb.stmts), last(bb.stmts)))
10031010
# this is not entirely correct, and will result in the bb starting again,
10041011
# but is the best we can do without changing how `finish_current_bb!` works.
10051012
end
10061013
end
10071014
uncompacted_cfg = CFG(inputs_bbs, Int[first(inputs_bbs[i].stmts) for i in 2:length(inputs_bbs)])
10081015

10091016
pop_new_node! = new_nodes_iter(compact.ir, compact.new_nodes_idx)
1010-
maxssaid = length(compact.ir.stmts) + Compiler.length(compact.ir.new_nodes)
1017+
maxssaid = length(compact.ir.stmts) + length(compact.ir.new_nodes)
10111018
let io = IOContext(io, :maxssaid=>maxssaid)
10121019
# first show any new nodes to be attached after the last compacted statement
10131020
if compact.idx > 1
@@ -1071,13 +1078,12 @@ function Base.show(io::IO, e::Effects)
10711078
print(io, ')')
10721079
end
10731080

1074-
1075-
function show(io::IO, inferred::Compiler.InferenceResult)
1081+
function Base.show(io::IO, inferred::InferenceResult)
10761082
mi = inferred.linfo
10771083
tt = mi.specTypes.parameters[2:end]
10781084
tts = join(["::$(t)" for t in tt], ", ")
10791085
rettype = inferred.result
1080-
if isa(rettype, Compiler.InferenceState)
1086+
if isa(rettype, InferenceState)
10811087
rettype = rettype.bestguess
10821088
end
10831089
if isa(mi.def, Method)
@@ -1102,9 +1108,8 @@ function Base.show(io::IO, limited::LimitedAccuracy)
11021108
print(io, ", #= ", length(limited.causes), " cause(s) =#)")
11031109
end
11041110

1105-
11061111
# These sometimes show up as Const-values in InferenceFrameInfo signatures
1107-
function show(io::IO, mi_info::Timings.InferenceFrameInfo)
1112+
function Base.show(io::IO, mi_info::Timings.InferenceFrameInfo)
11081113
mi = mi_info.mi
11091114
def = mi.def
11101115
if isa(def, Method)
@@ -1125,7 +1130,7 @@ function show(io::IO, mi_info::Timings.InferenceFrameInfo)
11251130
end
11261131
end
11271132

1128-
function show(io::IO, tinf::Timings.Timing)
1133+
function Base.show(io::IO, tinf::Timings.Timing)
11291134
print(io, "Compiler.Timings.Timing(", tinf.mi_info, ") with ", length(tinf.children), " children")
11301135
end
11311136

0 commit comments

Comments
 (0)