Skip to content

Commit f32a5c6

Browse files
authored
Merge pull request #46075 from JuliaLang/backports-release-1.8
release-1.8: Backports for 1.8-rc4
2 parents 843b322 + 50bbad7 commit f32a5c6

Some content is hidden

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

91 files changed

+1672
-1061
lines changed

NEWS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ New library features
111111
* `extrema` now accepts an `init` keyword argument ([#36265], [#43604]).
112112
* `Iterators.countfrom` now accepts any type that defines `+` ([#37747]).
113113
* `@time` now separates out % time spent recompiling invalidated methods ([#45015]).
114-
* `@time_imports` now shows any compilation and recompilation time percentages per import ([#45064]).
115114

116115
Standard library changes
117116
------------------------
@@ -147,7 +146,8 @@ Standard library changes
147146

148147
#### InteractiveUtils
149148

150-
* New macro `@time_imports` for reporting any time spent importing packages and their dependencies ([#41612]).
149+
* New macro `@time_imports` for reporting any time spent importing packages and their dependencies, highlighting
150+
compilation and recompilation time as percentages per import ([#41612],[#45064]).
151151

152152
#### LinearAlgebra
153153

base/Base.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,6 @@ include("process.jl")
292292
include("ttyhascolor.jl")
293293
include("secretbuffer.jl")
294294

295-
# RandomDevice support
296-
include("randomdevice.jl")
297-
298295
# core math functions
299296
include("floatfuncs.jl")
300297
include("math.jl")
@@ -484,8 +481,6 @@ end
484481

485482
if is_primary_base_module
486483
function __init__()
487-
# for the few uses of Libc.rand in Base:
488-
Libc.srand()
489484
# Base library init
490485
reinit_stdio()
491486
Multimedia.reinit_displays() # since Multimedia.displays uses stdout as fallback

base/abstractarray.jl

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -879,13 +879,12 @@ See also [`copyto!`](@ref).
879879
is available from the `Future` standard library as `Future.copy!`.
880880
"""
881881
function copy!(dst::AbstractVector, src::AbstractVector)
882+
firstindex(dst) == firstindex(src) || throw(ArgumentError(
883+
"vectors must have the same offset for copy! (consider using `copyto!`)"))
882884
if length(dst) != length(src)
883885
resize!(dst, length(src))
884886
end
885-
for i in eachindex(dst, src)
886-
@inbounds dst[i] = src[i]
887-
end
888-
dst
887+
copyto!(dst, src)
889888
end
890889

891890
function copy!(dst::AbstractArray, src::AbstractArray)
@@ -1011,6 +1010,10 @@ julia> y
10111010
"""
10121011
function copyto!(dest::AbstractArray, src::AbstractArray)
10131012
isempty(src) && return dest
1013+
if dest isa BitArray
1014+
# avoid ambiguities with other copyto!(::AbstractArray, ::SourceArray) methods
1015+
return _copyto_bitarray!(dest, src)
1016+
end
10141017
src′ = unalias(dest, src)
10151018
copyto_unaliased!(IndexStyle(dest), dest, IndexStyle(src′), src′)
10161019
end
@@ -1080,8 +1083,9 @@ function copyto!(dest::AbstractArray, dstart::Integer,
10801083
destinds, srcinds = LinearIndices(dest), LinearIndices(src)
10811084
(checkbounds(Bool, destinds, dstart) && checkbounds(Bool, destinds, dstart+n-1)) || throw(BoundsError(dest, dstart:dstart+n-1))
10821085
(checkbounds(Bool, srcinds, sstart) && checkbounds(Bool, srcinds, sstart+n-1)) || throw(BoundsError(src, sstart:sstart+n-1))
1083-
@inbounds for i = 0:(n-1)
1084-
dest[dstart+i] = src[sstart+i]
1086+
src′ = unalias(dest, src)
1087+
@inbounds for i = 0:n-1
1088+
dest[dstart+i] = src′[sstart+i]
10851089
end
10861090
return dest
10871091
end
@@ -1103,22 +1107,23 @@ function copyto!(B::AbstractVecOrMat{R}, ir_dest::AbstractRange{Int}, jr_dest::A
11031107
end
11041108
@boundscheck checkbounds(B, ir_dest, jr_dest)
11051109
@boundscheck checkbounds(A, ir_src, jr_src)
1110+
A′ = unalias(B, A)
11061111
jdest = first(jr_dest)
11071112
for jsrc in jr_src
11081113
idest = first(ir_dest)
11091114
for isrc in ir_src
1110-
@inbounds B[idest,jdest] = A[isrc,jsrc]
1115+
@inbounds B[idest,jdest] = A[isrc,jsrc]
11111116
idest += step(ir_dest)
11121117
end
11131118
jdest += step(jr_dest)
11141119
end
11151120
return B
11161121
end
11171122

1118-
function copyto_axcheck!(dest, src)
1119-
@noinline checkaxs(axd, axs) = axd == axs || throw(DimensionMismatch("axes must agree, got $axd and $axs"))
1123+
@noinline _checkaxs(axd, axs) = axd == axs || throw(DimensionMismatch("axes must agree, got $axd and $axs"))
11201124

1121-
checkaxs(axes(dest), axes(src))
1125+
function copyto_axcheck!(dest, src)
1126+
_checkaxs(axes(dest), axes(src))
11221127
copyto!(dest, src)
11231128
end
11241129

@@ -1712,23 +1717,16 @@ end
17121717
_cs(d, a, b) = (a == b ? a : throw(DimensionMismatch(
17131718
"mismatch in dimension $d (expected $a got $b)")))
17141719

1715-
function dims2cat(::Val{dims}) where dims
1716-
if any((0), dims)
1717-
throw(ArgumentError("All cat dimensions must be positive integers, but got $dims"))
1718-
end
1719-
ntuple(in(dims), maximum(dims))
1720-
end
1721-
1720+
dims2cat(::Val{dims}) where dims = dims2cat(dims)
17221721
function dims2cat(dims)
17231722
if any((0), dims)
17241723
throw(ArgumentError("All cat dimensions must be positive integers, but got $dims"))
17251724
end
17261725
ntuple(in(dims), maximum(dims))
17271726
end
17281727

1729-
_cat(dims, X...) = cat_t(promote_eltypeof(X...), X...; dims=dims)
1728+
_cat(dims, X...) = _cat_t(dims, promote_eltypeof(X...), X...)
17301729

1731-
@inline cat_t(::Type{T}, X...; dims) where {T} = _cat_t(dims, T, X...)
17321730
@inline function _cat_t(dims, ::Type{T}, X...) where {T}
17331731
catdims = dims2cat(dims)
17341732
shape = cat_size_shape(catdims, X...)
@@ -1738,6 +1736,9 @@ _cat(dims, X...) = cat_t(promote_eltypeof(X...), X...; dims=dims)
17381736
end
17391737
return __cat(A, shape, catdims, X...)
17401738
end
1739+
# this version of `cat_t` is not very kind for inference and so its usage should be avoided,
1740+
# nevertheless it is here just for compat after https://github.com/JuliaLang/julia/pull/45028
1741+
@inline cat_t(::Type{T}, X...; dims) where {T} = _cat_t(dims, T, X...)
17411742

17421743
# Why isn't this called `__cat!`?
17431744
__cat(A, shape, catdims, X...) = __cat_offset!(A, shape, catdims, ntuple(zero, length(shape)), X...)
@@ -1876,8 +1877,8 @@ julia> reduce(hcat, vs)
18761877
"""
18771878
hcat(X...) = cat(X...; dims=Val(2))
18781879

1879-
typed_vcat(::Type{T}, X...) where T = cat_t(T, X...; dims=Val(1))
1880-
typed_hcat(::Type{T}, X...) where T = cat_t(T, X...; dims=Val(2))
1880+
typed_vcat(::Type{T}, X...) where T = _cat_t(Val(1), T, X...)
1881+
typed_hcat(::Type{T}, X...) where T = _cat_t(Val(2), T, X...)
18811882

18821883
"""
18831884
cat(A...; dims)
@@ -1913,7 +1914,8 @@ julia> cat(true, trues(2,2), trues(4)', dims=(1,2))
19131914
```
19141915
"""
19151916
@inline cat(A...; dims) = _cat(dims, A...)
1916-
_cat(catdims, A::AbstractArray{T}...) where {T} = cat_t(T, A...; dims=catdims)
1917+
# `@constprop :aggressive` allows `catdims` to be propagated as constant improving return type inference
1918+
@constprop :aggressive _cat(catdims, A::AbstractArray{T}...) where {T} = _cat_t(catdims, T, A...)
19171919

19181920
# The specializations for 1 and 2 inputs are important
19191921
# especially when running with --inline=no, see #11158
@@ -1924,12 +1926,12 @@ hcat(A::AbstractArray) = cat(A; dims=Val(2))
19241926
hcat(A::AbstractArray, B::AbstractArray) = cat(A, B; dims=Val(2))
19251927
hcat(A::AbstractArray...) = cat(A...; dims=Val(2))
19261928

1927-
typed_vcat(T::Type, A::AbstractArray) = cat_t(T, A; dims=Val(1))
1928-
typed_vcat(T::Type, A::AbstractArray, B::AbstractArray) = cat_t(T, A, B; dims=Val(1))
1929-
typed_vcat(T::Type, A::AbstractArray...) = cat_t(T, A...; dims=Val(1))
1930-
typed_hcat(T::Type, A::AbstractArray) = cat_t(T, A; dims=Val(2))
1931-
typed_hcat(T::Type, A::AbstractArray, B::AbstractArray) = cat_t(T, A, B; dims=Val(2))
1932-
typed_hcat(T::Type, A::AbstractArray...) = cat_t(T, A...; dims=Val(2))
1929+
typed_vcat(T::Type, A::AbstractArray) = _cat_t(Val(1), T, A)
1930+
typed_vcat(T::Type, A::AbstractArray, B::AbstractArray) = _cat_t(Val(1), T, A, B)
1931+
typed_vcat(T::Type, A::AbstractArray...) = _cat_t(Val(1), T, A...)
1932+
typed_hcat(T::Type, A::AbstractArray) = _cat_t(Val(2), T, A)
1933+
typed_hcat(T::Type, A::AbstractArray, B::AbstractArray) = _cat_t(Val(2), T, A, B)
1934+
typed_hcat(T::Type, A::AbstractArray...) = _cat_t(Val(2), T, A...)
19331935

19341936
# 2d horizontal and vertical concatenation
19351937

base/bitarray.jl

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,11 @@ function unsafe_copyto!(dest::BitArray, doffs::Integer, src::Union{BitArray,Arra
458458
return dest
459459
end
460460

461-
copyto!(dest::BitArray, doffs::Integer, src::Array, soffs::Integer, n::Integer) =
461+
copyto!(dest::BitArray, doffs::Integer, src::Union{BitArray,Array}, soffs::Integer, n::Integer) =
462462
_copyto_int!(dest, Int(doffs), src, Int(soffs), Int(n))
463-
function _copyto_int!(dest::BitArray, doffs::Int, src::Array, soffs::Int, n::Int)
463+
function _copyto_int!(dest::BitArray, doffs::Int, src::Union{BitArray,Array}, soffs::Int, n::Int)
464464
n == 0 && return dest
465+
n < 0 && throw(ArgumentError("Number of elements to copy must be nonnegative."))
465466
soffs < 1 && throw(BoundsError(src, soffs))
466467
doffs < 1 && throw(BoundsError(dest, doffs))
467468
soffs+n-1 > length(src) && throw(BoundsError(src, length(src)+1))
@@ -501,40 +502,42 @@ function Array{T,N}(B::BitArray{N}) where {T,N}
501502
end
502503

503504
BitArray(A::AbstractArray{<:Any,N}) where {N} = BitArray{N}(A)
505+
504506
function BitArray{N}(A::AbstractArray{T,N}) where N where T
505507
B = BitArray(undef, convert(Dims{N}, size(A)::Dims{N}))
506-
Bc = B.chunks
507-
l = length(B)
508+
_checkaxs(axes(B), axes(A))
509+
_copyto_bitarray!(B, A)
510+
return B::BitArray{N}
511+
end
512+
513+
function _copyto_bitarray!(B::BitArray, A::AbstractArray)
514+
l = length(A)
508515
l == 0 && return B
509-
ind = 1
516+
l > length(B) && throw(BoundsError(B, length(B)+1))
517+
Bc = B.chunks
518+
nc = num_bit_chunks(l)
519+
Ai = first(eachindex(A))
510520
@inbounds begin
511-
for i = 1:length(Bc)-1
521+
for i = 1:nc-1
512522
c = UInt64(0)
513523
for j = 0:63
514-
c |= (UInt64(convert(Bool, A[ind])::Bool) << j)
515-
ind += 1
524+
c |= (UInt64(convert(Bool, A[Ai])::Bool) << j)
525+
Ai = nextind(A, Ai)
516526
end
517527
Bc[i] = c
518528
end
519529
c = UInt64(0)
520-
for j = 0:_mod64(l-1)
521-
c |= (UInt64(convert(Bool, A[ind])::Bool) << j)
522-
ind += 1
530+
tail = _mod64(l - 1) + 1
531+
for j = 0:tail-1
532+
c |= (UInt64(convert(Bool, A[Ai])::Bool) << j)
533+
Ai = nextind(A, Ai)
523534
end
524-
Bc[end] = c
535+
msk = _msk_end(tail)
536+
Bc[nc] = (c & msk) | (Bc[nc] & ~msk)
525537
end
526538
return B
527539
end
528540

529-
function BitArray{N}(A::Array{Bool,N}) where N
530-
B = BitArray(undef, size(A))
531-
Bc = B.chunks
532-
l = length(B)
533-
l == 0 && return B
534-
copy_to_bitarray_chunks!(Bc, 1, A, 1, l)
535-
return B::BitArray{N}
536-
end
537-
538541
reinterpret(::Type{Bool}, B::BitArray, dims::NTuple{N,Int}) where {N} = reinterpret(B, dims)
539542
reinterpret(B::BitArray, dims::NTuple{N,Int}) where {N} = reshape(B, dims)
540543

@@ -721,24 +724,25 @@ function _unsafe_setindex!(B::BitArray, X::AbstractArray, I::BitArray)
721724
lx = length(X)
722725
last_chunk_len = _mod64(length(B)-1)+1
723726

724-
c = 1
727+
Xi = first(eachindex(X))
728+
lastXi = last(eachindex(X))
725729
for i = 1:lc
726730
@inbounds Imsk = Ic[i]
727731
@inbounds C = Bc[i]
728732
u = UInt64(1)
729733
for j = 1:(i < lc ? 64 : last_chunk_len)
730734
if Imsk & u != 0
731-
lx < c && throw_setindex_mismatch(X, c)
732-
@inbounds x = convert(Bool, X[c])
735+
Xi > lastXi && throw_setindex_mismatch(X, count(I))
736+
@inbounds x = convert(Bool, X[Xi])
733737
C = ifelse(x, C | u, C & ~u)
734-
c += 1
738+
Xi = nextind(X, Xi)
735739
end
736740
u <<= 1
737741
end
738742
@inbounds Bc[i] = C
739743
end
740-
if length(X) != c-1
741-
throw_setindex_mismatch(X, c-1)
744+
if Xi != nextind(X, lastXi)
745+
throw_setindex_mismatch(X, count(I))
742746
end
743747
return B
744748
end

base/checked.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ function checked_abs end
115115

116116
function checked_abs(x::SignedInt)
117117
r = ifelse(x<0, -x, x)
118-
r<0 && throw(OverflowError(string("checked arithmetic: cannot compute |x| for x = ", x, "::", typeof(x))))
119-
r
120-
end
118+
r<0 || return r
119+
msg = LazyString("checked arithmetic: cannot compute |x| for x = ", x, "::", typeof(x))
120+
throw(OverflowError(msg))
121+
end
121122
checked_abs(x::UnsignedInt) = x
122123
checked_abs(x::Bool) = x
123124

@@ -151,7 +152,7 @@ end
151152

152153

153154
throw_overflowerr_binaryop(op, x, y) = (@noinline;
154-
throw(OverflowError(Base.invokelatest(string, x, " ", op, " ", y, " overflowed for type ", typeof(x)))))
155+
throw(OverflowError(LazyString(x, " ", op, " ", y, " overflowed for type ", typeof(x)))))
155156

156157
"""
157158
Base.checked_add(x, y)

0 commit comments

Comments
 (0)