Skip to content

Commit f30c949

Browse files
authoredSep 16, 2016
Merge pull request #18467 from TotalVerb/fw/inference-vararg
Work around inference bug with Vararg
2 parents e781d08 + 6bffa3c commit f30c949

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed
 

‎base/inference.jl

+12-11
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ cmp_tfunc = (x,y)->Bool
242242

243243
isType(t::ANY) = isa(t,DataType) && is((t::DataType).name,Type.name)
244244

245+
# true if Type is inlineable as constant
246+
isconstType(t::ANY,b::Bool) =
247+
isType(t) && !has_typevars(t.parameters[1],b) &&
248+
!issubtype(Tuple{Vararg}, t.parameters[1]) # work around inference bug #18450
249+
245250
const IInf = typemax(Int) # integer infinity
246251
const n_ifunc = reinterpret(Int32,arraylen)+1
247252
const t_ifunc = Array{Tuple{Int,Int,Any},1}(n_ifunc)
@@ -990,7 +995,7 @@ end
990995

991996
function pure_eval_call(f::ANY, argtypes::ANY, atype, vtypes, sv)
992997
for a in drop(argtypes,1)
993-
if !(isa(a,Const) || (isType(a) && !has_typevars(a.parameters[1])))
998+
if !(isa(a,Const) || isconstType(a,false))
994999
return false
9951000
end
9961001
end
@@ -1965,7 +1970,7 @@ function finish(me::InferenceState)
19651970
# need to add coverage support to the `jl_call_method_internal` fast path
19661971
if !do_coverage &&
19671972
((isa(me.bestguess,Const) && me.bestguess.val !== nothing) ||
1968-
(isType(me.bestguess) && !has_typevars(me.bestguess.parameters[1],true)))
1973+
isconstType(me.bestguess,true))
19691974
if !ispure && length(me.src.code) < 10
19701975
ispure = true
19711976
for stmt in me.src.code
@@ -2388,7 +2393,7 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atypes::Vector{Any}, sv::Inference
23882393
topmod = _topmod(sv)
23892394
# special-case inliners for known pure functions that compute types
23902395
if sv.inlining
2391-
if isType(e.typ) && !has_typevars(e.typ.parameters[1],true)
2396+
if isconstType(e.typ,true)
23922397
if (is(f, apply_type) || is(f, fieldtype) || is(f, typeof) ||
23932398
istopfunction(topmod, f, :typejoin) ||
23942399
istopfunction(topmod, f, :promote_type))
@@ -2539,14 +2544,10 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atypes::Vector{Any}, sv::Inference
25392544
methsp = meth[2]
25402545
method = meth[3]::Method
25412546
# check whether call can be inlined to just a quoted constant value
2542-
if isa(f, widenconst(ft)) && !method.isstaged && (method.source.pure || f === return_type) &&
2543-
(isType(e.typ) || isa(e.typ,Const))
2544-
if isType(e.typ)
2545-
if !has_typevars(e.typ.parameters[1])
2546-
return inline_as_constant(e.typ.parameters[1], argexprs, sv)
2547-
end
2548-
else
2549-
assert(isa(e.typ,Const))
2547+
if isa(f, widenconst(ft)) && !method.isstaged && (method.source.pure || f === return_type)
2548+
if isconstType(e.typ,false)
2549+
return inline_as_constant(e.typ.parameters[1], argexprs, sv)
2550+
elseif isa(e.typ,Const)
25502551
return inline_as_constant(e.typ.val, argexprs, sv)
25512552
end
25522553
end

‎test/inference.jl

+4
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,7 @@ function test18399(C)
364364
return hvcat18399(((2, 3),))
365365
end
366366
@test test18399(C18399) == (2, 3)
367+
368+
# issue #18450
369+
f18450() = ifelse(true, Tuple{Vararg{Int}}, Tuple{Vararg})
370+
@test f18450() == Tuple{Vararg{Int}}

2 commit comments

Comments
 (2)

yuyichao commented on Sep 19, 2016

@yuyichao
Contributor

@nanosoldier runbenchmarks(ALL, vs="@e781d08180a96519e84793e872c96e095df95c79")

e781d08

nanosoldier commented on Sep 19, 2016

@nanosoldier
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels

Please sign in to comment.