Skip to content

Commit

Permalink
Fix non-uniformity in nothrow queries with PartialTypeVar (#33751)
Browse files Browse the repository at this point in the history
We were missing a case in the lattice operation for
⊑(::PartialTypeVar, ::Type{TypeVar}) causing non-uniformity for
various nothrow queries. Additionally `apply_type_nothrow` was
using `===` rather than `⊑`, causing additional problems there
even after the fix.
  • Loading branch information
Keno authored Nov 3, 2019
1 parent c7e4b99 commit 5294219
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ function apply_type_nothrow(argtypes::Array{Any, 1}, @nospecialize(rt))
for i = 2:length(argtypes)
isa(u, UnionAll) || return false
ai = widenconditional(argtypes[i])
if ai === TypeVar
if ai TypeVar
# We don't know anything about the bounds of this typevar, but as
# long as the UnionAll is not constrained, that's ok.
if !(u.var.lb === Union{} && u.var.ub === Any)
Expand Down
2 changes: 2 additions & 0 deletions base/compiler/typelattice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ function ⊑(@nospecialize(a), @nospecialize(b))
return a.instance === b.val
end
return false
elseif isa(a, PartialTypeVar) && b === TypeVar
return true
elseif !(isa(a, Type) || isa(a, TypeVar)) ||
!(isa(b, Type) || isa(b, TypeVar))
return a === b
Expand Down
8 changes: 8 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2456,3 +2456,11 @@ const DenseIdx = Union{IntRange,Integer}
@inline foo_26724(result, r::IntRange, I::DenseIdx...) =
foo_26724((result..., length(r)), I...)
@test @inferred(foo_26724((), 1:4, 1:5, 1:6)) === (4, 5, 6)

# Non uniformity in expresions with PartialTypeVar
@test Core.Compiler.:(Core.Compiler.PartialTypeVar(TypeVar(:N), true, true), TypeVar)
let N = TypeVar(:N)
@test Core.Compiler.apply_type_nothrow([Core.Compiler.Const(NTuple),
Core.Compiler.PartialTypeVar(N, true, true),
Core.Compiler.Const(Any)], Type{Tuple{Vararg{Any,N}}})
end

2 comments on commit 5294219

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

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

Please sign in to comment.