Skip to content

Commit 261dc4a

Browse files
authored
Backports for 1.12-rc2 (#59337)
2 parents 18f42dc + 50e72b3 commit 261dc4a

File tree

42 files changed

+432
-197
lines changed

Some content is hidden

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

42 files changed

+432
-197
lines changed

Compiler/test/inference.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6291,3 +6291,10 @@ end <: Bool
62916291
@test Base.infer_return_type((Module,Symbol,Vector{Any})) do m, n, xs
62926292
Core.get_binding_type(m, n, xs...)
62936293
end <: Type
6294+
6295+
# issue #59269
6296+
function haskey_inference_test()
6297+
kwargs = Core.compilerbarrier(:const, Base.pairs((; item = false)))
6298+
return haskey(kwargs, :item) ? nothing : Any[]
6299+
end
6300+
@inferred haskey_inference_test()

base/binaryplatforms.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,14 +520,17 @@ function triplet(p::AbstractPlatform)
520520
)
521521

522522
# Tack on optional compiler ABI flags
523-
if libgfortran_version(p) !== nothing
524-
str = string(str, "-libgfortran", libgfortran_version(p).major)
523+
libgfortran_version_ = libgfortran_version(p)
524+
if libgfortran_version_ !== nothing
525+
str = string(str, "-libgfortran", libgfortran_version_.major)
525526
end
526-
if cxxstring_abi(p) !== nothing
527-
str = string(str, "-", cxxstring_abi(p))
527+
cxxstring_abi_ = cxxstring_abi(p)
528+
if cxxstring_abi_ !== nothing
529+
str = string(str, "-", cxxstring_abi_)
528530
end
529-
if libstdcxx_version(p) !== nothing
530-
str = string(str, "-libstdcxx", libstdcxx_version(p).patch)
531+
libstdcxx_version_ = libstdcxx_version(p)
532+
if libstdcxx_version_ !== nothing
533+
str = string(str, "-libstdcxx", libstdcxx_version_.patch)
531534
end
532535

533536
# Tack on all extra tags

base/essentials.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,9 @@ end
489489
Pairs{K, V, I, A}(data, itr) where {K, V, I, A} = $(Expr(:new, :(Pairs{K, V, I, A}), :(data isa A ? data : convert(A, data)), :(itr isa I ? itr : convert(I, itr))))
490490
Pairs{K, V}(data::A, itr::I) where {K, V, I, A} = $(Expr(:new, :(Pairs{K, V, I, A}), :data, :itr))
491491
Pairs{K}(data::A, itr::I) where {K, I, A} = $(Expr(:new, :(Pairs{K, eltype(A), I, A}), :data, :itr))
492-
Pairs(data::A, itr::I) where {I, A} = $(Expr(:new, :(Pairs{eltype(I), eltype(A), I, A}), :data, :itr))
492+
Pairs(data::A, itr::I) where {I, A} = $(Expr(:new, :(Pairs{I !== Nothing ? eltype(I) : keytype(A), eltype(A), I, A}), :data, :itr))
493493
end
494-
pairs(::Type{NamedTuple}) = Pairs{Symbol, V, NTuple{N, Symbol}, NamedTuple{names, T}} where {V, N, names, T<:NTuple{N, Any}}
494+
pairs(::Type{NamedTuple}) = Pairs{Symbol, V, Nothing, NT} where {V, NT <: NamedTuple}
495495

496496
"""
497497
Base.Pairs(values, keys) <: AbstractDict{eltype(keys), eltype(values)}

base/idset.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ IdSet{T}() constructs a set (see [`Set`](@ref)) using
1010
In the example below, the values are all `isequal` so they get overwritten in the ordinary `Set`.
1111
The `IdSet` compares by `===` and so preserves the 3 different values.
1212
13+
!!! compat "Julia 1.11"
14+
Exported in Julia 1.11 and later.
15+
1316
# Examples
1417
```jldoctest; filter = r"\\n\\s*(1|1\\.0|true)"
1518
julia> Set(Any[true, 1, 1.0])

base/invalidation.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ function invalidate_code_for_globalref!(b::Core.Binding, invalidated_bpart::Core
155155
latest_bpart = user_binding.partitions
156156
latest_bpart.max_world == typemax(UInt) || continue
157157
is_some_implicit(binding_kind(latest_bpart)) || continue
158-
new_bpart = need_to_invalidate_export ?
159-
ccall(:jl_maybe_reresolve_implicit, Any, (Any, Csize_t), user_binding, new_max_world) :
160-
latest_bpart
158+
new_bpart = ccall(:jl_maybe_reresolve_implicit, Any, (Any, Csize_t), user_binding, new_max_world)
161159
if need_to_invalidate_code || new_bpart !== latest_bpart
162160
push!(queued_bindings, (convert(Core.Binding, user_binding), latest_bpart, new_bpart))
163161
end

base/iterators.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,48 +267,48 @@ pairs(::IndexLinear, A::AbstractArray) = Pairs(A, LinearIndices(A))
267267
# preserve indexing capabilities for known indexable types
268268
# faster than zip(keys(a), values(a)) for arrays
269269
pairs(tuple::Tuple) = Pairs{Int}(tuple, keys(tuple))
270-
pairs(nt::NamedTuple) = Pairs{Symbol}(nt, keys(nt))
270+
pairs(nt::NamedTuple) = Pairs{Symbol}(nt, nothing)
271271
pairs(v::Core.SimpleVector) = Pairs(v, LinearIndices(v))
272272
pairs(A::AbstractVector) = pairs(IndexLinear(), A)
273273
# pairs(v::Pairs) = v # listed for reference, but already defined from being an AbstractDict
274274

275275
pairs(::IndexCartesian, A::AbstractArray) = Pairs(A, Base.CartesianIndices(axes(A)))
276276
pairs(A::AbstractArray) = pairs(IndexCartesian(), A)
277277

278-
length(v::Pairs) = length(getfield(v, :itr))
279-
axes(v::Pairs) = axes(getfield(v, :itr))
280-
size(v::Pairs) = size(getfield(v, :itr))
278+
length(v::Pairs) = length(keys(v))
279+
axes(v::Pairs) = axes(keys(v))
280+
size(v::Pairs) = size(keys(v))
281281

282282
Base.@eval @propagate_inbounds function _pairs_elt(p::Pairs{K, V}, idx) where {K, V}
283283
return $(Expr(:new, :(Pair{K, V}), :idx, :(getfield(p, :data)[idx])))
284284
end
285285

286286
@propagate_inbounds function iterate(p::Pairs{K, V}, state...) where {K, V}
287-
x = iterate(getfield(p, :itr), state...)
287+
x = iterate(keys(p), state...)
288288
x === nothing && return x
289289
idx, next = x
290290
return (_pairs_elt(p, idx), next)
291291
end
292292

293-
@propagate_inbounds function iterate(r::Reverse{<:Pairs}, state=(reverse(getfield(r.itr, :itr)),))
293+
@propagate_inbounds function iterate(r::Reverse{<:Pairs}, state=(reverse(keys(r.itr)),))
294294
x = iterate(state...)
295295
x === nothing && return x
296296
idx, next = x
297297
return (_pairs_elt(r.itr, idx), (state[1], next))
298298
end
299299

300-
@inline isdone(v::Pairs, state...) = isdone(getfield(v, :itr), state...)
300+
@inline isdone(v::Pairs, state...) = isdone(keys(v), state...)
301301

302302
IteratorSize(::Type{<:Pairs{<:Any, <:Any, I}}) where {I} = IteratorSize(I)
303303
IteratorSize(::Type{<:Pairs{<:Any, <:Any, <:AbstractUnitRange, <:Tuple}}) = HasLength()
304304

305305
function last(v::Pairs{K, V}) where {K, V}
306-
idx = last(getfield(v, :itr))
306+
idx = last(keys(v))
307307
return Pair{K, V}(idx, v[idx])
308308
end
309309

310-
haskey(v::Pairs, key) = (key in getfield(v, :itr))
311-
keys(v::Pairs) = getfield(v, :itr)
310+
haskey(v::Pairs, key) = key in keys(v)
311+
keys(v::Pairs) = getfield(v, :itr) === nothing ? keys(getfield(v, :data)) : getfield(v, :itr)
312312
values(v::Pairs) = getfield(v, :data) # TODO: this should be a view of data subset by itr
313313
getindex(v::Pairs, key) = getfield(v, :data)[key]
314314
setindex!(v::Pairs, value, key) = (getfield(v, :data)[key] = value; v)

base/loading.jl

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,17 +1267,21 @@ function _include_from_serialized(pkg::PkgId, path::String, ocachepath::Union{No
12671267
sv = try
12681268
if ocachepath !== nothing
12691269
@debug "Loading object cache file $ocachepath for $(repr("text/plain", pkg))"
1270-
ccall(:jl_restore_package_image_from_file, Ref{SimpleVector}, (Cstring, Any, Cint, Cstring, Cint),
1270+
ccall(:jl_restore_package_image_from_file, Any, (Cstring, Any, Cint, Cstring, Cint),
12711271
ocachepath, depmods, #=completeinfo=#false, pkg.name, ignore_native)
12721272
else
12731273
@debug "Loading cache file $path for $(repr("text/plain", pkg))"
1274-
ccall(:jl_restore_incremental, Ref{SimpleVector}, (Cstring, Any, Cint, Cstring),
1274+
ccall(:jl_restore_incremental, Any, (Cstring, Any, Cint, Cstring),
12751275
path, depmods, #=completeinfo=#false, pkg.name)
12761276
end
12771277
finally
12781278
lock(require_lock)
12791279
end
1280+
if isa(sv, Exception)
1281+
return sv
1282+
end
12801283

1284+
sv = sv::SimpleVector
12811285
edges = sv[3]::Vector{Any}
12821286
ext_edges = sv[4]::Union{Nothing,Vector{Any}}
12831287
extext_methods = sv[5]::Vector{Any}
@@ -2630,21 +2634,23 @@ function __require_prelocked(pkg::PkgId, env)
26302634
@goto load_from_cache
26312635
end
26322636
# spawn off a new incremental pre-compile task for recursive `require` calls
2633-
loaded = maybe_cachefile_lock(pkg, path) do
2634-
# double-check the search now that we have lock
2635-
m = _require_search_from_serialized(pkg, path, UInt128(0), true)
2636-
m isa Module && return m
2637-
triggers = get(EXT_PRIMED, pkg, nothing)
2638-
loadable_exts = nothing
2639-
if triggers !== nothing # extension
2640-
loadable_exts = PkgId[]
2641-
for (ext′, triggers′) in EXT_PRIMED
2642-
if triggers′ triggers
2643-
push!(loadable_exts, ext′)
2637+
loaded = let path = path, reasons = reasons
2638+
maybe_cachefile_lock(pkg, path) do
2639+
# double-check the search now that we have lock
2640+
m = _require_search_from_serialized(pkg, path, UInt128(0), true)
2641+
m isa Module && return m
2642+
triggers = get(EXT_PRIMED, pkg, nothing)
2643+
loadable_exts = nothing
2644+
if triggers !== nothing # extension
2645+
loadable_exts = PkgId[]
2646+
for (ext′, triggers′) in EXT_PRIMED
2647+
if triggers′ triggers
2648+
push!(loadable_exts, ext′)
2649+
end
26442650
end
26452651
end
2652+
return compilecache(pkg, path; reasons, loadable_exts)
26462653
end
2647-
return compilecache(pkg, path; reasons, loadable_exts)
26482654
end
26492655
loaded isa Module && return loaded
26502656
if isnothing(loaded) # maybe_cachefile_lock returns nothing if it had to wait for another process

base/namedtuple.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ merge(a::NamedTuple, b::NamedTuple{()}) = a
343343
merge(a::NamedTuple{()}, b::NamedTuple{()}) = a
344344
merge(a::NamedTuple{()}, b::NamedTuple) = b
345345

346-
merge(a::NamedTuple, b::Iterators.Pairs{<:Any,<:Any,<:Any,<:NamedTuple}) = merge(a, getfield(b, :data))
346+
merge(a::NamedTuple, b::Iterators.Pairs{<:Any,<:Any,Nothing,<:NamedTuple}) = merge(a, getfield(b, :data))
347347

348348
merge(a::NamedTuple, b::Iterators.Zip{<:Tuple{Any,Any}}) = merge(a, NamedTuple{Tuple(b.is[1])}(b.is[2]))
349349

@@ -535,7 +535,7 @@ when it is printed in the stack trace view.
535535
536536
```julia
537537
julia> @Kwargs{init::Int} # the internal representation of keyword arguments
538-
Base.Pairs{Symbol, Int64, Tuple{Symbol}, @NamedTuple{init::Int64}}
538+
Base.Pairs{Symbol, Int64, Nothing, @NamedTuple{init::Int64}}
539539
540540
julia> sum("julia"; init=1)
541541
ERROR: MethodError: no method matching +(::Char, ::Char)
@@ -578,7 +578,7 @@ Stacktrace:
578578
macro Kwargs(ex)
579579
return :(let
580580
NT = @NamedTuple $ex
581-
Base.Pairs{keytype(NT),eltype(NT),typeof(NT.parameters[1]),NT}
581+
Base.Pairs{keytype(NT),eltype(NT),Nothing,NT}
582582
end)
583583
end
584584

base/show.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,8 @@ function show_type_name(io::IO, tn::Core.TypeName)
11061106
end
11071107

11081108
function maybe_kws_nt(x::DataType)
1109+
# manually-written version of
1110+
# x <: (Pairs{Symbol, eltype(NT), Nothing, NT} where NT <: NamedTuple)
11091111
x.name === typename(Pairs) || return nothing
11101112
length(x.parameters) == 4 || return nothing
11111113
x.parameters[1] === Symbol || return nothing
@@ -1115,7 +1117,7 @@ function maybe_kws_nt(x::DataType)
11151117
types isa DataType || return nothing
11161118
x.parameters[2] === eltype(p4) || return nothing
11171119
isa(syms, Tuple) || return nothing
1118-
x.parameters[3] === typeof(syms) || return nothing
1120+
x.parameters[3] === Nothing || return nothing
11191121
return p4
11201122
end
11211123
return nothing
@@ -3313,7 +3315,7 @@ function Base.showarg(io::IO, r::Iterators.Pairs{<:Integer, <:Any, <:Any, T}, to
33133315
print(io, "pairs(IndexLinear(), ::", T, ")")
33143316
end
33153317

3316-
function Base.showarg(io::IO, r::Iterators.Pairs{Symbol, <:Any, <:Any, T}, toplevel) where {T <: NamedTuple}
3318+
function Base.showarg(io::IO, r::Iterators.Pairs{Symbol, <:Any, Nothing, T}, toplevel) where {T <: NamedTuple}
33173319
print(io, "pairs(::NamedTuple)")
33183320
end
33193321

base/stacktraces.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,4 @@ function from(frame::StackFrame, m::Module)
365365
return parentmodule(frame) === m
366366
end
367367

368-
end
368+
end # module StackTraces

0 commit comments

Comments
 (0)