Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix type intersection for invalidation during method insertion to handle typevars properly #27351

Merged
merged 4 commits into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 11 additions & 1 deletion src/typemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,19 @@ int jl_typemap_intersection_visitor(union jl_typemap_t map, int offs,
ty = jl_tparam(ttypes, offs);
}
if (ty) {
while (jl_is_typevar(ty))
ty = ((jl_tvar_t*)ty)->ub;
// approxify the tparam until we have a valid type
Copy link
Member

Choose a reason for hiding this comment

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

approxify is not a word unless you live in silicon valley.

Copy link
Member Author

@jrevels jrevels Jun 1, 2018

Choose a reason for hiding this comment

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

I didn't write that comment, it's a good ol' fashioned jamesonism

EDIT: just to clarify, I stand by approxify in all of its linguistic glory

if (jl_has_free_typevars(ty)) {
ty = jl_unwrap_unionall(ty);
if (jl_is_datatype(ty))
ty = ((jl_datatype_t*)ty)->name->wrapper;
else
ty = (jl_value_t*)jl_any_type;
}
if (cache->targ.values != (void*)jl_nothing) {
jl_value_t *typetype = jl_is_type_type(ty) ? jl_tparam0(ty) : NULL;
if (typetype && !jl_has_free_typevars(typetype)) {
if (typetype) {
if (is_cache_leaf(typetype)) {
// direct lookup of leaf types
union jl_typemap_t ml = mtcache_hash_lookup(&cache->targ, typetype, 1, offs);
Expand Down
1 change: 1 addition & 0 deletions stdlib/SparseArrays/src/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,7 @@ for (fun, mode) in [(:+, 1), (:-, 1), (:*, 0), (:min, 2), (:max, 2)]
end
@eval begin
map(::typeof($fun), x::AbstractSparseVector, y::AbstractSparseVector) = _binarymap($fun, x, y, $mode)
map(::typeof($fun), x::SparseVector, y::SparseVector) = _binarymap($fun, x, y, $mode)
broadcast(::typeof($fun), x::AbstractSparseVector, y::AbstractSparseVector) = _bcast_binary_map($fun, x, y, $mode)
broadcast(::typeof($fun), x::SparseVector, y::SparseVector) = _bcast_binary_map($fun, x, y, $mode)
end
Expand Down
10 changes: 10 additions & 0 deletions test/compiler/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1597,3 +1597,13 @@ end
@test Core.Compiler.return_type(Core.apply_type, Tuple{Type{Union},Any,Int}) == Union{}
@test Core.Compiler.return_type(Core.apply_type, Tuple{Any}) == Type
@test Core.Compiler.return_type(Core.apply_type, Tuple{Any,Any}) == Type

# PR 27351, make sure optimized type intersection for method invalidation handles typevars

abstract type AbstractT27351 end
struct T27351 <: AbstractT27351 end
for i27351 in 1:15
@eval f27351(::Val{$i27351}, ::AbstractT27351, ::AbstractT27351) = $i27351
end
f27351(::T, ::T27351, ::T27351) where {T} = 16
@test_throws MethodError f27351(Val(1), T27351(), T27351())