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

set default max_methods to 3 #36208

Merged
merged 3 commits into from
Jun 19, 2020
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
2 changes: 1 addition & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ end
size(a::Array, d::Integer) = arraysize(a, convert(Int, d))
size(a::Vector) = (arraysize(a,1),)
size(a::Matrix) = (arraysize(a,1), arraysize(a,2))
size(a::Array{<:Any,N}) where {N} = (@_inline_meta; ntuple(M -> size(a, M), Val(N)))
size(a::Array{<:Any,N}) where {N} = (@_inline_meta; ntuple(M -> size(a, M), Val(N))::Dims)

asize_from(a::Array, n) = n > ndims(a) ? () : (arraysize(a,n), asize_from(a, n+1)...)

Expand Down
15 changes: 14 additions & 1 deletion base/compiler/typelimits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,20 @@ function tmerge(@nospecialize(typea), @nospecialize(typeb))
widen = tuplemerge(unwrap_unionall(ti)::DataType, unwrap_unionall(tj)::DataType)
widen = rewrap_unionall(rewrap_unionall(widen, ti), tj)
else
widen = typenames[i].wrapper
wr = typenames[i].wrapper
uw = unwrap_unionall(wr)::DataType
ui = unwrap_unionall(ti)::DataType
uj = unwrap_unionall(tj)::DataType
merged = wr
for k = 1:length(uw.parameters)
ui_k = ui.parameters[k]
if ui_k === uj.parameters[k] && !has_free_typevars(ui_k)
merged = merged{ui_k}
else
merged = merged{uw.parameters[k]}
end
end
widen = rewrap_unionall(merged, wr)
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this is entirely sound, due mainly to losing where bounds, but also wondering if it'd mismatch TypeVars coming from different places. What if we had something like:

struct MyType{A, B, C, D} end
T = TypeVar(:T)
S = TypeVar(:S)
A = UnionAll(T, MyType{T, S, T, Pair{T, S}})
B = UnionAll(T, MyType{S, T, T, Pair{T, S}})

The merge result would appear to be:

MyType{A, B, T, Pair{T, S}} where B where A

Which, I think the only issue it has is that it's missing where T, but just checking

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right. I'll exclude anything with free typevars.

end
types[i] = Union{}
typenames[i] = Any.name
Expand Down
4 changes: 2 additions & 2 deletions base/compiler/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct OptimizationParams
inline_cost_threshold::Int = 100,
inline_nonleaf_penalty::Int = 1000,
inline_tupleret_bonus::Int = 400,
max_methods::Int = 4,
max_methods::Int = 3,
tuple_splat::Int = 32,
union_splitting::Int = 4,
)
Expand Down Expand Up @@ -107,7 +107,7 @@ struct InferenceParams
function InferenceParams(;
ipo_constant_propagation::Bool = true,
aggressive_constant_propagation::Bool = false,
max_methods::Int = 4,
max_methods::Int = 3,
union_splitting::Int = 4,
apply_union_enum::Int = 8,
tupletype_depth::Int = 3,
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Random/src/Random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ rand(rng::AbstractRNG, ::UniformT{T}) where {T} = rand(rng, T)
rand(rng::AbstractRNG, X) = rand(rng, Sampler(rng, X, Val(1)))
# this is needed to disambiguate
rand(rng::AbstractRNG, X::Dims) = rand(rng, Sampler(rng, X, Val(1)))
rand(rng::AbstractRNG=default_rng(), ::Type{X}=Float64) where {X} = rand(rng, Sampler(rng, X, Val(1)))
rand(rng::AbstractRNG=default_rng(), ::Type{X}=Float64) where {X} = rand(rng, Sampler(rng, X, Val(1)))::X

rand(X) = rand(default_rng(), X)
rand(::Type{X}) where {X} = rand(default_rng(), X)
Expand Down
1 change: 1 addition & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ tmerge_test(Tuple{}, Tuple{Complex, Vararg{Union{ComplexF32, ComplexF64}}},
Union{Nothing, Tuple{Vararg{ComplexF32}}}
@test Core.Compiler.tmerge(Union{Nothing, Tuple{ComplexF32}}, Union{Nothing, Tuple{ComplexF32, ComplexF32}}) ==
Union{Nothing, Tuple{Vararg{ComplexF32}}}
@test Core.Compiler.tmerge(Vector{Int}, Core.Compiler.tmerge(Vector{String}, Vector{Bool})) == Vector

# issue 9770
@noinline x9770() = false
Expand Down
17 changes: 15 additions & 2 deletions test/worlds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,12 @@ applyf35855(Any[1])
wany3 = worlds(instance(applyf35855, (Vector{Any},)))
src3 = code_typed(applyf35855, (Vector{Any},))[1]
@test (wany3 == wany2) == equal(src3, src2) # don't invalidate unless you also change the code
f35855(::AbstractVector) = 4 # next test would pass if this were ::Vector{Int}
f35855(::AbstractVector) = 4
applyf35855(Any[1])
wany4 = worlds(instance(applyf35855, (Vector{Any},)))
src4 = code_typed(applyf35855, (Vector{Any},))[1]
@test_broken (wany4 == wany3) == equal(src4, src3)
# this passes when max_methods == 3, fails when set to 4
@test (wany4 == wany3) == equal(src4, src3)
f35855(::Dict) = 5
applyf35855(Any[1])
wany5 = worlds(instance(applyf35855, (Vector{Any},)))
Expand All @@ -291,6 +292,18 @@ wany6 = worlds(instance(applyf35855, (Vector{Any},)))
src6 = code_typed(applyf35855, (Vector{Any},))[1]
@test (wany6 == wany5) == equal(src6, src5)

applyf35855_2(c) = f35855_2(c[1])
f35855_2(::Int) = 1
f35855_2(::Float64) = 2
applyf35855_2(Any[1])
wany3 = worlds(instance(applyf35855_2, (Vector{Any},)))
src3 = code_typed(applyf35855_2, (Vector{Any},))[1]
f35855_2(::AbstractVector) = 4 # next test would pass if this were ::Vector{Int}
applyf35855_2(Any[1])
wany4 = worlds(instance(applyf35855_2, (Vector{Any},)))
src4 = code_typed(applyf35855_2, (Vector{Any},))[1]
@test_broken (wany4 == wany3) == equal(src4, src3)

## ambiguities do not trigger invalidation
using Printf
Printf.gen("%f")
Expand Down