Skip to content

Commit

Permalink
make inlining tests more robusts to lowering changes
Browse files Browse the repository at this point in the history
In particular, JuliaLang/julia#51970 which
adds more nodes in lowered ir.
  • Loading branch information
Pangoraw committed Dec 11, 2023
1 parent d7d8c2a commit 5cdd662
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions test/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ end
let
ir1 = @code_ir foo(1, 2)
ir2 = @code_ir bar(1, 2)
ir = IRTools.inline(ir1, IRTools.var(4), ir2)
inline_at = findfirst(ir1) do (_, stmt)
IRTools.isexpr(stmt.expr, :call) &&
stmt.expr.args[1] == GlobalRef(@__MODULE__, :bar)
end
@test inline_at !== nothing
ir = IRTools.inline(ir1, inline_at, ir2)
f = IRTools.func(ir)
@test f(nothing, 2, 3) == 3
@test f(nothing, 3, 2) == 3
Expand All @@ -66,7 +71,12 @@ end
let
ir = @code_ir foo2(1)
ir2 = @code_ir foo1(1)
ir3 = IRTools.inline(ir, IRTools.var(4), ir2)
inline_at = findfirst(ir) do (_, stmt)
IRTools.isexpr(stmt.expr, :call) &&
stmt.expr.args[1] == GlobalRef(@__MODULE__, :foo1)
end
@test inline_at !== nothing
ir3 = IRTools.inline(ir, inline_at, ir2)
@test IRTools.func(ir3)(nothing, 2) == 12
@test IRTools.func(ir3)(nothing, 101) == 101
end
Expand All @@ -87,7 +97,12 @@ end
let
ir = @code_ir foo2(1)
ir2 = @code_ir foo1(1)
ir3 = IRTools.inline(ir, IRTools.var(3), ir2)
inline_at = findfirst(ir) do (_, stmt)
IRTools.isexpr(stmt.expr, :call) &&
stmt.expr.args[1] == GlobalRef(@__MODULE__, :foo1)
end
@test inline_at !== nothing
ir3 = IRTools.inline(ir, inline_at, ir2)
@test IRTools.func(ir3)(nothing, 2) == foo2(2)
@test IRTools.func(ir3)(nothing, -2) == foo2(-2)
end

0 comments on commit 5cdd662

Please sign in to comment.