Skip to content

Commit f3a0ebb

Browse files
committed
decrease max_methods world-splitting setting for some functions
A function which is meant to have methods added to it by users should have a small `max_methods` value, as world-splitting just leads to unnecessary invalidation in that case, in the context of the package ecosystem, where users are allowed to add arbitrarily many methods to such functions. xref PR JuliaLang#57884 xref PR JuliaLang#58788 xref PR JuliaLang#58829 xref PR JuliaLang#59091
1 parent d28a587 commit f3a0ebb

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

base/Base_compiler.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ include("anyall.jl")
346346
include("ordering.jl")
347347
using .Order
348348

349+
include("interface_callables_base.jl")
350+
349351
include("coreir.jl")
350352
include("module.jl")
351353

base/abstractarray.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -934,10 +934,6 @@ end
934934

935935
## from general iterable to any array
936936

937-
# This is `Experimental.@max_methods 1 function copyto! end`, which is not
938-
# defined at this point in bootstrap.
939-
typeof(function copyto! end).name.max_methods = UInt8(1)
940-
941937
function copyto!(dest::AbstractArray, src)
942938
destiter = eachindex(dest)
943939
y = iterate(destiter)

base/broadcast.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,4 +1396,9 @@ function Base.show(io::IO, op::BroadcastFunction)
13961396
end
13971397
Base.show(io::IO, ::MIME"text/plain", op::BroadcastFunction) = show(io, op)
13981398

1399+
# interface callables, like in interface_callables_base.jl, but for `Broadcast` instead of for `Base`.
1400+
for f Any[broadcastable, instantiate]
1401+
Base._stable_typeof(f).name.max_methods = 0x1
1402+
end
1403+
13991404
end # module

base/interface_callables_base.jl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
# Interface functions defined in `Base`: define any that are not defined yet.
4+
for c Symbol[
5+
:propertynames, :getproperty, :setproperty!,
6+
:show, :print,
7+
:nextind, :prevind, :thisind,
8+
:length, :iterate, :eltype, :size, :axes, :isdone, :isempty,
9+
:firstindex, :lastindex, :getindex, :setindex!,
10+
:copy, :copyto!,
11+
:isone, :iszero,
12+
:strides, :stride, :elsize,
13+
:ndims, :one, :zero, :oneunit, :widen,
14+
:promote_rule, :convert,
15+
:similar,
16+
]
17+
@eval function $c end
18+
end
19+
20+
# Disable world spliting for callables to which users should add new methods.
21+
for c Any[
22+
propertynames, getproperty, setproperty!,
23+
show, print,
24+
nextind, prevind, thisind,
25+
length, iterate, size, axes, isdone, isempty,
26+
firstindex, lastindex, getindex, setindex!,
27+
copy, :copyto!,
28+
isone, iszero,
29+
strides, stride,
30+
+, -, *, /, //, <<, >>, >>>, div, fld, cld,
31+
]
32+
Base._stable_typeof(f).name.max_methods = 0x1
33+
end
34+
35+
# Callables which take type arguments and need a method for the bottom type need a
36+
# `max_methods` value of two for good inference, because the bottom type subtypes
37+
# each type.
38+
#
39+
# TODO: add `eltype`
40+
for c Any[
41+
elsize,
42+
ndims, one, zero, oneunit, widen,
43+
promote_rule, convert,
44+
similar,
45+
]
46+
Base._stable_typeof(f).name.max_methods = 0x2
47+
end

0 commit comments

Comments
 (0)