Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
11 changes: 9 additions & 2 deletions src/copyable_task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ the current world age, will make a copy of an existing `MistyClosure`. If not,
will derive it from scratch (derive the IR + compile it etc).
"""
function build_callable(sig::Type{<:Tuple})
if sig <: Tuple{typeof(produce),Any}
msg = """
Can not construct a TapedTask for a 'naked' call to `produce`.
Please wrap the call to `produce` in a function, and construct a
TapedTask from that function."""
throw(ArgumentError(msg))
end
key = CacheKey(Base.get_world_counter(), sig)
if haskey(mc_cache, key)
return fresh_copy(mc_cache[key])
Expand Down Expand Up @@ -367,8 +374,8 @@ get_value(x) = x
expression, otherwise `false`.
"""
function is_produce_stmt(x)::Bool
if Meta.isexpr(x, :invoke) && length(x.args) == 3
return get_value(x.args[2]) === produce
if Meta.isexpr(x, :invoke) && length(x.args) == 3 && x.args[1] isa Core.MethodInstance
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably the right thing to do. In versions 1.10 and 1.11 it's definitely the case that the first argument in an :invoke expression must be a Core.MethodInstance (to the best of my knowledge). However, this might change in later versions, so this check feels appropriate.

return x.args[1].specTypes <: Tuple{typeof(produce),Any}
elseif Meta.isexpr(x, :call) && length(x.args) == 2
return get_value(x.args[1]) === produce
else
Expand Down
11 changes: 11 additions & 0 deletions test/copyable_task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@
@test ex isa BoundsError
end
end

@testset "Naked produce" begin
@test_throws "wrap the call to `produce` in a function" Libtask.consume(
Libtask.TapedTask(nothing, Libtask.produce, 0)
)
end
end

@testset "copying" begin
Expand Down Expand Up @@ -209,4 +215,9 @@
end
@test ex === nothing
end

@testset "Issue #185" begin
g() = produce(rand() > -1.0 ? 2 : 0.1)
@test Libtask.consume(Libtask.TapedTask(nothing, g)) == 2
end
end
Loading