Skip to content

Commit c669e2b

Browse files
committed
set default max_methods to 3
1 parent 8ca6e8d commit c669e2b

File tree

6 files changed

+33
-7
lines changed

6 files changed

+33
-7
lines changed

base/array.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ end
154154
size(a::Array, d::Integer) = arraysize(a, convert(Int, d))
155155
size(a::Vector) = (arraysize(a,1),)
156156
size(a::Matrix) = (arraysize(a,1), arraysize(a,2))
157-
size(a::Array{<:Any,N}) where {N} = (@_inline_meta; ntuple(M -> size(a, M), Val(N)))
157+
size(a::Array{<:Any,N}) where {N} = (@_inline_meta; ntuple(M -> size(a, M), Val(N))::Dims)
158158

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

base/compiler/typelimits.jl

+13-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,19 @@ function tmerge(@nospecialize(typea), @nospecialize(typeb))
391391
widen = tuplemerge(unwrap_unionall(ti)::DataType, unwrap_unionall(tj)::DataType)
392392
widen = rewrap_unionall(rewrap_unionall(widen, ti), tj)
393393
else
394-
widen = typenames[i].wrapper
394+
wr = typenames[i].wrapper
395+
uw = unwrap_unionall(wr)
396+
ui = unwrap_unionall(ti)
397+
uj = unwrap_unionall(tj)
398+
merged = wr
399+
for k = 1:length(uw.parameters)
400+
if ui.parameters[k] === uj.parameters[k]
401+
merged = merged{ui.parameters[k]}
402+
else
403+
merged = merged{uw.parameters[k]}
404+
end
405+
end
406+
widen = rewrap_unionall(merged, wr)
395407
end
396408
types[i] = Union{}
397409
typenames[i] = Any.name

base/compiler/types.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct OptimizationParams
5858
inline_cost_threshold::Int = 100,
5959
inline_nonleaf_penalty::Int = 1000,
6060
inline_tupleret_bonus::Int = 400,
61-
max_methods::Int = 4,
61+
max_methods::Int = 3,
6262
tuple_splat::Int = 32,
6363
union_splitting::Int = 4,
6464
)
@@ -107,7 +107,7 @@ struct InferenceParams
107107
function InferenceParams(;
108108
ipo_constant_propagation::Bool = true,
109109
aggressive_constant_propagation::Bool = false,
110-
max_methods::Int = 4,
110+
max_methods::Int = 3,
111111
union_splitting::Int = 4,
112112
apply_union_enum::Int = 8,
113113
tupletype_depth::Int = 3,

stdlib/Random/src/Random.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ rand(rng::AbstractRNG, ::UniformT{T}) where {T} = rand(rng, T)
253253
rand(rng::AbstractRNG, X) = rand(rng, Sampler(rng, X, Val(1)))
254254
# this is needed to disambiguate
255255
rand(rng::AbstractRNG, X::Dims) = rand(rng, Sampler(rng, X, Val(1)))
256-
rand(rng::AbstractRNG=default_rng(), ::Type{X}=Float64) where {X} = rand(rng, Sampler(rng, X, Val(1)))
256+
rand(rng::AbstractRNG=default_rng(), ::Type{X}=Float64) where {X} = rand(rng, Sampler(rng, X, Val(1)))::X
257257

258258
rand(X) = rand(default_rng(), X)
259259
rand(::Type{X}) where {X} = rand(default_rng(), X)

test/compiler/inference.jl

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ tmerge_test(Tuple{}, Tuple{Complex, Vararg{Union{ComplexF32, ComplexF64}}},
9595
Union{Nothing, Tuple{Vararg{ComplexF32}}}
9696
@test Core.Compiler.tmerge(Union{Nothing, Tuple{ComplexF32}}, Union{Nothing, Tuple{ComplexF32, ComplexF32}}) ==
9797
Union{Nothing, Tuple{Vararg{ComplexF32}}}
98+
@test Core.Compiler.tmerge(Vector{Int}, Core.Compiler.tmerge(Vector{String}, Vector{Bool})) == Vector
9899

99100
# issue 9770
100101
@noinline x9770() = false

test/worlds.jl

+15-2
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,12 @@ applyf35855(Any[1])
275275
wany3 = worlds(instance(applyf35855, (Vector{Any},)))
276276
src3 = code_typed(applyf35855, (Vector{Any},))[1]
277277
@test (wany3 == wany2) == equal(src3, src2) # don't invalidate unless you also change the code
278-
f35855(::AbstractVector) = 4 # next test would pass if this were ::Vector{Int}
278+
f35855(::AbstractVector) = 4
279279
applyf35855(Any[1])
280280
wany4 = worlds(instance(applyf35855, (Vector{Any},)))
281281
src4 = code_typed(applyf35855, (Vector{Any},))[1]
282-
@test_broken (wany4 == wany3) == equal(src4, src3)
282+
# this passes when max_methods == 3, fails when set to 4
283+
@test (wany4 == wany3) == equal(src4, src3)
283284
f35855(::Dict) = 5
284285
applyf35855(Any[1])
285286
wany5 = worlds(instance(applyf35855, (Vector{Any},)))
@@ -291,6 +292,18 @@ wany6 = worlds(instance(applyf35855, (Vector{Any},)))
291292
src6 = code_typed(applyf35855, (Vector{Any},))[1]
292293
@test (wany6 == wany5) == equal(src6, src5)
293294

295+
applyf35855_2(c) = f35855_2(c[1])
296+
f35855_2(::Int) = 1
297+
f35855_2(::Float64) = 2
298+
applyf35855_2(Any[1])
299+
wany3 = worlds(instance(applyf35855_2, (Vector{Any},)))
300+
src3 = code_typed(applyf35855_2, (Vector{Any},))[1]
301+
f35855_2(::AbstractVector) = 4 # next test would pass if this were ::Vector{Int}
302+
applyf35855_2(Any[1])
303+
wany4 = worlds(instance(applyf35855_2, (Vector{Any},)))
304+
src4 = code_typed(applyf35855_2, (Vector{Any},))[1]
305+
@test_broken (wany4 == wany3) == equal(src4, src3)
306+
294307
## ambiguities do not trigger invalidation
295308
using Printf
296309
Printf.gen("%f")

0 commit comments

Comments
 (0)