Skip to content

Commit a47559f

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 #57884 xref PR #58788 xref PR #58829 xref PR #59091
1 parent cbea8cf commit a47559f

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-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: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
:+, :-, :*, :/, ://, :<<, :>>, :>>>, :div, :fld, :cld,
17+
]
18+
@eval function $c end
19+
end
20+
21+
# Disable world splitting for callables to which users should add new methods.
22+
for c Any[
23+
propertynames, getproperty, setproperty!,
24+
show, print,
25+
nextind, prevind, thisind,
26+
length, iterate, size, axes, isdone, isempty,
27+
firstindex, lastindex, getindex, setindex!,
28+
copy, :copyto!,
29+
isone, iszero,
30+
strides, stride,
31+
+, -, *, /, //, <<, >>, >>>, div, fld, cld,
32+
]
33+
Base._stable_typeof(c).name.max_methods = 0x1
34+
end
35+
36+
# Callables which take type arguments and need a method for the bottom type need a
37+
# `max_methods` value of two for good inference, because the bottom type subtypes
38+
# each type.
39+
#
40+
# TODO: add `eltype`
41+
for c Any[
42+
elsize,
43+
ndims, one, zero, oneunit, widen,
44+
promote_rule, convert,
45+
similar,
46+
]
47+
Base._stable_typeof(c).name.max_methods = 0x2
48+
end

0 commit comments

Comments
 (0)