Skip to content

Commit 2cada0d

Browse files
committed
Merge branch 'master' of github.com:JuliaDebug/LoweredCodeUtils.jl into support-external-methodtables
2 parents f57ed81 + d821711 commit 2cada0d

File tree

8 files changed

+38
-28
lines changed

8 files changed

+38
-28
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
name = "LoweredCodeUtils"
22
uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b"
3-
version = "3.3.0"
3+
version = "3.4.2"
44
authors = ["Tim Holy <[email protected]>"]
55

66
[deps]
77
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
8+
Compiler = "807dbc54-b67e-4c79-8afb-eafe4df6f2e1"
89
JuliaInterpreter = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
910

1011
[compat]
1112
CodeTracking = "2"
13+
Compiler = "0.1"
1214
JuliaInterpreter = "0.10"
1315
julia = "1.10"
1416

src/LoweredCodeUtils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ using JuliaInterpreter: SSAValue, SlotNumber, Frame, Interpreter, RecursiveInter
1616
using JuliaInterpreter: codelocation, is_global_ref, is_global_ref_egal, is_quotenode_egal, is_return,
1717
lookup, lookup_return, linetable, moduleof, next_until!, nstatements, pc_expr,
1818
step_expr!, whichtt, extract_method_table
19+
using Compiler: Compiler as CC
1920

2021
include("packagedef.jl")
2122

src/codeedges.jl

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,25 +106,25 @@ function print_with_code(preprint, postprint, io::IO, src::CodeInfo)
106106
used = BitSet()
107107
cfg = compute_basic_blocks(src.code)
108108
for stmt in src.code
109-
Core.Compiler.scan_ssa_use!(push!, used, stmt)
109+
CC.scan_ssa_use!(push!, used, stmt)
110110
end
111111
@static if isdefined(Base, :__has_internal_change) && Base.__has_internal_change(v"1.12-alpha", :printcodeinfocalls)
112112
sptypes = let parent = src.parent
113113
parent isa MethodInstance ?
114-
Core.Compiler.sptypes_from_meth_instance(parent) :
115-
Core.Compiler.EMPTY_SPTYPES
114+
CC.sptypes_from_meth_instance(parent) :
115+
CC.EMPTY_SPTYPES
116116
end
117117
end
118-
line_info_preprinter = Base.IRShow.lineinfo_disabled
119-
line_info_postprinter = Base.IRShow.default_expr_type_printer
118+
line_info_preprinter = IRShow.lineinfo_disabled
119+
line_info_postprinter = IRShow.default_expr_type_printer
120120
preprint(io)
121121
bb_idx_prev = bb_idx = 1
122122
for idx = 1:length(src.code)
123123
preprint(io, idx)
124124
@static if isdefined(Base, :__has_internal_change) && Base.__has_internal_change(v"1.12-alpha", :printcodeinfocalls)
125-
bb_idx = Base.IRShow.show_ir_stmt(io, src, idx, line_info_preprinter, line_info_postprinter, sptypes, used, cfg, bb_idx)
125+
bb_idx = IRShow.show_ir_stmt(io, src, idx, line_info_preprinter, line_info_postprinter, sptypes, used, cfg, bb_idx)
126126
else
127-
bb_idx = Base.IRShow.show_ir_stmt(io, src, idx, line_info_preprinter, line_info_postprinter, used, cfg, bb_idx)
127+
bb_idx = IRShow.show_ir_stmt(io, src, idx, line_info_preprinter, line_info_postprinter, used, cfg, bb_idx)
128128
end
129129
postprint(io, idx, bb_idx != bb_idx_prev)
130130
bb_idx_prev = bb_idx
@@ -760,8 +760,6 @@ end
760760

761761
## Add control-flow
762762

763-
using Core: CodeInfo
764-
using Core.Compiler: CFG, BasicBlock, compute_basic_blocks
765763

766764
# The goal of this function is to request concretization of the minimal necessary control
767765
# flow to evaluate statements whose concretization have already been requested.
@@ -1047,7 +1045,7 @@ function JuliaInterpreter.get_return(interp::SelectiveInterpreter, frame::Frame)
10471045
node = pc_expr(frame, pc)
10481046
if is_return(node)
10491047
if interp.isrequired[pc]
1050-
return lookup_return(frame, node)
1048+
return lookup_return(interp.inner, frame, node)
10511049
end
10521050
else
10531051
if isassigned(frame.framedata.ssavalues, pc)

src/domtree.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
# A few items needed to be added:
77

8-
using Core.Compiler: BasicBlock
98
import Base: length, copy, copy!
109

1110
# END additions

src/packagedef.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@ using Core.IR: CodeInfo, GotoIfNot, GotoNode, IR, MethodInstance, ReturnNode
55
@static if isdefined(Core.IR, :EnterNode)
66
using Core.IR: EnterNode
77
end
8-
using Core.Compiler: construct_domtree, construct_postdomtree, nearest_common_dominator,
9-
postdominates
8+
using .CC:
9+
BasicBlock, CFG,
10+
compute_basic_blocks, construct_domtree, construct_postdomtree,
11+
nearest_common_dominator, postdominates
12+
13+
@static if isdefined(CC, :IRShow)
14+
using .CC: IRShow
15+
else
16+
using Base: IRShow
17+
end
18+
1019
using Base.Meta: isexpr
1120

12-
const SSAValues = Union{Core.Compiler.SSAValue, JuliaInterpreter.SSAValue}
21+
const SSAValues = Union{Core.IR.SSAValue, JuliaInterpreter.SSAValue}
1322

1423
const trackedheads = (:method,) # Revise uses this (for now), don't delete; also update test/hastrackedexpr if this list gets expanded
1524
const structdecls = (:_structtype, :_abstracttype, :_primitivetype)

src/utils.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
const AnySSAValue = Union{Core.Compiler.SSAValue,JuliaInterpreter.SSAValue}
2-
const AnySlotNumber = Union{Core.Compiler.SlotNumber,JuliaInterpreter.SlotNumber}
1+
const AnySSAValue = Union{Core.IR.SSAValue,JuliaInterpreter.SSAValue}
2+
const AnySlotNumber = Union{Core.IR.SlotNumber,JuliaInterpreter.SlotNumber}
33

44
# to circumvent https://github.com/JuliaLang/julia/issues/37342, we inline these `isa`
55
# condition checks at surface AST level
66
# https://github.com/JuliaLang/julia/pull/38905 will get rid of the need of these hacks
77
macro isssa(stmt)
8-
:($(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(Core.Compiler, :SSAValue))) ||
8+
:($(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(Core.IR, :SSAValue))) ||
99
$(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(JuliaInterpreter, :SSAValue))))
1010
end
1111
macro issslotnum(stmt)
12-
:($(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(Core.Compiler, :SlotNumber))) ||
12+
:($(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(Core.IR, :SlotNumber))) ||
1313
$(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(JuliaInterpreter, :SlotNumber))))
1414
end
1515

@@ -211,8 +211,8 @@ end
211211

212212
showempty(list) = isempty(list) ? '' : list
213213

214-
# Smooth the transition between Core.Compiler and Base
215-
rng(bb::Core.Compiler.BasicBlock) = (r = bb.stmts; return Core.Compiler.first(r):Core.Compiler.last(r))
214+
# Smooth the transition between CC and Base (not requried for v1.12 and above)
215+
rng(bb::BasicBlock) = (r = bb.stmts; return CC.first(r):CC.last(r))
216216

217217
function pushall!(dest, src)
218218
for item in src
@@ -224,7 +224,7 @@ end
224224
# computes strongly connected components of a control flow graph `cfg`
225225
# NOTE adapted from https://github.com/JuliaGraphs/Graphs.jl/blob/5878e7be4d68b2a1c179d1367aea670db115ebb5/src/connectivity.jl#L265-L357
226226
# since to load an entire Graphs.jl is a bit cost-ineffective in terms of a trade-off of latency vs. maintainability
227-
function strongly_connected_components(g::Core.Compiler.CFG)
227+
function strongly_connected_components(g::CFG)
228228
T = Int
229229
zero_t = zero(T)
230230
one_t = one(T)
@@ -322,12 +322,12 @@ function strongly_connected_components(g::Core.Compiler.CFG)
322322
end
323323

324324
# compatibility with Graphs.jl interfaces
325-
@inline nv(cfg::Core.Compiler.CFG) = length(cfg.blocks)
326-
@inline vertices(cfg::Core.Compiler.CFG) = 1:nv(cfg)
327-
@inline outneighbors(cfg::Core.Compiler.CFG, v) = cfg.blocks[v].succs
325+
@inline nv(cfg::CFG) = length(cfg.blocks)
326+
@inline vertices(cfg::CFG) = 1:nv(cfg)
327+
@inline outneighbors(cfg::CFG, v) = cfg.blocks[v].succs
328328

329329
# using Graphs: SimpleDiGraph, add_edge!, strongly_connected_components as oracle_scc
330-
# function cfg_to_sdg(cfg::Core.Compiler.CFG)
330+
# function cfg_to_sdg(cfg::CFG)
331331
# g = SimpleDiGraph(length(cfg.blocks))
332332
# for (v, block) in enumerate(cfg.blocks)
333333
# for succ in block.succs

test/codeedges.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module codeedges
22

33
using LoweredCodeUtils
44
using LoweredCodeUtils.JuliaInterpreter
5+
using LoweredCodeUtils: CC
56
using LoweredCodeUtils: callee_matches, istypedef, exclude_named_typedefs
67
using JuliaInterpreter: is_global_ref, is_quotenode
78
using Test
@@ -324,7 +325,7 @@ module ModSelective end
324325
src = frame.framecode.src
325326
edges = CodeEdges(ModEval, src)
326327
isrequired = minimal_evaluation(@nospecialize(stmt)->(LoweredCodeUtils.ismethod3(stmt),false), src, edges; norequire=exclude_named_typedefs(src, edges)) # initially mark only the constructor
327-
bbs = Core.Compiler.compute_basic_blocks(src.code)
328+
bbs = CC.compute_basic_blocks(src.code)
328329
for (iblock, block) in enumerate(bbs.blocks)
329330
r = LoweredCodeUtils.rng(block)
330331
if iblock == length(bbs.blocks)

test/signatures.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ bodymethtest5(x, y=Dict(1=>2)) = 5
323323
methoddefs!(signatures, frame; define=false)
324324
@test !isempty(signatures)
325325

326-
# Inner methods in structs. Comes up in, e.g., Core.Compiler.Params.
326+
# Inner methods in structs. Comes up in, e.g., CC.Params.
327327
# The body of CustomMS is an SSAValue.
328328
ex = quote
329329
struct MyStructWithMeth

0 commit comments

Comments
 (0)