-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
fix ssa conversion for catch blocks #117
Changes from 5 commits
4651208
284684c
0c9c2bd
43fc812
44f59c3
1d45fcb
2d6242d
f728dc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,7 @@ function err3(f) | |
end | ||
|
||
@test passthrough(err3, () -> 2+2) == 4 | ||
@test_broken passthrough(err3, () -> 0//0) == 1 | ||
@test passthrough(err3, () -> 0//0) == 1 | ||
|
||
@dynamo function mullify(a...) | ||
ir = IR(a...) | ||
|
@@ -211,3 +211,140 @@ end | |
@test (code_typed(func_ir, Tuple{typeof(func_ir)}) |> only | ||
isa Pair{Core.CodeInfo,DataType}) | ||
end | ||
|
||
function f_try_catch(x) | ||
y = 0. | ||
try | ||
y = sqrt(x) | ||
catch | ||
|
||
end | ||
y | ||
end | ||
|
||
function f_try_catch2(x, cond) | ||
local y | ||
if cond | ||
y = 2x | ||
end | ||
|
||
try | ||
x = 3 * error() | ||
catch | ||
end | ||
|
||
y | ||
end | ||
|
||
function f_try_catch3() | ||
local x | ||
try | ||
error() | ||
catch | ||
x = 42 | ||
end | ||
x | ||
end | ||
|
||
function f_try_catch4(x, cond) | ||
local y | ||
try | ||
throw(x) | ||
catch err | ||
if cond | ||
y = err + x | ||
end | ||
end | ||
y | ||
end | ||
|
||
function f_try_catch5(x, cond) | ||
local y | ||
cond && (x = 2x) | ||
try | ||
y = x | ||
cond && error() | ||
catch | ||
y = x + 1 | ||
end | ||
y | ||
end | ||
|
||
function f_try_catch6(cond, y) | ||
x = 1 | ||
|
||
if cond | ||
y = 10y | ||
else | ||
y = 10y | ||
end | ||
|
||
try | ||
cond && error() | ||
catch | ||
y = 2x | ||
end | ||
|
||
y+x | ||
end | ||
|
||
function f_try_catch7() | ||
local x = 1. | ||
|
||
for _ in 1:10 | ||
|
||
try | ||
x = sqrt(x) | ||
x -= 1. | ||
catch | ||
x = -x | ||
end | ||
|
||
x = x ^ 2 | ||
end | ||
|
||
x | ||
end | ||
|
||
@testset "try/catch" begin | ||
ir = @code_ir f_try_catch(1.) | ||
fir = func(ir) | ||
@test fir(nothing,1.) === 1. | ||
@test fir(nothing,-1.) === 0. | ||
|
||
ir = @code_ir f_try_catch2(1., false) | ||
fir = func(ir) | ||
|
||
# This should be @test_throws UndefVarError fir(nothing,42,false) | ||
# See TODO in `IRTools.slots!` | ||
@test fir(nothing, 42, false) === IRTools.undef | ||
@test fir(nothing, 42, true) === 84 | ||
|
||
ir = @code_ir f_try_catch3() | ||
@test any(ir) do (_, stmt) | ||
IRTools.isexpr(stmt.expr, :catch) && | ||
length(stmt.expr.args) == 1 | ||
end | ||
fir = func(ir) | ||
@test fir(nothing) == 42 | ||
|
||
ir = @code_ir f_try_catch4(42, false) | ||
fir = func(ir) | ||
# This should be @test_throws UndefVarError fir(nothing,42,false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. It looks like |
||
# See TODO in `IRTools.slots!` | ||
@test fir(nothing, 42, false) === IRTools.undef | ||
@test fir(nothing, 42, true) === 84 | ||
|
||
ir = @code_ir f_try_catch5(1, false) | ||
fir = func(ir) | ||
@test fir(nothing, 3, false) === 3 | ||
@test fir(nothing, 3, true) === 7 | ||
|
||
ir = @code_ir f_try_catch6(true, 1) | ||
fir = func(ir) | ||
@test fir(nothing, true, 1) === 3 | ||
@test fir(nothing, false, 1) === 11 | ||
|
||
ir = @code_ir f_try_catch7() | ||
@test func(ir)(nothing) === 1. | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is purely just a clarification of the existing code, right? to rename
v
toslot
(A good clarification)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! In other parts of the package,
v
often refers to aVariable
(SSA value) so I renamed to clarify.