Skip to content
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 on nightly #182

Merged
merged 2 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/overdub.jl
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,21 @@ function overdub_pass!(reflection::Reflection,
#=== untag `gotoifnot` conditionals if tagging is enabled ===#

if istaggingenabled && !iskwfunc
insert_statements!(overdubbed_code, overdubbed_codelocs,
(x, i) -> Base.Meta.isexpr(x, :gotoifnot) ? 2 : nothing,
(x, i) -> [
Expr(:call, Expr(:nooverdub, GlobalRef(Cassette, :untag)), x.args[1], overdub_ctx_slot),
Expr(:gotoifnot, SSAValue(i), x.args[2])
])
@static if isdefined(Core, :GotoIfNot)
insert_statements!(overdubbed_code, overdubbed_codelocs,
(x, i) -> isa(x, Core.GotoIfNot) ? 2 : nothing,
(x, i) -> [
Expr(:call, Expr(:nooverdub, GlobalRef(Cassette, :untag)), x.cond, overdub_ctx_slot),
Core.GotoIfNot(SSAValue(i), x.dest)
])
else
insert_statements!(overdubbed_code, overdubbed_codelocs,
(x, i) -> Base.Meta.isexpr(x, :gotoifnot) ? 2 : nothing,
(x, i) -> [
Expr(:call, Expr(:nooverdub, GlobalRef(Cassette, :untag)), x.args[1], overdub_ctx_slot),
Expr(:gotoifnot, SSAValue(i), x.args[2])
])
end
end

#=== replace `Expr(:new, ...)`/`Expr(:splatnew, ...)` with ===#
Expand Down
6 changes: 5 additions & 1 deletion test/misctaggingtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ before_time = time()

@context ApplyCtx
x = rand()
applytest(x) = Core._apply(hypot, (x,), (1, x), 1, x, (1, 2))
@static if isdefined(Core, :_apply_iterate)
applytest(x) = Core._apply_iterate(iterate, hypot, (x,), (1, x), 1, x, (1, 2))
else
applytest(x) = Core._apply(hypot, (x,), (1, x), 1, x, (1, 2))
end
ctx = enabletagging(ApplyCtx(), 1)
@test overdub(ctx, applytest, tag(x, ctx)) === applytest(x)

Expand Down
27 changes: 19 additions & 8 deletions test/misctests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -617,14 +617,25 @@ function sliceprintln(::Type{<:SliceCtx}, reflection::Cassette.Reflection)
end)

# replace return statements of the form `return x` with `return (x, callback)`
Cassette.insert_statements!(ir.code, ir.codelocs,
(stmt, i) -> Base.Meta.isexpr(stmt, :return) ? 2 : nothing,
(stmt, i) -> begin
return [
Expr(:call, Expr(:nooverdub, GlobalRef(Core, :tuple)), stmt.args[1], callbackslot)
Expr(:return, SSAValue(i))
]
end)
@static if isdefined(Core, :ReturnNode)
Cassette.insert_statements!(ir.code, ir.codelocs,
(stmt, i) -> isa(stmt, Core.ReturnNode) ? 2 : nothing,
(stmt, i) -> begin
return [
Expr(:call, Expr(:nooverdub, GlobalRef(Core, :tuple)), stmt.val, callbackslot),
Core.ReturnNode(SSAValue(i))
]
end)
else
Cassette.insert_statements!(ir.code, ir.codelocs,
(stmt, i) -> Base.Meta.isexpr(stmt, :return) ? 2 : nothing,
(stmt, i) -> begin
return [
Expr(:call, Expr(:nooverdub, GlobalRef(Core, :tuple)), stmt.args[1], callbackslot),
Expr(:return, SSAValue(i))
]
end)
end
return ir
end

Expand Down
7 changes: 6 additions & 1 deletion test/unittests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
using InteractiveUtils: subtypes
using Core.Compiler: SSAValue, Const, GotoNode


function const_bool_retval(f, sig)
ctyped = code_typed(f, sig)[1].first
retval = ctyped.code[end]
retval = isa(retval, GotoNode) ? ctyped.code[retval.label] : retval
retval = Meta.isexpr(retval, :return) ? retval.args[1] : retval
@static if isdefined(Core, :ReturnNode)
retval = isa(retval, Core.ReturnNode) ? retval.val : retval
else
retval = Meta.isexpr(retval, :return) ? retval.args[1] : retval
end
retval = isa(retval, SSAValue) ? ctyped.ssavaluetypes[retval.id] : retval
retval = isa(retval, Const) ? retval.val : retval
isa(retval, Bool) && return retval
Expand Down