Skip to content

use the stdlib version of Compiler instead of Core.Compiler #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
name = "LoweredCodeUtils"
uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b"
version = "3.3.0"
version = "3.4.0"
authors = ["Tim Holy <tim.holy@gmail.com>"]

[deps]
Compiler = "807dbc54-b67e-4c79-8afb-eafe4df6f2e1"
JuliaInterpreter = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"

[compat]
Compiler = "0.1.0"
JuliaInterpreter = "0.10"
julia = "1.10"

Expand Down
8 changes: 3 additions & 5 deletions src/codeedges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ function print_with_code(preprint, postprint, io::IO, src::CodeInfo)
used = BitSet()
cfg = compute_basic_blocks(src.code)
for stmt in src.code
Core.Compiler.scan_ssa_use!(push!, used, stmt)
CC.scan_ssa_use!(push!, used, stmt)
end
@static if isdefined(Base, :__has_internal_change) && Base.__has_internal_change(v"1.12-alpha", :printcodeinfocalls)
sptypes = let parent = src.parent
parent isa MethodInstance ?
Core.Compiler.sptypes_from_meth_instance(parent) :
Core.Compiler.EMPTY_SPTYPES
CC.sptypes_from_meth_instance(parent) :
CC.EMPTY_SPTYPES
end
end
line_info_preprinter = Base.IRShow.lineinfo_disabled
Expand Down Expand Up @@ -763,8 +763,6 @@ end

## Add control-flow

using Core: CodeInfo
using Core.Compiler: CFG, BasicBlock, compute_basic_blocks

# The goal of this function is to request concretization of the minimal necessary control
# flow to evaluate statements whose concretization have already been requested.
Expand Down
1 change: 0 additions & 1 deletion src/domtree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

# A few items needed to be added:

using Core.Compiler: BasicBlock
import Base: length, copy, copy!

# END additions
Expand Down
9 changes: 6 additions & 3 deletions src/packagedef.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ using Core.IR: CodeInfo, GotoIfNot, GotoNode, IR, MethodInstance, ReturnNode
@static if isdefined(Core.IR, :EnterNode)
using Core.IR: EnterNode
end
using Core.Compiler: construct_domtree, construct_postdomtree, nearest_common_dominator,
postdominates
using Compiler: Compiler as CC
using .CC:
BasicBlock, CFG,
compute_basic_blocks, construct_domtree, construct_postdomtree,
nearest_common_dominator, postdominates
using Base.Meta: isexpr

const SSAValues = Union{Core.Compiler.SSAValue, JuliaInterpreter.SSAValue}
const SSAValues = Union{Core.IR.SSAValue, JuliaInterpreter.SSAValue}

const trackedheads = (:method,) # Revise uses this (for now), don't delete; also update test/hastrackedexpr if this list gets expanded
const structdecls = (:_structtype, :_abstracttype, :_primitivetype)
Expand Down
22 changes: 11 additions & 11 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const AnySSAValue = Union{Core.Compiler.SSAValue,JuliaInterpreter.SSAValue}
const AnySlotNumber = Union{Core.Compiler.SlotNumber,JuliaInterpreter.SlotNumber}
const AnySSAValue = Union{Core.IR.SSAValue,JuliaInterpreter.SSAValue}
const AnySlotNumber = Union{Core.IR.SlotNumber,JuliaInterpreter.SlotNumber}

# to circumvent https://github.com/JuliaLang/julia/issues/37342, we inline these `isa`
# condition checks at surface AST level
# https://github.com/JuliaLang/julia/pull/38905 will get rid of the need of these hacks
macro isssa(stmt)
:($(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(Core.Compiler, :SSAValue))) ||
:($(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(Core.IR, :SSAValue))) ||
$(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(JuliaInterpreter, :SSAValue))))
end
macro issslotnum(stmt)
:($(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(Core.Compiler, :SlotNumber))) ||
:($(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(Core.IR, :SlotNumber))) ||
$(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(JuliaInterpreter, :SlotNumber))))
end

Expand Down Expand Up @@ -211,8 +211,8 @@ end

showempty(list) = isempty(list) ? '∅' : list

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

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

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

# using Graphs: SimpleDiGraph, add_edge!, strongly_connected_components as oracle_scc
# function cfg_to_sdg(cfg::Core.Compiler.CFG)
# function cfg_to_sdg(cfg::CFG)
# g = SimpleDiGraph(length(cfg.blocks))
# for (v, block) in enumerate(cfg.blocks)
# for succ in block.succs
Expand Down
3 changes: 2 additions & 1 deletion test/codeedges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module codeedges

using LoweredCodeUtils
using LoweredCodeUtils.JuliaInterpreter
using LoweredCodeUtils: CC
using LoweredCodeUtils: callee_matches, istypedef, exclude_named_typedefs
using JuliaInterpreter: is_global_ref, is_quotenode
using Test
Expand Down Expand Up @@ -324,7 +325,7 @@ module ModSelective end
src = frame.framecode.src
edges = CodeEdges(ModEval, src)
isrequired = minimal_evaluation(@nospecialize(stmt)->(LoweredCodeUtils.ismethod3(stmt),false), src, edges; norequire=exclude_named_typedefs(src, edges)) # initially mark only the constructor
bbs = Core.Compiler.compute_basic_blocks(src.code)
bbs = CC.compute_basic_blocks(src.code)
for (iblock, block) in enumerate(bbs.blocks)
r = LoweredCodeUtils.rng(block)
if iblock == length(bbs.blocks)
Expand Down
2 changes: 1 addition & 1 deletion test/signatures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ bodymethtest5(x, y=Dict(1=>2)) = 5
methoddefs!(signatures, frame; define=false)
@test !isempty(signatures)

# Inner methods in structs. Comes up in, e.g., Core.Compiler.Params.
# Inner methods in structs. Comes up in, e.g., CC.Params.
# The body of CustomMS is an SSAValue.
ex = quote
struct MyStructWithMeth
Expand Down
Loading