Skip to content

Commit 563988f

Browse files
committed
fix update_slots
1 parent 3a91139 commit 563988f

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/CompilerPluginTools.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ module CompilerPluginTools
33
using MLStyle
44
using Expronicon
55

6-
export NewCodeInfo,
6+
export
7+
# interp
8+
NewCodeInfo,
79
NewSlotNumber,
810
JuliaLikeInterpreter,
911
AbstractInterpreter,
1012
isintrinsic,
1113
# reexport SSA nodes from Core
14+
MethodInstance,
1215
CodeInfo,
1316
SSAValue,
1417
Const,
@@ -50,6 +53,8 @@ export NewCodeInfo,
5053
const_invoke!,
5154
finish,
5255
IntrinsicError,
56+
# utils
57+
method_instance,
5358
@make_codeinfo,
5459
@make_ircode,
5560
@intrinsic_stub

src/codeinfo.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ function update_slots(e, newslotmap, changemap)
249249
@match e begin
250250
SlotNumber(id) => SlotNumber(id + changemap[id])
251251
NewSlotNumber(id) => SlotNumber(newslotmap[id])
252+
ReturnNode(x) => ReturnNode(update_slots(x, newslotmap, changemap))
253+
GotoIfNot(cond, dest) => GotoIfNot(update_slots(cond, newslotmap, changemap), dest)
252254
NewvarNode(SlotNumber(id)) => NewvarNode(SlotNumber(id+slotmap[id]))
253255
Expr(head, args...) => Expr(head, map(x->update_slots(x, newslotmap, changemap), e.args)...)
254256
_ => e

src/utils.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,18 @@ function make_codeinfo_m(ex)
5959
end
6060
end
6161

62+
"""
63+
method_instance(f, tt, world=Base.get_world_counter())
64+
65+
Return the `MethodInstance`, unlike `Base.method_instances`, `tt` must be specified type.
66+
"""
67+
function method_instance(@nospecialize(f), @nospecialize(tt), world=Base.get_world_counter())
68+
# get the method instance
69+
meth = which(f, tt)
70+
sig = Base.signature_type(f, tt)::Type
71+
(ti, env) = ccall(:jl_type_intersection_with_env, Any, (Any, Any), sig,
72+
meth.sig)::Core.SimpleVector
73+
meth = Base.func_for_method_checked(meth, ti, env)
74+
return ccall(:jl_specializations_get_linfo, Ref{Core.MethodInstance},
75+
(Any, Any, Any, UInt), meth, ti, env, world)
76+
end

0 commit comments

Comments
 (0)