Skip to content

Commit

Permalink
don't call staged functions on abstract types during inference
Browse files Browse the repository at this point in the history
this is a bit drastic, but otherwise there is too much risk of type
unsoundness. fixes #8504
  • Loading branch information
JeffBezanson committed Mar 5, 2015
1 parent 46bcd77 commit 6d0db53
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,14 @@ let stagedcache=Dict{Any,Any}()
elseif haskey(stagedcache,(m,tt,env))
return stagedcache[(m,tt,env)].code
else
f=ccall(:jl_instantiate_staged,Any,(Any,Any,Any),m,tt,env)
stagedcache[(m,tt,env)]=f
if !isleaftype(tt)
# don't call staged functions on abstract types.
# (see issues #8504, #10230)
# we can't guarantee that their type behavior is monotonic.
error()
end
f = ccall(:jl_instantiate_staged,Any,(Any,Any,Any),m,tt,env)
stagedcache[(m,tt,env)] = f
return f.code
end
end
Expand Down
4 changes: 2 additions & 2 deletions base/reducedim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ stagedfunction _mapreducedim!{T,N}(f, op, R::AbstractArray, A::AbstractArray{T,N
end
end

mapreducedim!(f, op, R::AbstractArray, A::AbstractArray) = _mapreducedim!(f, op, R, A)
mapreducedim!(f, op, R::AbstractArray, A::AbstractArray) = (_mapreducedim!(f, op, R, A); R)

This comment has been minimized.

Copy link
@StefanKarpinski

StefanKarpinski Mar 5, 2015

Member

Are these changes related or did they slip in by accident?

This comment has been minimized.

Copy link
@timholy

timholy Mar 5, 2015

Member

to_op(op) = op
function to_op(op::Function)
Expand All @@ -201,7 +201,7 @@ function to_op(op::Function)
end

mapreducedim!(f, op, R::AbstractArray, A::AbstractArray) =
_mapreducedim!(f, to_op(op), R, A)
(_mapreducedim!(f, to_op(op), R, A); R)

reducedim!{RT}(op, R::AbstractArray{RT}, A::AbstractArray) =
mapreducedim!(IdFun(), op, R, A, zero(RT))
Expand Down

0 comments on commit 6d0db53

Please sign in to comment.