Skip to content

Commit 8191420

Browse files
committed
WIP: Adjust to julia#53219
These are the changes I was using locally when developing that branch to have basic Cthulhu functionality. It's likely additional changes are required to have Cthulhu fully functional.
1 parent 864002c commit 8191420

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

TypedSyntax/src/node.jl

+9-9
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,18 @@ function tsn_and_mappings(@nospecialize(f), @nospecialize(t); kwargs...)
3030
tsn_and_mappings(m, src, rt; kwargs...)
3131
end
3232

33-
function tsn_and_mappings(m::Method, src::CodeInfo, @nospecialize(rt); warn::Bool=true, strip_macros::Bool=false, kwargs...)
33+
function tsn_and_mappings(mi::MethodInstance, src::CodeInfo, @nospecialize(rt); warn::Bool=true, strip_macros::Bool=false, kwargs...)
34+
m = mi.def::Method
3435
def = definition(String, m)
3536
if isnothing(def)
3637
warn && @warn "couldn't retrieve source of $m"
3738
return nothing, nothing
3839
end
39-
return tsn_and_mappings(m, src, rt, def...; warn, strip_macros, kwargs...)
40+
return tsn_and_mappings(mi, src, rt, def...; warn, strip_macros, kwargs...)
4041
end
4142

42-
function tsn_and_mappings(m::Method, src::CodeInfo, @nospecialize(rt), sourcetext::AbstractString, lineno::Integer; warn::Bool=true, strip_macros::Bool=false, kwargs...)
43+
function tsn_and_mappings(mi::MethodInstance, src::CodeInfo, @nospecialize(rt), sourcetext::AbstractString, lineno::Integer; warn::Bool=true, strip_macros::Bool=false, kwargs...)
44+
m = mi.def::Method
4345
filename = isnothing(functionloc(m)[1]) ? string(m.file) : functionloc(m)[1]
4446
rootnode = JuliaSyntax.parsestmt(SyntaxNode, sourcetext; filename=filename, first_line=lineno, kwargs...)
4547
if strip_macros
@@ -50,7 +52,7 @@ function tsn_and_mappings(m::Method, src::CodeInfo, @nospecialize(rt), sourcetex
5052
end
5153
end
5254
Δline = lineno - m.line # offset from original line number (Revise)
53-
mappings, symtyps = map_ssas_to_source(src, rootnode, Δline)
55+
mappings, symtyps = map_ssas_to_source(src, mi, rootnode, Δline)
5456
node = TypedSyntaxNode(rootnode, src, mappings, symtyps)
5557
node.typ = rt
5658
return node, mappings
@@ -59,9 +61,8 @@ end
5961
TypedSyntaxNode(@nospecialize(f), @nospecialize(t); kwargs...) = tsn_and_mappings(f, t; kwargs...)[1]
6062

6163
function TypedSyntaxNode(mi::MethodInstance; kwargs...)
62-
m = mi.def::Method
6364
src, rt = getsrc(mi)
64-
tsn_and_mappings(m, src, rt; kwargs...)[1]
65+
tsn_and_mappings(mi, src, rt; kwargs...)[1]
6566
end
6667

6768
TypedSyntaxNode(rootnode::SyntaxNode, src::CodeInfo, Δline::Integer=0) =
@@ -397,8 +398,7 @@ end
397398
# Main logic for mapping `src.code[i]` to node(s) in the SyntaxNode tree
398399
# Success: when we map it to a unique node
399400
# Δline is the (Revise) offset of the line number
400-
function map_ssas_to_source(src::CodeInfo, rootnode::SyntaxNode, Δline::Int)
401-
mi = src.parent::MethodInstance
401+
function map_ssas_to_source(src::CodeInfo, mi::MethodInstance, rootnode::SyntaxNode, Δline::Int)
402402
slottypes = src.slottypes::Union{Nothing, Vector{Any}}
403403
have_slottypes = slottypes !== nothing
404404
ssavaluetypes = src.ssavaluetypes::Vector{Any}
@@ -736,7 +736,7 @@ function map_ssas_to_source(src::CodeInfo, rootnode::SyntaxNode, Δline::Int)
736736
end
737737
return mappings, symtyps
738738
end
739-
map_ssas_to_source(src::CodeInfo, rootnode::SyntaxNode, Δline::Integer) = map_ssas_to_source(src, rootnode, Int(Δline))
739+
map_ssas_to_source(src::CodeInfo, mi::MethodInstance, rootnode::SyntaxNode, Δline::Integer) = map_ssas_to_source(src, mi, rootnode, Int(Δline))
740740

741741
function follow_back(src, arg)
742742
# Follow SSAValue backward to see if it maps back to a slot

TypedSyntax/test/exhaustive.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const goodmis = Core.MethodInstance[]
2626
continue
2727
end
2828
try
29-
tsn, _ = TypedSyntax.tsn_and_mappings(m, src, rt, ret...; warn=false)
29+
tsn, _ = TypedSyntax.tsn_and_mappings(mi, src, rt, ret...; warn=false)
3030
@test isa(tsn, TypedSyntaxNode)
3131
push!(goodmis, mi)
3232
catch

src/codeview.jl

-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ function cthulhu_typed(io::IO, debuginfo::Symbol,
182182
# we're working on pre-optimization state, need to ignore `LimitedAccuracy`
183183
src = copy(src)
184184
src.ssavaluetypes = mapany(ignorelimited, src.ssavaluetypes::Vector{Any})
185-
src.rettype = ignorelimited(src.rettype)
186185

187186
if src.slotnames !== nothing
188187
slotnames = Base.sourceinfo_slotnames(src)

src/interpreter.jl

+8-1
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,17 @@ function create_cthulhu_source(@nospecialize(opt), effects::Effects)
126126
return OptimizedSource(ir, opt.src, opt.src.inlineable, effects)
127127
end
128128

129+
@static if VERSION v"1.12.0-DEV.15"
130+
function CC.transform_result_for_cache(interp::CthulhuInterpreter,
131+
linfo::MethodInstance, valid_worlds::WorldRange, result::InferenceResult, can_discard_trees::Bool=false)
132+
return create_cthulhu_source(result.src, result.ipo_effects)
133+
end
134+
else
129135
function CC.transform_result_for_cache(interp::CthulhuInterpreter,
130136
linfo::MethodInstance, valid_worlds::WorldRange, result::InferenceResult)
131137
return create_cthulhu_source(result.src, result.ipo_effects)
132138
end
139+
end
133140

134141
@static if VERSION v"1.11.0-DEV.879"
135142
function CC.inlining_policy(interp::CthulhuInterpreter,
@@ -176,7 +183,7 @@ function CC.IRInterpretationState(interp::CthulhuInterpreter,
176183
src = inferred.src
177184
method_info = CC.MethodInfo(src)
178185
return CC.IRInterpretationState(interp, method_info, ir, mi, argtypes, world,
179-
src.min_world, src.max_world)
186+
code.min_world, code.max_world)
180187
end
181188

182189
@static if VERSION v"1.11.0-DEV.737"

src/reflection.jl

+2-3
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,8 @@ function add_sourceline!(locs, CI, stmtidx::Int)
350350
end
351351

352352
function get_typed_sourcetext(mi::MethodInstance, src::CodeInfo, @nospecialize(rt); warn::Bool=true)
353-
meth = mi.def::Method
354-
tsn, mappings = TypedSyntax.tsn_and_mappings(meth, src, rt; warn, strip_macros=true)
355-
return truncate_if_defaultargs!(tsn, mappings, meth)
353+
tsn, mappings = TypedSyntax.tsn_and_mappings(mi, src, rt; warn, strip_macros=true)
354+
return truncate_if_defaultargs!(tsn, mappings, mi.def::Method)
356355
end
357356

358357
function get_typed_sourcetext(mi::MethodInstance, ::IRCode, @nospecialize(rt); kwargs...)

0 commit comments

Comments
 (0)