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

Deal with _apply_iterate #158

Merged
merged 3 commits into from
Jan 20, 2020
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ julia:
- 1.0
- 1.1
- 1.2
- 1.3
- nightly
matrix:
allow_failures:
Expand Down
3 changes: 3 additions & 0 deletions src/context.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ macro context(_Ctx)
@inline Cassette.overdub(::C, ::Typeof(Tag), ::Type{N}, ::Type{X}) where {C<:$Ctx,N,X} = Tag(N, X, tagtype(C))

@inline Cassette.overdub(ctx::$Ctx, ::typeof(Core._apply), f, args...) = Core._apply(overdub, (ctx, f), args...)
if VERSION >= v"1.4.0-DEV.304"
@inline Cassette.overdub(ctx::$Ctx, ::typeof(Core._apply_iterate), f, args...) = Core._apply_iterate((args...)->overdub(ctx, f, args...), args...)
end

# TODO: There are certain non-`Core.Builtin` functions which the compiler often
# relies upon constant propagation/tfuncs to infer, instead of specializing on
Expand Down
3 changes: 3 additions & 0 deletions src/overdub.jl
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,9 @@ function overdub end
function recurse end

recurse(ctx::Context, ::typeof(Core._apply), f, args...) = Core._apply(recurse, (ctx, f), args...)
if VERSION >= v"1.4.0-DEV.304"
recurse(ctx::Context, ::typeof(Core._apply_iterate), f, args...) = Core._apply_iterate((args...)->recurse(ctx, f, args...), args...)
end

function overdub_definition(line, file)
return quote
Expand Down
44 changes: 39 additions & 5 deletions test/misctests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,21 @@ kwargtest(foobar; foo = 1, bar = 2) = nothing
@inferred(overdub(InferCtx(), eltype, rand(1)))
@inferred(overdub(InferCtx(), *, rand(1, 1), rand(1, 1)))
@inferred(overdub(InferCtx(), *, rand(Float32, 1, 1), rand(Float32, 1, 1)))
@inferred(overdub(InferCtx(), *, rand(Float32, 1, 1), rand(Float32, 1)))
@inferred(overdub(InferCtx(), rand, Float32, 1))
@inferred(overdub(InferCtx(), broadcast, +, rand(1), rand(1)))
@inferred(overdub(InferCtx(), relulayer, rand(Float64, 1, 1), rand(Float32, 1), rand(Float32, 1)))
if VERSION <= v"1.3"
@inferred(overdub(InferCtx(), *, rand(Float32, 1, 1), rand(Float32, 1)))
@inferred(overdub(InferCtx(), rand, Float32, 1))
@inferred(overdub(InferCtx(), broadcast, +, rand(1), rand(1)))
@inferred(overdub(InferCtx(), relulayer, rand(Float64, 1, 1), rand(Float32, 1), rand(Float32, 1)))
else
# test depends on constant propagation
@test_throws Exception @inferred(overdub(InferCtx(), *, rand(Float32, 1, 1), rand(Float32, 1)))
# XXX: Figure out why this broke
@test_throws Exception @inferred(overdub(InferCtx(), rand, Float32, 1))
# XXX: Figure out why this broke
@test_throws Exception @inferred(overdub(InferCtx(), broadcast, +, rand(1), rand(1)))
# XXX: Figure out why this broke
@test_throws Exception @inferred(overdub(InferCtx(), relulayer, rand(Float64, 1, 1), rand(Float32, 1), rand(Float32, 1)))
end
@inferred(overdub(InferCtx(), () -> kwargtest(42; foo = 1, bar = 2)))

println("done (took ", time() - before_time, " seconds)")
Expand Down Expand Up @@ -669,6 +680,29 @@ end
print(" running OverdubOverdubCtx test...")

# Fixed in PR #148
Cassette.@context OverdubOverdubCtx;
Cassette.@context OverdubOverdubCtx
overdub_overdub_me() = 2
Cassette.overdub(OverdubOverdubCtx(), Cassette.overdub, OverdubOverdubCtx(), overdub_overdub_me)

#############################################################################################

print(" running NukeCtx test...")

@Cassette.context NukeContext
struct Silo; end

Base.iterate(x::Silo) = (println("Launching Nukes"); error("What's the point?"))

function Cassette.overdub(ctx::NukeContext, ::typeof(iterate), x::Silo)
nothing
end

@test Cassette.overdub(NukeContext(), iterate, Silo()) === nothing

launch(s::Silo) = (s...,)

if VERSION >= v"1.4.0-DEV.304"
@test Cassette.overdub(NukeContext(), launch, Silo()) === ()
else
@test_broken Cassette.overdub(NukeContext(), launch, Silo()) === ()
end