Skip to content

Commit

Permalink
Make Extrema example compilable
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Jan 16, 2019
1 parent 50ab48e commit 6d99ccf
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ not defined for `R_{X}`, this happens automatically.
complete(f, result) = f(result)
complete(rf::Reduction, result) =
# Not using dispatch to avoid ambiguity
if result isa PrivateState{typeof(rf)}
if ownsstate(rf, result)
complete(rf.inner, unwrap(rf, result)[2])
else
complete(rf.inner, result)
Expand All @@ -214,10 +214,10 @@ complete(rf::Reduction, result) =
combine(f, a, b) = f(a, b)
combine(rf::Reduction, a, b) =
# Not using dispatch to avoid ambiguity
if a isa PrivateState{typeof(rf)}
if ownsstate(rf, a)
# TODO: make sure this branch is compiled out
error("Stateful transducer ", rf.xform, " does not support `combine`")
elseif b isa PrivateState{typeof(rf)}
elseif ownsstate(rf, b)
error("""
Some thing went wrong in two ways:
* `combine(rf, a, b)` is called but type of `a` and `b` are different.
Expand All @@ -236,6 +236,13 @@ end
PrivateState(rf::Reduction, state, result) =
PrivateState{typeof(rf), typeof(state), typeof(result)}(state, result)

ownsstate(::Any, ::Any) = false
ownsstate(::R, ::PrivateState{T}) where {R, T} = R === T
# Using `result isa PrivateState{typeof(rf)}` makes it impossible to
# compile Extrema examples in ../examples/tutorial_missings.jl (it
# took more than 10 min). See also:
# https://github.com/JuliaLang/julia/issues/30125

"""
unwrap(rf, result)
Expand Down

0 comments on commit 6d99ccf

Please sign in to comment.