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

implement splatnew #125

Merged
merged 3 commits into from
Jun 29, 2019
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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ language: julia
os:
- linux
julia:
- 0.7
- 1.0
- 1.1
- 1.2
- nightly
matrix:
allow_failures:
Expand Down
13 changes: 8 additions & 5 deletions src/overdub.jl
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ function overdub_pass!(reflection::Reflection,
i >= original_code_start_index || return nothing
stmt = Base.Meta.isexpr(x, :(=)) ? x.args[2] : x
Base.Meta.isexpr(stmt, :replaceglobalref) && return 1
if isa(stmt, Expr) # Base.Meta.isexpr(stmt, :call) || Base.Meta.isexpr(stmt, :new) || Base.Meta.isexpr(stmt, :return)
if isa(stmt, Expr)
count = 0
for arg in stmt.args
if Base.Meta.isexpr(arg, :replaceglobalref)
Expand All @@ -280,7 +280,7 @@ function overdub_pass!(reflection::Reflection,
globalref = stmt.args[2]
name = QuoteNode(globalref.name)
result = Expr(:call, Expr(:nooverdub, GlobalRef(Cassette, :tagged_globalref)), overdub_ctx_slot, tagmodssa, name, globalref)
elseif isa(stmt, Expr) # Base.Meta.isexpr(stmt, :call) || Base.Meta.isexpr(stmt, :new) || Base.Meta.isexpr(stmt, :return)
elseif isa(stmt, Expr)
result = Expr(stmt.head)
for arg in stmt.args
if Base.Meta.isexpr(arg, :replaceglobalref)
Expand Down Expand Up @@ -350,11 +350,13 @@ function overdub_pass!(reflection::Reflection,
])
end

#=== replace `Expr(:new, ...)` with `Expr(:call, :tagged_new)` if tagging is enabled ===#
#=== replace `Expr(:new, ...)`/`Expr(:splatnew, ...)` with ===#
#=== `Expr(:call, :tagged_new)`/`Expr(:call, :tagged_splatnew)` if tagging is enabled ===#

if istaggingenabled && !iskwfunc
replace_match!(x -> Base.Meta.isexpr(x, :new), overdubbed_code) do x
return Expr(:call, Expr(:nooverdub, GlobalRef(Cassette, :tagged_new)), overdub_ctx_slot, x.args...)
replace_match!(x -> Base.Meta.isexpr(x, :new) || Base.Meta.isexpr(x, :splatnew), overdubbed_code) do x
tagged_version = x.head == :new ? :tagged_new : :tagged_splatnew
return Expr(:call, Expr(:nooverdub, GlobalRef(Cassette, tagged_version)), overdub_ctx_slot, x.args...)
end
end

Expand Down Expand Up @@ -569,6 +571,7 @@ If `Cassette.hastagging(typeof(context))`, then a number of additional passes ar
order to accomodate tagged value propagation:

- `Expr(:new)` is replaced with a call to `Cassette.tagged_new`
- `Expr(:splatnew)` is replaced with a call to `Cassette.tagged_splatnew`
- conditional values passed to `Expr(:gotoifnot)` are untagged
- arguments to `Expr(:foreigncall)` are untagged
- load/stores to external module bindings are intercepted by the tagging system
Expand Down
8 changes: 5 additions & 3 deletions src/tagging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,9 @@ destructstate(ctx, state) = untag(state, ctx)
Base.iterate(t::Tagged) = destructstate(t.context, overdub(t.context, iterate, t))
Base.iterate(t::Tagged, state) = destructstate(t.context, overdub(t.context, iterate, t, state))

################
# `tagged_new` #
################
##################################
# `tagged_new`/`tagged_splatnew` #
##################################

@generated function tagged_new(context::C, ::Type{T}, args...) where {C<:Context,T}
argmetaexprs = Any[]
Expand Down Expand Up @@ -493,6 +493,8 @@ Base.iterate(t::Tagged, state) = destructstate(t.context, overdub(t.context, ite
end
end

@inline tagged_splatnew(context::Context, T::Type, args) = tagged_new(context, T, args...)

@generated function tagged_new_array(context::C, ::Type{T}, args...) where {C<:Context,T<:Array}
untagged_args = [:(untag(args[$i], context)) for i in 1:nfields(args)]
return quote
Expand Down