Skip to content

Commit 229f027

Browse files
authored
Backports for 1.11.2 (#56228)
Backported PRs: - [x] #55886 <!-- irrationals: restrict assume effects annotations to known types --> - [x] #55867 <!-- update `hash` doc string: `widen` not required any more --> - [x] #56084 <!-- slightly improve inference in precompilation code --> - [x] #56088 <!-- make `Base.ANSIIterator` have a concrete field --> - [x] #54093 <!-- Fix `JULIA_CPU_TARGET` being propagated to workers precompiling stdlib pkgimages --> - [x] #56165 <!-- Fix markdown list in installation.md --> - [x] #56148 <!-- Make loading work when stdlib deps are missing in the manifest --> - [x] #56174 <!-- Fix implicit `convert(String, ...)` in several places --> - [x] #56159 <!-- Add invalidation barriers for `displaysize` and `implicit_typeinfo` --> - [x] #56089 <!-- Call `MulAddMul` instead of multiplication in _generic_matmatmul! --> - [x] #56195 <!-- Include default user depot when JULIA_DEPOT_PATH has leading empty entry --> - [x] #56215 <!-- [REPL] fix lock ordering mistake in load_pkg --> - [x] #56251 <!-- REPL: run repl hint generation for modeswitch chars when not switching --> - [x] #56092 <!-- stream: fix reading LibuvStream into array --> - [x] #55870 <!-- fix infinite recursion in `promote_type` for `Irrational` --> - [x] #56227 <!-- Do not call `rand` during sysimage precompilation --> - [x] #55741 <!-- Change annotations to use a NamedTuple --> - [x] #56149 <!-- Specialize adding/subtracting mixed Upper/LowerTriangular --> - [x] #56214 <!-- fix precompile process flags --> - [x] #54471 - [x] #55622 - [x] #55704 - [x] #55764
2 parents 8f5b7ca + f55307c commit 229f027

File tree

115 files changed

+1978
-865
lines changed

Some content is hidden

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

115 files changed

+1978
-865
lines changed

NEWS.md

+15
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ Language changes
3737
omit the default user depot ([#51448]).
3838
* Precompilation cache files are now relocatable and their validity is now verified through
3939
a content hash of their source files instead of their `mtime` ([#49866]).
40+
* Extensions may now depend on other extensions, if their triggers include all triggers of any
41+
extension they wish to depend upon (+ at least one other trigger). Ext-to-ext dependencies
42+
that don't meet this requirement are now blocked from using `Base.get_extension` during pre-
43+
compilation, to prevent extension cycles [#55557].
4044

4145
Compiler/Runtime improvements
4246
-----------------------------
@@ -139,6 +143,17 @@ Standard library changes
139143
`length(::Stateful)` method. The last type parameter of `Stateful` is gone, too. Issue: ([#47790]),
140144
PR: ([#51747]).
141145

146+
#### Package Manager
147+
148+
* It is now possible to specify "sources" for packages in a `[sources]` section in Project.toml.
149+
This can be used to add non-registered normal or test dependencies.
150+
* Pkg now obeys `[compat]` bounds for `julia` and raises an error if the version of the running Julia binary is incompatible with the bounds in `Project.toml`.
151+
Pkg has always obeyed this compat when working with Registry packages. This change affects mostly local packages
152+
* `pkg> add` and `Pkg.add` will now add compat entries for new direct dependencies if the active environment is a
153+
package (has a `name` and `uuid` entry).
154+
* Dependencies can now be directly added as weak deps or extras via the `pkg> add --weak/extra Foo` or
155+
`Pkg.add("Foo", target=:weakdeps/:extras)` forms.
156+
142157
#### StyledStrings
143158

144159
* A new standard library for handling styling in a more comprehensive and structured way ([#49586]).

base/Base.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ include("deepcopy.jl")
508508
include("download.jl")
509509
include("summarysize.jl")
510510
include("errorshow.jl")
511+
include("util.jl")
511512

512513
include("initdefs.jl")
513514
Filesystem.__postinit__()
@@ -524,7 +525,6 @@ include("loading.jl")
524525

525526
# misc useful functions & macros
526527
include("timing.jl")
527-
include("util.jl")
528528
include("client.jl")
529529
include("asyncmap.jl")
530530

@@ -605,7 +605,7 @@ function __init__()
605605
empty!(explicit_loaded_modules)
606606
empty!(loaded_precompiles) # If we load a packageimage when building the image this might not be empty
607607
for (mod, key) in module_keys
608-
loaded_precompiles[key => module_build_id(mod)] = mod
608+
push!(get!(Vector{Module}, loaded_precompiles, key), mod)
609609
end
610610
if haskey(ENV, "JULIA_MAX_NUM_PRECOMPILE_FILES")
611611
MAX_NUM_PRECOMPILE_FILES[] = parse(Int, ENV["JULIA_MAX_NUM_PRECOMPILE_FILES"])

base/abstractarray.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -1634,10 +1634,10 @@ typed_vcat(::Type{T}) where {T} = Vector{T}()
16341634
typed_hcat(::Type{T}) where {T} = Vector{T}()
16351635

16361636
## cat: special cases
1637-
vcat(X::T...) where {T} = T[ X[i] for i=1:length(X) ]
1638-
vcat(X::T...) where {T<:Number} = T[ X[i] for i=1:length(X) ]
1639-
hcat(X::T...) where {T} = T[ X[j] for i=1:1, j=1:length(X) ]
1640-
hcat(X::T...) where {T<:Number} = T[ X[j] for i=1:1, j=1:length(X) ]
1637+
vcat(X::T...) where {T} = T[ X[i] for i=eachindex(X) ]
1638+
vcat(X::T...) where {T<:Number} = T[ X[i] for i=eachindex(X) ]
1639+
hcat(X::T...) where {T} = T[ X[j] for i=1:1, j=eachindex(X) ]
1640+
hcat(X::T...) where {T<:Number} = T[ X[j] for i=1:1, j=eachindex(X) ]
16411641

16421642
vcat(X::Number...) = hvcat_fill!(Vector{promote_typeof(X...)}(undef, length(X)), X)
16431643
hcat(X::Number...) = hvcat_fill!(Matrix{promote_typeof(X...)}(undef, 1,length(X)), X)

base/array.jl

+11
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,17 @@ copy
351351
return $(Expr(:new, :(typeof(a)), :(memoryref(newmem)), :(a.size)))
352352
end
353353

354+
# a mutating version of copyto! that results in dst aliasing src afterwards
355+
function _take!(dst::Array{T,N}, src::Array{T,N}) where {T,N}
356+
if getfield(dst, :ref) !== getfield(src, :ref)
357+
setfield!(dst, :ref, getfield(src, :ref))
358+
end
359+
if getfield(dst, :size) !== getfield(src, :size)
360+
setfield!(dst, :size, getfield(src, :size))
361+
end
362+
return dst
363+
end
364+
354365
## Constructors ##
355366

356367
similar(a::Array{T,1}) where {T} = Vector{T}(undef, size(a,1))

base/arrayshow.jl

+11-5
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,12 @@ typeinfo_eltype(typeinfo::Type{<:AbstractArray{T}}) where {T} = eltype(typeinfo)
545545
typeinfo_eltype(typeinfo::Type{<:AbstractDict{K,V}}) where {K,V} = eltype(typeinfo)
546546
typeinfo_eltype(typeinfo::Type{<:AbstractSet{T}}) where {T} = eltype(typeinfo)
547547

548+
# This is a fancy way to make de-specialize a call to `typeinfo_implicit(T)`
549+
# which is unfortunately invalidated by Dates
550+
# (https://github.com/JuliaLang/julia/issues/56080)
551+
#
552+
# This makes the call less efficient, but avoids being invalidated by Dates.
553+
_typeinfo_implicit(@nospecialize(T)) = Base.invoke_in_world(Base.tls_world_age(), typeinfo_implicit, T)::Bool
548554

549555
# types that can be parsed back accurately from their un-decorated representations
550556
function typeinfo_implicit(@nospecialize(T))
@@ -553,9 +559,9 @@ function typeinfo_implicit(@nospecialize(T))
553559
return true
554560
end
555561
return isconcretetype(T) &&
556-
((T <: Array && typeinfo_implicit(eltype(T))) ||
557-
((T <: Tuple || T <: Pair) && all(typeinfo_implicit, fieldtypes(T))) ||
558-
(T <: AbstractDict && typeinfo_implicit(keytype(T)) && typeinfo_implicit(valtype(T))))
562+
((T <: Array && _typeinfo_implicit(eltype(T))) ||
563+
((T <: Tuple || T <: Pair) && all(_typeinfo_implicit, fieldtypes(T))) ||
564+
(T <: AbstractDict && _typeinfo_implicit(keytype(T)) && _typeinfo_implicit(valtype(T))))
559565
end
560566

561567
# X not constrained, can be any iterable (cf. show_vector)
@@ -573,7 +579,7 @@ function typeinfo_prefix(io::IO, X)
573579
if X isa AbstractDict
574580
if eltype_X == eltype_ctx
575581
sprint(show_type_name, typeof(X).name; context=io), false
576-
elseif !isempty(X) && typeinfo_implicit(keytype(X)) && typeinfo_implicit(valtype(X))
582+
elseif !isempty(X) && _typeinfo_implicit(keytype(X)) && _typeinfo_implicit(valtype(X))
577583
sprint(show_type_name, typeof(X).name; context=io), true
578584
else
579585
sprint(print, typeof(X); context=io), false
@@ -582,7 +588,7 @@ function typeinfo_prefix(io::IO, X)
582588
# Types hard-coded here are those which are created by default for a given syntax
583589
if eltype_X == eltype_ctx
584590
"", false
585-
elseif !isempty(X) && typeinfo_implicit(eltype_X)
591+
elseif !isempty(X) && _typeinfo_implicit(eltype_X)
586592
"", true
587593
elseif print_without_params(eltype_X)
588594
sprint(show_type_name, unwrap_unionall(eltype_X).name; context=io), false # Print "Array" rather than "Array{T,N}"

base/docs/basedocs.jl

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ kw"help", kw"Julia", kw"julia", kw""
3737
available for direct use. Names can also be used via dot syntax (e.g. `Foo.foo` to access
3838
the name `foo`), whether they are `export`ed or not.
3939
See the [manual section about modules](@ref modules) for details.
40+
41+
!!! note
42+
When two or more packages/modules export a name and that name does not refer to the
43+
same thing in each of the packages, and the packages are loaded via `using` without
44+
an explicit list of names, it is an error to reference that name without qualification.
45+
It is thus recommended that code intended to be forward-compatible with future versions
46+
of its dependencies and of Julia, e.g., code in released packages, list the names it
47+
uses from each loaded package, e.g., `using Foo: Foo, f` rather than `using Foo`.
4048
"""
4149
kw"using"
4250

base/errorshow.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ function showerror(io::IO, ex::CanonicalIndexError)
196196
print(io, "CanonicalIndexError: ", ex.func, " not defined for ", ex.type)
197197
end
198198

199-
typesof(@nospecialize args...) = Tuple{Any[ Core.Typeof(args[i]) for i in 1:length(args) ]...}
199+
typesof(@nospecialize args...) = Tuple{Any[Core.Typeof(arg) for arg in args]...}
200200

201201
function print_with_compare(io::IO, @nospecialize(a::DataType), @nospecialize(b::DataType), color::Symbol)
202202
if a.name === b.name
@@ -273,7 +273,7 @@ function showerror(io::IO, ex::MethodError)
273273
arg_types_param = arg_types_param[3:end]
274274
san_arg_types_param = san_arg_types_param[3:end]
275275
keys = kwt.parameters[1]::Tuple
276-
kwargs = Any[(keys[i], fieldtype(kwt, i)) for i in 1:length(keys)]
276+
kwargs = Any[(keys[i], fieldtype(kwt, i)) for i in eachindex(keys)]
277277
arg_types = rewrap_unionall(Tuple{arg_types_param...}, arg_types)
278278
end
279279
if f === Base.convert && length(arg_types_param) == 2 && !is_arg_types
@@ -687,7 +687,7 @@ function show_reduced_backtrace(io::IO, t::Vector)
687687

688688
push!(repeated_cycle, (0,0,0)) # repeated_cycle is never empty
689689
frame_counter = 1
690-
for i in 1:length(displayed_stackframes)
690+
for i in eachindex(displayed_stackframes)
691691
(frame, n) = displayed_stackframes[i]
692692

693693
print_stackframe(io, frame_counter, frame, n, ndigits_max, STACKTRACE_FIXEDCOLORS, STACKTRACE_MODULECOLORS)
@@ -864,7 +864,7 @@ end
864864
function _collapse_repeated_frames(trace)
865865
kept_frames = trues(length(trace))
866866
last_frame = nothing
867-
for i in 1:length(trace)
867+
for i in eachindex(trace)
868868
frame::StackFrame, _ = trace[i]
869869
if last_frame !== nothing && frame.file == last_frame.file && frame.line == last_frame.line
870870
#=
@@ -909,7 +909,7 @@ function _collapse_repeated_frames(trace)
909909
end
910910
if length(last_params) > length(params)
911911
issame = true
912-
for i = 1:length(params)
912+
for i = eachindex(params)
913913
issame &= params[i] == last_params[i]
914914
end
915915
if issame

base/expr.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function copy_exprs(@nospecialize(x))
6868
end
6969
return x
7070
end
71-
copy_exprargs(x::Array{Any,1}) = Any[copy_exprs(@inbounds x[i]) for i in 1:length(x)]
71+
copy_exprargs(x::Array{Any,1}) = Any[copy_exprs(@inbounds x[i]) for i in eachindex(x)]
7272

7373
@eval exprarray(head::Symbol, arg::Array{Any,1}) = $(Expr(:new, :Expr, :head, :arg))
7474

base/genericmemory.jl

+16-7
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,16 @@ function _unsetindex!(A::MemoryRef{T}) where T
8080
MemT = typeof(mem)
8181
arrayelem = datatype_arrayelem(MemT)
8282
elsz = datatype_layoutsize(MemT)
83-
isboxed = 1; isunion = 2
83+
isbits = 0; isboxed = 1; isunion = 2
84+
arrayelem == isbits && datatype_pointerfree(T::DataType) && return A
8485
t = @_gc_preserve_begin mem
8586
p = Ptr{Ptr{Cvoid}}(@inbounds pointer(A))
8687
if arrayelem == isboxed
8788
Intrinsics.atomic_pointerset(p, C_NULL, :monotonic)
8889
elseif arrayelem != isunion
89-
if !datatype_pointerfree(T::DataType)
90-
for j = 1:Core.sizeof(Ptr{Cvoid}):elsz
91-
# XXX: this violates memory ordering, since it writes more than one C_NULL to each
92-
Intrinsics.atomic_pointerset(p + j - 1, C_NULL, :monotonic)
93-
end
90+
for j = 1:Core.sizeof(Ptr{Cvoid}):elsz
91+
# XXX: this violates memory ordering, since it writes more than one C_NULL to each
92+
Intrinsics.atomic_pointerset(p + j - 1, C_NULL, :monotonic)
9493
end
9594
end
9695
@_gc_preserve_end t
@@ -114,7 +113,17 @@ function unsafe_copyto!(dest::MemoryRef{T}, src::MemoryRef{T}, n) where {T}
114113
@_terminates_globally_notaskstate_meta
115114
n == 0 && return dest
116115
@boundscheck memoryref(dest, n), memoryref(src, n)
117-
ccall(:jl_genericmemory_copyto, Cvoid, (Any, Ptr{Cvoid}, Any, Ptr{Cvoid}, Int), dest.mem, dest.ptr_or_offset, src.mem, src.ptr_or_offset, Int(n))
116+
if isbitstype(T)
117+
tdest = @_gc_preserve_begin dest
118+
tsrc = @_gc_preserve_begin src
119+
pdest = unsafe_convert(Ptr{Cvoid}, dest)
120+
psrc = unsafe_convert(Ptr{Cvoid}, src)
121+
memmove(pdest, psrc, aligned_sizeof(T) * n)
122+
@_gc_preserve_end tdest
123+
@_gc_preserve_end tsrc
124+
else
125+
ccall(:jl_genericmemory_copyto, Cvoid, (Any, Ptr{Cvoid}, Any, Ptr{Cvoid}, Int), dest.mem, dest.ptr_or_offset, src.mem, src.ptr_or_offset, Int(n))
126+
end
118127
return dest
119128
end
120129

base/hashing.jl

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ optional second argument `h` is another hash code to be mixed with the result.
1111
New types should implement the 2-argument form, typically by calling the 2-argument `hash`
1212
method recursively in order to mix hashes of the contents with each other (and with `h`).
1313
Typically, any type that implements `hash` should also implement its own [`==`](@ref) (hence
14-
[`isequal`](@ref)) to guarantee the property mentioned above. Types supporting subtraction
15-
(operator `-`) should also implement [`widen`](@ref), which is required to hash
16-
values inside heterogeneous arrays.
14+
[`isequal`](@ref)) to guarantee the property mentioned above.
1715
1816
The hash value may change when a new Julia process is started.
1917

base/initdefs.jl

+7-4
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,23 @@ function init_depot_path()
112112

113113
# otherwise, populate the depot path with the entries in JULIA_DEPOT_PATH,
114114
# expanding empty strings to the bundled depot
115-
populated = false
116-
for path in eachsplit(str, Sys.iswindows() ? ';' : ':')
115+
pushfirst_default = true
116+
for (i, path) in enumerate(eachsplit(str, Sys.iswindows() ? ';' : ':'))
117117
if isempty(path)
118118
append_bundled_depot_path!(DEPOT_PATH)
119119
else
120120
path = expanduser(path)
121121
path in DEPOT_PATH || push!(DEPOT_PATH, path)
122-
populated = true
122+
if i == 1
123+
# if a first entry is given, don't add the default depot at the start
124+
pushfirst_default = false
125+
end
123126
end
124127
end
125128

126129
# backwards compatibility: if JULIA_DEPOT_PATH only contains empty entries
127130
# (e.g., JULIA_DEPOT_PATH=':'), make sure to use the default depot
128-
if !populated
131+
if pushfirst_default
129132
pushfirst!(DEPOT_PATH, joinpath(homedir(), ".julia"))
130133
end
131134
else

base/intfuncs.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ end
976976
977977
Return an array with element type `T` (default `Int`) of the digits of `n` in the given
978978
base, optionally padded with zeros to a specified size. More significant digits are at
979-
higher indices, such that `n == sum(digits[k]*base^(k-1) for k=1:length(digits))`.
979+
higher indices, such that `n == sum(digits[k]*base^(k-1) for k in eachindex(digits))`.
980980
981981
See also [`ndigits`](@ref), [`digits!`](@ref),
982982
and for base 2 also [`bitstring`](@ref), [`count_ones`](@ref).

base/irrationals.jl

+24-9
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,22 @@ promote_rule(::Type{<:AbstractIrrational}, ::Type{Float16}) = Float16
4545
promote_rule(::Type{<:AbstractIrrational}, ::Type{Float32}) = Float32
4646
promote_rule(::Type{<:AbstractIrrational}, ::Type{<:AbstractIrrational}) = Float64
4747
promote_rule(::Type{<:AbstractIrrational}, ::Type{T}) where {T<:Real} = promote_type(Float64, T)
48-
promote_rule(::Type{S}, ::Type{T}) where {S<:AbstractIrrational,T<:Number} = promote_type(promote_type(S, real(T)), T)
48+
49+
function promote_rule(::Type{S}, ::Type{T}) where {S<:AbstractIrrational,T<:Number}
50+
U = promote_type(S, real(T))
51+
if S <: U
52+
# prevent infinite recursion
53+
promote_type(Float64, T)
54+
else
55+
promote_type(U, T)
56+
end
57+
end
4958

5059
AbstractFloat(x::AbstractIrrational) = Float64(x)::Float64
5160
Float16(x::AbstractIrrational) = Float16(Float32(x)::Float32)
5261
Complex{T}(x::AbstractIrrational) where {T<:Real} = Complex{T}(T(x))
5362

54-
# XXX this may change `DEFAULT_PRECISION`, thus not effect free
55-
@assume_effects :total function Rational{T}(x::AbstractIrrational) where T<:Integer
63+
function _irrational_to_rational(::Type{T}, x::AbstractIrrational) where T<:Integer
5664
o = precision(BigFloat)
5765
p = 256
5866
while true
@@ -66,13 +74,16 @@ Complex{T}(x::AbstractIrrational) where {T<:Real} = Complex{T}(T(x))
6674
p += 32
6775
end
6876
end
69-
Rational{BigInt}(x::AbstractIrrational) = throw(ArgumentError("Cannot convert an AbstractIrrational to a Rational{BigInt}: use rationalize(BigInt, x) instead"))
77+
Rational{T}(x::AbstractIrrational) where {T<:Integer} = _irrational_to_rational(T, x)
78+
_throw_argument_error_irrational_to_rational_bigint() = throw(ArgumentError("Cannot convert an AbstractIrrational to a Rational{BigInt}: use rationalize(BigInt, x) instead"))
79+
Rational{BigInt}(::AbstractIrrational) = _throw_argument_error_irrational_to_rational_bigint()
7080

71-
@assume_effects :total function (t::Type{T})(x::AbstractIrrational, r::RoundingMode) where T<:Union{Float32,Float64}
81+
function _irrational_to_float(::Type{T}, x::AbstractIrrational, r::RoundingMode) where T<:Union{Float32,Float64}
7282
setprecision(BigFloat, 256) do
7383
T(BigFloat(x)::BigFloat, r)
7484
end
7585
end
86+
(::Type{T})(x::AbstractIrrational, r::RoundingMode) where {T<:Union{Float32,Float64}} = _irrational_to_float(T, x, r)
7687

7788
float(::Type{<:AbstractIrrational}) = Float64
7889

@@ -110,14 +121,18 @@ end
110121
<=(x::AbstractFloat, y::AbstractIrrational) = x < y
111122

112123
# Irrational vs Rational
113-
@assume_effects :total function rationalize(::Type{T}, x::AbstractIrrational; tol::Real=0) where T
124+
function _rationalize_irrational(::Type{T}, x::AbstractIrrational, tol::Real) where {T<:Integer}
114125
return rationalize(T, big(x), tol=tol)
115126
end
116-
@assume_effects :total function lessrational(rx::Rational{<:Integer}, x::AbstractIrrational)
117-
# an @assume_effects :total version of `<` for determining if the rationalization of
118-
# an irrational number required rounding up or down
127+
function rationalize(::Type{T}, x::AbstractIrrational; tol::Real=0) where {T<:Integer}
128+
return _rationalize_irrational(T, x, tol)
129+
end
130+
function _lessrational(rx::Rational, x::AbstractIrrational)
119131
return rx < big(x)
120132
end
133+
function lessrational(rx::Rational, x::AbstractIrrational)
134+
return _lessrational(rx, x)
135+
end
121136
function <(x::AbstractIrrational, y::Rational{T}) where T
122137
T <: Unsigned && x < 0.0 && return true
123138
rx = rationalize(T, x)

0 commit comments

Comments
 (0)