Skip to content

Commit 47f5627

Browse files
Merge pull request #83 from simeonschaub/sds/fix_on_master
fix IRTools on Julia 1.6
2 parents 2c5b9e7 + 927e9cf commit 47f5627

File tree

6 files changed

+44
-51
lines changed

6 files changed

+44
-51
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
docs/build
22
.DS_Store
3+
4+
Manifest.toml

Manifest.toml

Lines changed: 0 additions & 39 deletions
This file was deleted.

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "IRTools"
22
uuid = "7869d1d1-7146-5819-86e3-90919afe41df"
33
authors = ["Mike J Innes <[email protected]>"]
4-
version = "0.4.1"
4+
version = "0.4.2"
55

66
[deps]
77
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

src/ir/wrap.jl

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function IRCode(ir::IR)
2121
for b in IRTools.blocks(ir)
2222
if b.id == 1
2323
for (i, arg) in enumerate(IRTools.arguments(b))
24-
defs[arg] = Core.Compiler.Argument(i)
24+
defs[arg] = Core.SlotNumber(i)
2525
end
2626
else
2727
@assert isempty(BasicBlock(b).args)
@@ -66,15 +66,30 @@ function IRCode(ir::IR)
6666
end
6767
end
6868

69+
if VERSION >= v"1.6.0-DEV.272"
70+
isgotoifnot(@nospecialize(ex)) = (@assert !isexpr(ex, :gotoifnot); ex isa Core.GotoIfNot)
71+
destruct_gotoifnot(@nospecialize(ex)) = Any[ex.cond, ex.dest]
72+
73+
isreturn(@nospecialize(ex)) = (@assert !isexpr(ex, :return); ex isa ReturnNode)
74+
retval(@nospecialize(ex)) = ex.val
75+
else
76+
isgotoifnot(@nospecialize(ex)) = isexpr(ex, :gotoifnot)
77+
destruct_gotoifnot(@nospecialize(ex)) = ex.args
78+
79+
isreturn(@nospecialize(ex)) = isexpr(ex, :return)
80+
retval(@nospecialize(ex)) = ex.args[1]
81+
end
82+
6983
function blockstarts(ci::CodeInfo)
7084
bs = Int[]
7185
terminator = false
7286
for i = 1:length(ci.code)
7387
ex = ci.code[i]
74-
if isexpr(ex, :gotoifnot)
75-
push!(bs, ex.args[2])
88+
if isgotoifnot(ex)
89+
_, dest = destruct_gotoifnot(ex)
90+
push!(bs, dest)
7691
terminator = true
77-
elseif isexpr(ex, GotoNode, :return)
92+
elseif ex isa GotoNode || isreturn(ex)
7893
ex isa GotoNode && push!(bs, ex.label)
7994
i < length(ci.code) && push!(bs, i+1)
8095
terminator = false
@@ -108,13 +123,14 @@ function IR(ci::CodeInfo, nargs::Integer; meta = nothing)
108123
continue
109124
elseif isexpr(ex, :enter)
110125
_rename[Core.SSAValue(i)] = push!(ir, Expr(:enter, findfirst(==(ex.args[1]), bs)+1))
111-
elseif isexpr(ex, GotoNode)
126+
elseif ex isa GotoNode
112127
branch!(ir, findfirst(==(ex.label), bs)+1)
113-
elseif isexpr(ex, :gotoifnot)
114-
branch!(ir, findfirst(==(ex.args[2]), bs)+1,
115-
unless = rename(ex.args[1]))
116-
elseif isexpr(ex, :return)
117-
return!(ir, rename(ex.args[1]))
128+
elseif isgotoifnot(ex)
129+
cond, dest = destruct_gotoifnot(ex)
130+
branch!(ir, findfirst(==(dest), bs)+1,
131+
unless = rename(cond))
132+
elseif isreturn(ex)
133+
return!(ir, rename(retval(ex)))
118134
else
119135
_rename[Core.SSAValue(i)] = push!(ir, IRTools.stmt(rename(ex), line = ci.codelocs[i]))
120136
end

src/reflection/utils.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,22 @@ using Core.Compiler: CodeInfo, SlotNumber
5757
function slots!(ci::CodeInfo)
5858
ss = Dict{Slot,SlotNumber}()
5959
for i = 1:length(ci.code)
60-
ci.code[i] = MacroTools.prewalk(ci.code[i]) do x
60+
function f(x)
6161
x isa Slot || return x
6262
haskey(ss, x) && return ss[x]
6363
push!(ci.slotnames, x.id)
6464
push!(ci.slotflags, 0x00)
6565
ss[x] = SlotNumber(length(ci.slotnames))
6666
end
67+
if VERSION >= v"1.6.0-DEV.272"
68+
ci.code[i] = MacroTools.prewalk(ci.code[i]) do x
69+
x isa Core.ReturnNode ? Core.ReturnNode(f(x.val)) :
70+
x isa Core.GotoIfNot ? Core.GotoIfNot(f(x.cond), x.dest) :
71+
f(x)
72+
end
73+
else
74+
ci.code[i] = MacroTools.prewalk(f, ci.code[i])
75+
end
6776
end
6877
return ci
6978
end

test/compiler.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ add(a, b) = a+b
1616
@test passthrough(add, 2, 3) == 5
1717
@test passthrough(sin, 1.0) == sin(1.0)
1818

19+
f_returnnode(::T) where {T} = T
20+
@test passthrough(f_returnnode, 1) == Int
21+
f_gotoifnot(::Val{x}) where {x} = x ? 1 : 0
22+
@test passthrough(f_gotoifnot, Val(true)) == 1
23+
1924
@test @code_ir(passthrough, add(2, 3)) isa IR
2025

2126
IRTools.refresh(roundtrip)

0 commit comments

Comments
 (0)