Skip to content

Commit 0a8ad1f

Browse files
authored
Backports for 1.11.3 (#56741)
2 parents 5e9a32e + 343c6ee commit 0a8ad1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+468
-204
lines changed

base/abstractdict.jl

+8-4
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ Return an iterator over all keys in a dictionary.
8888
When the keys are stored internally in a hash table,
8989
as is the case for `Dict`,
9090
the order in which they are returned may vary.
91-
But `keys(a)` and `values(a)` both iterate `a` and
92-
return the elements in the same order.
91+
But `keys(a)`, `values(a)` and `pairs(a)` all iterate `a`
92+
and return the elements in the same order.
9393
9494
# Examples
9595
```jldoctest
@@ -114,8 +114,8 @@ Return an iterator over all values in a collection.
114114
When the values are stored internally in a hash table,
115115
as is the case for `Dict`,
116116
the order in which they are returned may vary.
117-
But `keys(a)` and `values(a)` both iterate `a` and
118-
return the elements in the same order.
117+
But `keys(a)`, `values(a)` and `pairs(a)` all iterate `a`
118+
and return the elements in the same order.
119119
120120
# Examples
121121
```jldoctest
@@ -138,6 +138,10 @@ values(a::AbstractDict) = ValueIterator(a)
138138
Return an iterator over `key => value` pairs for any
139139
collection that maps a set of keys to a set of values.
140140
This includes arrays, where the keys are the array indices.
141+
When the entries are stored internally in a hash table,
142+
as is the case for `Dict`, the order in which they are returned may vary.
143+
But `keys(a)`, `values(a)` and `pairs(a)` all iterate `a`
144+
and return the elements in the same order.
141145
142146
# Examples
143147
```jldoctest

base/binaryplatforms.jl

+1
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ const arch_mapping = Dict(
591591
"armv7l" => "arm(v7l)?", # if we just see `arm-linux-gnueabihf`, we assume it's `armv7l`
592592
"armv6l" => "armv6l",
593593
"powerpc64le" => "p(ower)?pc64le",
594+
"riscv64" => "(rv64|riscv64)",
594595
)
595596
# Keep this in sync with `CPUID.ISAs_by_family`
596597
# These are the CPUID side of the microarchitectures targeted by GCC flags in BinaryBuilder.jl

base/broadcast.jl

+7-2
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,14 @@ Base.@propagate_inbounds function Base.iterate(bc::Broadcasted, s)
274274
end
275275

276276
Base.IteratorSize(::Type{T}) where {T<:Broadcasted} = Base.HasShape{ndims(T)}()
277-
Base.ndims(BC::Type{<:Broadcasted{<:Any,Nothing}}) = _maxndims(fieldtype(BC, :args))
278-
Base.ndims(::Type{<:Broadcasted{<:AbstractArrayStyle{N},Nothing}}) where {N<:Integer} = N
277+
Base.ndims(BC::Type{<:Broadcasted{<:Any,Nothing}}) = _maxndims_broadcasted(BC)
278+
# the `AbstractArrayStyle` type parameter is required to be either equal to `Any` or be an `Int` value
279+
Base.ndims(BC::Type{<:Broadcasted{<:AbstractArrayStyle{Any},Nothing}}) = _maxndims_broadcasted(BC)
280+
Base.ndims(::Type{<:Broadcasted{<:AbstractArrayStyle{N},Nothing}}) where {N} = N::Int
279281

282+
function _maxndims_broadcasted(BC::Type{<:Broadcasted})
283+
_maxndims(fieldtype(BC, :args))
284+
end
280285
_maxndims(::Type{T}) where {T<:Tuple} = reduce(max, ntuple(n -> (F = fieldtype(T, n); F <: Tuple ? 1 : ndims(F)), Base._counttuple(T)))
281286
_maxndims(::Type{<:Tuple{T}}) where {T} = T <: Tuple ? 1 : ndims(T)
282287
function _maxndims(::Type{<:Tuple{T, S}}) where {T, S}

base/compiler/effects.jl

+1
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ is_inaccessiblemem_or_argmemonly(effects::Effects) = effects.inaccessiblememonly
329329

330330
is_consistent_overlay(effects::Effects) = effects.nonoverlayed === CONSISTENT_OVERLAY
331331

332+
# (sync this with codegen.cpp and staticdata.c effects_foldable functions)
332333
function encode_effects(e::Effects)
333334
return ((e.consistent % UInt32) << 0) |
334335
((e.effect_free % UInt32) << 3) |

base/compiler/ssair/passes.jl

+7-5
Original file line numberDiff line numberDiff line change
@@ -2075,18 +2075,19 @@ function adce_pass!(ir::IRCode, inlining::Union{Nothing,InliningState}=nothing)
20752075
unionphi = unionphis[i]
20762076
phi = unionphi[1]
20772077
t = unionphi[2]
2078+
inst = compact.result[phi]
20782079
if t === Union{}
2079-
stmt = compact[SSAValue(phi)][:stmt]::PhiNode
2080+
stmt = inst[:stmt]::PhiNode
20802081
kill_phi!(compact, phi_uses, 1:length(stmt.values), SSAValue(phi), stmt, true)
20812082
made_changes = true
20822083
continue
20832084
elseif t === Any
20842085
continue
2085-
elseif (𝕃ₒ, compact.result[phi][:type], t)
2086-
continue
20872086
end
2087+
= strictpartialorder(𝕃ₒ)
2088+
t inst[:type] || continue
20882089
to_drop = Int[]
2089-
stmt = compact[SSAValue(phi)][:stmt]
2090+
stmt = inst[:stmt]
20902091
stmt === nothing && continue
20912092
stmt = stmt::PhiNode
20922093
for i = 1:length(stmt.values)
@@ -2098,7 +2099,8 @@ function adce_pass!(ir::IRCode, inlining::Union{Nothing,InliningState}=nothing)
20982099
push!(to_drop, i)
20992100
end
21002101
end
2101-
compact.result[phi][:type] = t
2102+
inst[:type] = t
2103+
add_flag!(inst, IR_FLAG_REFINED) # t ⊏ inst[:type]
21022104
kill_phi!(compact, phi_uses, to_drop, SSAValue(phi), stmt, false)
21032105
made_changes = true
21042106
end

base/compiler/tfuncs.jl

+10-2
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,16 @@ add_tfunc(svec, 0, INT_INF, @nospecs((𝕃::AbstractLattice, args...)->SimpleVec
587587
return TypeVar
588588
end
589589
end
590-
tv = TypeVar(nval, lb, ub)
591-
return PartialTypeVar(tv, lb_certain, ub_certain)
590+
lb_valid = lb isa Type || lb isa TypeVar
591+
ub_valid = ub isa Type || ub isa TypeVar
592+
if lb_valid && ub_valid
593+
tv = TypeVar(nval, lb, ub)
594+
return PartialTypeVar(tv, lb_certain, ub_certain)
595+
elseif !lb_valid && lb_certain
596+
return Union{}
597+
elseif !ub_valid && ub_certain
598+
return Union{}
599+
end
592600
end
593601
return TypeVar
594602
end

base/deepcopy.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,14 @@ function _deepcopy_memory_t(@nospecialize(x::Memory), T, stackdict::IdDict)
120120
end
121121
return dest
122122
end
123-
@eval function deepcopy_internal(x::Array{T, N}, stackdict::IdDict) where {T, N}
123+
function deepcopy_internal(x::Array{T, N}, stackdict::IdDict) where {T, N}
124124
if haskey(stackdict, x)
125125
return stackdict[x]::typeof(x)
126126
end
127-
stackdict[x] = $(Expr(:new, :(Array{T, N}), :(deepcopy_internal(x.ref, stackdict)), :(x.size)))
127+
y = stackdict[x] = Array{T, N}(undef, ntuple(Returns(0), Val{N}()))
128+
setfield!(y, :ref, deepcopy_internal(x.ref, stackdict))
129+
setfield!(y, :size, x.size)
130+
y
128131
end
129132
function deepcopy_internal(x::GenericMemoryRef, stackdict::IdDict)
130133
if haskey(stackdict, x)

base/docs/basedocs.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@ kw"new"
14601460
"""
14611461
where
14621462
1463-
The `where` keyword creates a type that is an iterated union of other types, over all
1463+
The `where` keyword creates a [`UnionAll`](@ref) type, which may be thought of as an iterated union of other types, over all
14641464
values of some variable. For example `Vector{T} where T<:Real` includes all [`Vector`](@ref)s
14651465
where the element type is some kind of `Real` number.
14661466

base/loading.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1782,7 +1782,7 @@ function compilecache_path(pkg::PkgId;
17821782
path = nothing
17831783
isnothing(sourcepath) && error("Cannot locate source for $(repr("text/plain", pkg))")
17841784
for path_to_try in cachepaths
1785-
staledeps = stale_cachefile(sourcepath, path_to_try, ignore_loaded = true, requested_flags=flags)
1785+
staledeps = stale_cachefile(sourcepath, path_to_try; ignore_loaded, requested_flags=flags)
17861786
if staledeps === true
17871787
continue
17881788
end
@@ -2555,7 +2555,7 @@ function _require(pkg::PkgId, env=nothing)
25552555
parallel_precompile_attempted = true
25562556
unlock(require_lock)
25572557
try
2558-
Precompilation.precompilepkgs([pkg.name]; _from_loading=true)
2558+
Precompilation.precompilepkgs([pkg.name]; _from_loading=true, ignore_loaded=false)
25592559
finally
25602560
lock(require_lock)
25612561
end

base/mathconstants.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ end
2929
Base.@assume_effects :foldable function (::Type{T})(x::_KnownIrrational, r::RoundingMode) where {T<:Union{Float32,Float64}}
3030
Base._irrational_to_float(T, x, r)
3131
end
32-
Base.@assume_effects :foldable function rationalize(::Type{T}, x::_KnownIrrational; tol::Real=0) where {T<:Integer}
32+
Base.@assume_effects :foldable function Base.rationalize(::Type{T}, x::_KnownIrrational; tol::Real=0) where {T<:Integer}
3333
Base._rationalize_irrational(T, x, tol)
3434
end
3535
Base.@assume_effects :foldable function Base.lessrational(rx::Rational, x::_KnownIrrational)

base/meta.jl

+21
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,29 @@ function _partially_inline!(@nospecialize(x), slot_replacements::Vector{Any},
362362
x.edges .+= slot_offset
363363
return x
364364
end
365+
if isa(x, Core.UpsilonNode)
366+
if !isdefined(x, :val)
367+
return x
368+
end
369+
return Core.UpsilonNode(
370+
_partially_inline!(x.val, slot_replacements, type_signature, static_param_values,
371+
slot_offset, statement_offset, boundscheck),
372+
)
373+
end
374+
if isa(x, Core.PhiCNode)
375+
_partially_inline!(x.values, slot_replacements, type_signature, static_param_values,
376+
slot_offset, statement_offset, boundscheck)
377+
end
365378
if isa(x, Core.ReturnNode)
379+
# Unreachable doesn't have val defined
380+
if !isdefined(x, :val)
381+
return x
382+
else
366383
return Core.ReturnNode(
367384
_partially_inline!(x.val, slot_replacements, type_signature, static_param_values,
368385
slot_offset, statement_offset, boundscheck),
369386
)
387+
end
370388
end
371389
if isa(x, Core.GotoIfNot)
372390
return Core.GotoIfNot(
@@ -376,6 +394,9 @@ function _partially_inline!(@nospecialize(x), slot_replacements::Vector{Any},
376394
)
377395
end
378396
if isa(x, Core.EnterNode)
397+
if x.catch_dest == 0
398+
return x
399+
end
379400
return Core.EnterNode(x, x.catch_dest + statement_offset)
380401
end
381402
if isa(x, Expr)

base/precompilation.jl

+29-19
Original file line numberDiff line numberDiff line change
@@ -404,11 +404,12 @@ function precompilepkgs(pkgs::Vector{String}=String[];
404404
configs::Union{Config,Vector{Config}}=(``=>Base.CacheFlags()),
405405
io::IO=stderr,
406406
# asking for timing disables fancy mode, as timing is shown in non-fancy mode
407-
fancyprint::Bool = can_fancyprint(io) && !timing)
407+
fancyprint::Bool = can_fancyprint(io) && !timing,
408+
ignore_loaded::Bool=true)
408409
# monomorphize this to avoid latency problems
409410
_precompilepkgs(pkgs, internal_call, strict, warn_loaded, timing, _from_loading,
410411
configs isa Vector{Config} ? configs : [configs],
411-
IOContext{IO}(io), fancyprint)
412+
IOContext{IO}(io), fancyprint, ignore_loaded)
412413
end
413414

414415
function _precompilepkgs(pkgs::Vector{String},
@@ -419,7 +420,8 @@ function _precompilepkgs(pkgs::Vector{String},
419420
_from_loading::Bool,
420421
configs::Vector{Config},
421422
io::IOContext{IO},
422-
fancyprint::Bool)
423+
fancyprint::Bool,
424+
ignore_loaded::Bool)
423425
requested_pkgs = copy(pkgs) # for understanding user intent
424426

425427
time_start = time_ns()
@@ -894,7 +896,7 @@ function _precompilepkgs(pkgs::Vector{String},
894896
wait(was_processed[(dep,config)])
895897
end
896898
circular = pkg in circular_deps
897-
is_stale = !Base.isprecompiled(pkg; ignore_loaded=true, stale_cache, cachepath_cache, cachepaths, sourcepath, flags=cacheflags)
899+
is_stale = !Base.isprecompiled(pkg; ignore_loaded, stale_cache, cachepath_cache, cachepaths, sourcepath, flags=cacheflags)
898900
if !circular && is_stale
899901
Base.acquire(parallel_limiter)
900902
is_direct_dep = pkg in direct_deps
@@ -920,10 +922,10 @@ function _precompilepkgs(pkgs::Vector{String},
920922
try
921923
# allows processes to wait if another process is precompiling a given package to
922924
# a functionally identical package cache (except for preferences, which may differ)
923-
t = @elapsed ret = precompile_pkgs_maybe_cachefile_lock(io, print_lock, fancyprint, pkg_config, pkgspidlocked, hascolor) do
925+
t = @elapsed ret = precompile_pkgs_maybe_cachefile_lock(io, print_lock, fancyprint, pkg_config, pkgspidlocked, hascolor, parallel_limiter, ignore_loaded) do
924926
Base.with_logger(Base.NullLogger()) do
925-
# The false here means we ignore loaded modules, so precompile for a fresh session
926-
keep_loaded_modules = false
927+
# whether to respect already loaded dependency versions
928+
keep_loaded_modules = !ignore_loaded
927929
# for extensions, any extension in our direct dependencies is one we have a right to load
928930
# for packages, we may load any extension (all possible triggers are accounted for above)
929931
loadable_exts = haskey(exts, pkg) ? filter((dep)->haskey(exts, dep), depsmap[pkg]) : nothing
@@ -1008,9 +1010,11 @@ function _precompilepkgs(pkgs::Vector{String},
10081010
plural1 = length(configs) > 1 ? "dependency configurations" : n_loaded == 1 ? "dependency" : "dependencies"
10091011
plural2 = n_loaded == 1 ? "a different version is" : "different versions are"
10101012
plural3 = n_loaded == 1 ? "" : "s"
1013+
plural4 = n_loaded == 1 ? "this package" : "these packages"
10111014
print(iostr, "\n ",
10121015
color_string(string(n_loaded), Base.warn_color()),
1013-
" $(plural1) precompiled but $(plural2) currently loaded. Restart julia to access the new version$(plural3)"
1016+
" $(plural1) precompiled but $(plural2) currently loaded. Restart julia to access the new version$(plural3). \
1017+
Otherwise, loading dependents of $(plural4) may trigger further precompilation to work with the unexpected version$(plural3)."
10141018
)
10151019
end
10161020
if !isempty(precomperr_deps)
@@ -1069,7 +1073,7 @@ function _precompilepkgs(pkgs::Vector{String},
10691073
direct = strict ? "" : "direct "
10701074
err_msg = "The following $n_direct_errs $(direct)dependenc$(pluralde) failed to precompile:\n$(String(take!(err_str)))"
10711075
if internal_call # aka. auto-precompilation
1072-
if isinteractive() && !get(ENV, "CI", false)
1076+
if isinteractive()
10731077
plural1 = length(failed_deps) == 1 ? "y" : "ies"
10741078
println(io, " ", color_string("$(length(failed_deps))", Base.error_color()), " dependenc$(plural1) errored.")
10751079
println(io, " For a report of the errors see `julia> err`. To retry use `pkg> precompile`")
@@ -1101,7 +1105,7 @@ function _color_string(cstr::String, col::Union{Int64, Symbol}, hascolor)
11011105
end
11021106

11031107
# Can be merged with `maybe_cachefile_lock` in loading?
1104-
function precompile_pkgs_maybe_cachefile_lock(f, io::IO, print_lock::ReentrantLock, fancyprint::Bool, pkg_config, pkgspidlocked, hascolor)
1108+
function precompile_pkgs_maybe_cachefile_lock(f, io::IO, print_lock::ReentrantLock, fancyprint::Bool, pkg_config, pkgspidlocked, hascolor, parallel_limiter::Base.Semaphore, ignore_loaded::Bool)
11051109
pkg, config = pkg_config
11061110
flags, cacheflags = config
11071111
FileWatching = Base.loaded_modules[Base.PkgId(Base.UUID("7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"), "FileWatching")]
@@ -1122,15 +1126,21 @@ function precompile_pkgs_maybe_cachefile_lock(f, io::IO, print_lock::ReentrantLo
11221126
!fancyprint && lock(print_lock) do
11231127
println(io, " ", pkg.name, _color_string(" Being precompiled by $(pkgspidlocked[pkg_config])", Base.info_color(), hascolor))
11241128
end
1125-
# wait until the lock is available
1126-
FileWatching.mkpidlock(pidfile; stale_age) do
1127-
# double-check in case the other process crashed or the lock expired
1128-
if Base.isprecompiled(pkg; ignore_loaded=true, flags=cacheflags) # don't use caches for this as the env state will have changed
1129-
return nothing # returning nothing indicates a process waited for another
1130-
else
1131-
delete!(pkgspidlocked, pkg_config)
1132-
return f() # precompile
1133-
end
1129+
Base.release(parallel_limiter) # release so other work can be done while waiting
1130+
try
1131+
# wait until the lock is available
1132+
@invokelatest Base.mkpidlock_hook(() -> begin
1133+
# double-check in case the other process crashed or the lock expired
1134+
if Base.isprecompiled(pkg; ignore_loaded, flags=cacheflags) # don't use caches for this as the env state will have changed
1135+
return nothing # returning nothing indicates a process waited for another
1136+
else
1137+
delete!(pkgspidlocked, pkg_config)
1138+
Base.acquire(f, parallel_limiter) # precompile
1139+
end
1140+
end,
1141+
pidfile; stale_age)
1142+
finally
1143+
Base.acquire(parallel_limiter) # re-acquire so the outer release is balanced
11341144
end
11351145
end
11361146
return cachefile

base/special/exp.jl

+2
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ end
216216
small_part = muladd(jU, expm1b_kernel(base, r), jL) + jU
217217

218218
if !(abs(x) <= SUBNORM_EXP(base, T))
219+
isnan(x) && return x
219220
x >= MAX_EXP(base, T) && return Inf
220221
x <= MIN_EXP(base, T) && return 0.0
221222
if k <= -53
@@ -243,6 +244,7 @@ end
243244
hi, lo = Base.canonicalize2(1.0, kern)
244245
small_part = fma(jU, hi, muladd(jU, (lo+xlo), very_small))
245246
if !(abs(x) <= SUBNORM_EXP(base, T))
247+
isnan(x) && return x
246248
x >= MAX_EXP(base, T) && return Inf
247249
x <= MIN_EXP(base, T) && return 0.0
248250
if k <= -53

base/subarray.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -295,18 +295,18 @@ reindex(idxs::Tuple{Slice, Vararg{Any}}, subidxs::Tuple{Any, Vararg{Any}}) =
295295

296296
# Re-index into parent vectors with one subindex
297297
reindex(idxs::Tuple{AbstractVector, Vararg{Any}}, subidxs::Tuple{Any, Vararg{Any}}) =
298-
(@_propagate_inbounds_meta; (maybeview(idxs[1], subidxs[1]), reindex(tail(idxs), tail(subidxs))...))
298+
(@_propagate_inbounds_meta; (idxs[1][subidxs[1]], reindex(tail(idxs), tail(subidxs))...))
299299

300300
# Parent matrices are re-indexed with two sub-indices
301301
reindex(idxs::Tuple{AbstractMatrix, Vararg{Any}}, subidxs::Tuple{Any, Any, Vararg{Any}}) =
302-
(@_propagate_inbounds_meta; (maybeview(idxs[1], subidxs[1], subidxs[2]), reindex(tail(idxs), tail(tail(subidxs)))...))
302+
(@_propagate_inbounds_meta; (idxs[1][subidxs[1], subidxs[2]], reindex(tail(idxs), tail(tail(subidxs)))...))
303303

304304
# In general, we index N-dimensional parent arrays with N indices
305305
@generated function reindex(idxs::Tuple{AbstractArray{T,N}, Vararg{Any}}, subidxs::Tuple{Vararg{Any}}) where {T,N}
306306
if length(subidxs.parameters) >= N
307307
subs = [:(subidxs[$d]) for d in 1:N]
308308
tail = [:(subidxs[$d]) for d in N+1:length(subidxs.parameters)]
309-
:(@_propagate_inbounds_meta; (maybeview(idxs[1], $(subs...)), reindex(tail(idxs), ($(tail...),))...))
309+
:(@_propagate_inbounds_meta; (idxs[1][$(subs...)], reindex(tail(idxs), ($(tail...),))...))
310310
else
311311
:(throw(ArgumentError("cannot re-index SubArray with fewer indices than dimensions\nThis should not occur; please submit a bug report.")))
312312
end

0 commit comments

Comments
 (0)