Skip to content

Commit 6ec3afe

Browse files
authored
Merge pull request #41254 from JuliaLang/backports-release-1.7
Backports for 1.7-beta2
2 parents a15fbbc + ed9fda2 commit 6ec3afe

File tree

37 files changed

+317
-213
lines changed

37 files changed

+317
-213
lines changed

base/abstractarray.jl

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,11 +1635,21 @@ cat_size(A::AbstractArray) = size(A)
16351635
cat_size(A, d) = 1
16361636
cat_size(A::AbstractArray, d) = size(A, d)
16371637

1638+
cat_length(::Any) = 1
1639+
cat_length(a::AbstractArray) = length(a)
1640+
1641+
cat_ndims(a) = 0
1642+
cat_ndims(a::AbstractArray) = ndims(a)
1643+
16381644
cat_indices(A, d) = OneTo(1)
16391645
cat_indices(A::AbstractArray, d) = axes(A, d)
16401646

1641-
cat_similar(A, ::Type{T}, shape) where T = Array{T}(undef, shape)
1642-
cat_similar(A::AbstractArray, ::Type{T}, shape) where T = similar(A, T, shape)
1647+
cat_similar(A, ::Type{T}, shape::Tuple) where T = Array{T}(undef, shape)
1648+
cat_similar(A, ::Type{T}, shape::Vector) where T = Array{T}(undef, shape...)
1649+
cat_similar(A::Array, ::Type{T}, shape::Tuple) where T = Array{T}(undef, shape)
1650+
cat_similar(A::Array, ::Type{T}, shape::Vector) where T = Array{T}(undef, shape...)
1651+
cat_similar(A::AbstractArray, T::Type, shape::Tuple) = similar(A, T, shape)
1652+
cat_similar(A::AbstractArray, T::Type, shape::Vector) = similar(A, T, shape...)
16431653

16441654
# These are for backwards compatibility (even though internal)
16451655
cat_shape(dims, shape::Tuple{Vararg{Int}}) = shape
@@ -2034,22 +2044,25 @@ function typed_hvcat(::Type{T}, rows::Tuple{Vararg{Int}}, as...) where T
20342044
T[rs...;]
20352045
end
20362046

2037-
# nd concatenation
2047+
## N-dimensional concatenation ##
20382048

20392049
"""
2050+
hvncat(dim::Int, row_first, values...)
20402051
hvncat(dims::Tuple{Vararg{Int}}, row_first, values...)
20412052
hvncat(shape::Tuple{Vararg{Tuple}}, row_first, values...)
20422053
20432054
Horizontal, vertical, and n-dimensional concatenation of many `values` in one call.
20442055
2045-
This function is called
2046-
for block matrix syntax. The first argument either specifies the shape of the concatenation,
2047-
similar to `hvcat`, as a tuple of tuples, or the dimensions that specify the key number of
2048-
elements along each axis, and is used to determine the output dimensions. The `dims` form
2049-
is more performant, and is used by default when the concatenation operation has the same
2050-
number of elements along each axis (e.g., [a b; c d;;; e f ; g h]). The `shape` form is used
2051-
when the number of elements along each axis is unbalanced (e.g., [a b ; c]). Unbalanced
2052-
syntax needs additional validation overhead.
2056+
This function is called for block matrix syntax. The first argument either specifies the
2057+
shape of the concatenation, similar to `hvcat`, as a tuple of tuples, or the dimensions that
2058+
specify the key number of elements along each axis, and is used to determine the output
2059+
dimensions. The `dims` form is more performant, and is used by default when the concatenation
2060+
operation has the same number of elements along each axis (e.g., [a b; c d;;; e f ; g h]).
2061+
The `shape` form is used when the number of elements along each axis is unbalanced
2062+
(e.g., [a b ; c]). Unbalanced syntax needs additional validation overhead. The `dim` form
2063+
is an optimization for concatenation along just one dimension. `row_first` indicates how
2064+
`values` are ordered. The meaning of the first and second elements of `shape` are also
2065+
swapped based on `row_first`.
20532066
20542067
# Examples
20552068
```jldoctest
@@ -2097,6 +2110,24 @@ julia> hvncat(((3, 3), (3, 3), (6,)), true, a, b, c, d, e, f)
20972110
[:, :, 2] =
20982111
4 5 6
20992112
```
2113+
2114+
# Examples for construction of the arguments:
2115+
[a b c ; d e f ;;;
2116+
g h i ; j k l ;;;
2117+
m n o ; p q r ;;;
2118+
s t u ; v w x]
2119+
=> dims = (2, 3, 4)
2120+
2121+
[a b ; c ;;; d ;;;;]
2122+
___ _ _
2123+
2 1 1 = elements in each row (2, 1, 1)
2124+
_______ _
2125+
3 1 = elements in each column (3, 1)
2126+
_____________
2127+
4 = elements in each 3d slice (4,)
2128+
_____________
2129+
4 = elements in each 4d slice (4,)
2130+
=> shape = ((2, 1, 1), (3, 1), (4,), (4,)) with `rowfirst` = true
21002131
"""
21012132
hvncat(::Tuple{}, ::Bool) = []
21022133
hvncat(::Tuple{}, ::Bool, xs...) = []
@@ -2177,7 +2208,7 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as::AbstractArray...) where {T, N}
21772208
end
21782209
end
21792210

2180-
A = Array{T, nd}(undef, ntuple(d -> cat_size(as[1], d), N - 1)..., Ndim, ntuple(x -> 1, nd - N)...)
2211+
A = cat_similar(as[1], T, (ntuple(d -> size(as[1], d), N - 1)..., Ndim, ntuple(x -> 1, nd - N)...))
21812212
k = 1
21822213
for a as
21832214
for i eachindex(a)
@@ -2188,9 +2219,6 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as::AbstractArray...) where {T, N}
21882219
return A
21892220
end
21902221

2191-
cat_ndims(a) = 0
2192-
cat_ndims(a::AbstractArray) = ndims(a)
2193-
21942222
function _typed_hvncat(::Type{T}, ::Val{N}, as...) where {T, N}
21952223
# optimization for scalars and 1-length arrays that can be concatenated by copying them linearly
21962224
# into the destination
@@ -2257,12 +2285,12 @@ function _typed_hvncat(::Type{T}, dims::Tuple{Vararg{Int, N}}, row_first::Bool,
22572285
elseif currentdims[d] < outdims[d] # dimension in progress
22582286
break
22592287
else # exceeded dimension
2260-
ArgumentError("argument $i has too many elements along axis $d") |> throw
2288+
throw(ArgumentError("argument $i has too many elements along axis $d"))
22612289
end
22622290
end
22632291
end
22642292
elseif currentdims[d1] > outdims[d1] # exceeded dimension
2265-
ArgumentError("argument $i has too many elements along axis $d1") |> throw
2293+
throw(ArgumentError("argument $i has too many elements along axis $d1"))
22662294
end
22672295
end
22682296

@@ -2276,7 +2304,7 @@ function _typed_hvncat(::Type{T}, dims::Tuple{Vararg{Int, N}}, row_first::Bool,
22762304
len == outlen || ArgumentError("too many elements in arguments; expected $(outlen), got $(len)") |> throw
22772305

22782306
# copy into final array
2279-
A = Array{T, nd}(undef, outdims...)
2307+
A = cat_similar(as[1], T, outdims)
22802308
# @assert all(==(0), currentdims)
22812309
outdims .= 0
22822310
hvncat_fill!(A, currentdims, outdims, d1, d2, as)
@@ -2308,7 +2336,8 @@ function _typed_hvncat(::Type{T}, shape::Tuple{Vararg{Tuple, N}}, row_first::Boo
23082336
if d == 1 || i == 1 || wasstartblock
23092337
currentdims[d] += dsize
23102338
elseif dsize != cat_size(as[i - 1], ad)
2311-
ArgumentError("argument $i has a mismatched number of elements along axis $ad; expected $(cat_size(as[i - 1], ad)), got $dsize") |> throw
2339+
throw(ArgumentError("""argument $i has a mismatched number of elements along axis $ad; \
2340+
expected $(cat_size(as[i - 1], ad)), got $dsize"""))
23122341
end
23132342

23142343
wasstartblock = blockcounts[d] == 1 # remember for next dimension
@@ -2318,7 +2347,8 @@ function _typed_hvncat(::Type{T}, shape::Tuple{Vararg{Tuple, N}}, row_first::Boo
23182347
if outdims[d] == 0
23192348
outdims[d] = currentdims[d]
23202349
elseif outdims[d] != currentdims[d]
2321-
ArgumentError("argument $i has a mismatched number of elements along axis $ad; expected $(abs(outdims[d] - (currentdims[d] - dsize))), got $dsize") |> throw
2350+
throw(ArgumentError("""argument $i has a mismatched number of elements along axis $ad; \
2351+
expected $(abs(outdims[d] - (currentdims[d] - dsize))), got $dsize"""))
23222352
end
23232353
currentdims[d] = 0
23242354
blockcounts[d] = 0
@@ -2335,12 +2365,12 @@ function _typed_hvncat(::Type{T}, shape::Tuple{Vararg{Tuple, N}}, row_first::Boo
23352365
# @assert all(==(0), blockcounts)
23362366

23372367
# copy into final array
2338-
A = Array{T, nd}(undef, outdims...)
2368+
A = cat_similar(as[1], T, outdims)
23392369
hvncat_fill!(A, currentdims, blockcounts, d1, d2, as)
23402370
return A
23412371
end
23422372

2343-
function hvncat_fill!(A::Array{T, N}, scratch1::Vector{Int}, scratch2::Vector{Int}, d1::Int, d2::Int, as::Tuple{Vararg}) where {T, N}
2373+
function hvncat_fill!(A::AbstractArray{T, N}, scratch1::Vector{Int}, scratch2::Vector{Int}, d1::Int, d2::Int, as::Tuple{Vararg}) where {T, N}
23442374
outdims = size(A)
23452375
offsets = scratch1
23462376
inneroffsets = scratch2
@@ -2382,9 +2412,6 @@ end
23822412
Ai
23832413
end
23842414

2385-
cat_length(a::AbstractArray) = length(a)
2386-
cat_length(::Any) = 1
2387-
23882415
## Reductions and accumulates ##
23892416

23902417
function isequal(A::AbstractArray, B::AbstractArray)

base/compiler/tfuncs.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,10 @@ end
15681568

15691569
# Query whether the given intrinsic is nothrow
15701570

1571+
_iszero(x) = x === Intrinsics.xor_int(x, x)
1572+
_isneg1(x) = _iszero(Intrinsics.not_int(x))
1573+
_istypemin(x) = !_iszero(x) && Intrinsics.neg_int(x) === x
1574+
15711575
function intrinsic_nothrow(f::IntrinsicFunction, argtypes::Array{Any, 1})
15721576
# First check that we have the correct number of arguments
15731577
iidx = Int(reinterpret(Int32, f::IntrinsicFunction)) + 1
@@ -1594,11 +1598,10 @@ function intrinsic_nothrow(f::IntrinsicFunction, argtypes::Array{Any, 1})
15941598
return false
15951599
end
15961600
den_val = argtypes[2].val
1597-
den_val !== zero(typeof(den_val)) || return false
1601+
_iszero(den_val) && return false
15981602
f !== Intrinsics.checked_sdiv_int && return true
15991603
# Nothrow as long as we additionally don't do typemin(T)/-1
1600-
return den_val !== -1 || (isa(argtypes[1], Const) &&
1601-
argtypes[1].val !== typemin(typeof(den_val)))
1604+
return !_isneg1(den_val) || (isa(argtypes[1], Const) && !_istypemin(argtypes[1].val))
16021605
end
16031606
if f === Intrinsics.pointerref
16041607
# Nothrow as long as the types are ok. N.B.: dereferencability is not

base/experimental.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,21 @@ method tables (e.g., using [`Core.Compiler.OverlayMethodTable`](@ref)).
268268
"""
269269
macro overlay(mt, def)
270270
def = macroexpand(__module__, def) # to expand @inline, @generated, etc
271-
if !isexpr(def, [:function, :(=)]) || !isexpr(def.args[1], :call)
271+
if !isexpr(def, [:function, :(=)])
272+
error("@overlay requires a function Expr")
273+
end
274+
if isexpr(def.args[1], :call)
275+
def.args[1].args[1] = Expr(:overlay, mt, def.args[1].args[1])
276+
elseif isexpr(def.args[1], :where)
277+
def.args[1].args[1].args[1] = Expr(:overlay, mt, def.args[1].args[1].args[1])
278+
else
272279
error("@overlay requires a function Expr")
273280
end
274-
def.args[1].args[1] = Expr(:overlay, mt, def.args[1].args[1])
275281
esc(def)
276282
end
277283

278284
let new_mt(name::Symbol, mod::Module) = begin
279-
ccall(:jl_check_top_level_effect, Cvoid, (Any, Cstring), mod, name)
285+
ccall(:jl_check_top_level_effect, Cvoid, (Any, Cstring), mod, "@MethodTable")
280286
ccall(:jl_new_method_table, Any, (Any, Any), name, mod)
281287
end
282288
@eval macro MethodTable(name::Symbol)

base/expr.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ function make_atomic(order, ex)
534534
elseif isexpr(ex, :call, 3)
535535
return make_atomic(order, ex.args[2], ex.args[1], ex.args[3])
536536
elseif ex.head === :(=)
537-
l, r = ex.args[1], ex.args[2]
537+
l, r = ex.args[1], esc(ex.args[2])
538538
if is_expr(l, :., 2)
539539
ll, lr = esc(l.args[1]), esc(l.args[2])
540540
return :(setproperty!($ll, $lr, $r, $order))

base/range.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,9 @@ function sum(r::AbstractRange{<:Real})
12171217
end
12181218

12191219
function _in_range(x, r::AbstractRange)
1220-
if step(r) == 0
1220+
if !isfinite(x)
1221+
return false
1222+
elseif iszero(step(r))
12211223
return !isempty(r) && first(r) == x
12221224
else
12231225
n = round(Integer, (x - first(r)) / step(r)) + 1

base/rational.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,22 @@ unsafe_rational(num::T, den::T) where {T<:Integer} = unsafe_rational(T, num, den
1818
unsafe_rational(num::Integer, den::Integer) = unsafe_rational(promote(num, den)...)
1919

2020
@noinline __throw_rational_argerror_typemin(T) = throw(ArgumentError("invalid rational: denominator can't be typemin($T)"))
21-
function checked_den(num::T, den::T) where T<:Integer
21+
function checked_den(::Type{T}, num::T, den::T) where T<:Integer
2222
if signbit(den)
2323
den = -den
24-
signbit(den) && __throw_rational_argerror_typemin(T)
24+
signbit(den) && __throw_rational_argerror_typemin(typeof(den))
2525
num = -num
2626
end
2727
return unsafe_rational(T, num, den)
2828
end
29+
checked_den(num::T, den::T) where T<:Integer = checked_den(T, num, den)
2930
checked_den(num::Integer, den::Integer) = checked_den(promote(num, den)...)
3031

3132
@noinline __throw_rational_argerror_zero(T) = throw(ArgumentError("invalid rational: zero($T)//zero($T)"))
3233
function Rational{T}(num::Integer, den::Integer) where T<:Integer
3334
iszero(den) && iszero(num) && __throw_rational_argerror_zero(T)
3435
num, den = divgcd(num, den)
35-
return checked_den(T(num), T(den))
36+
return checked_den(T, T(num), T(den))
3637
end
3738

3839
Rational(n::T, d::T) where {T<:Integer} = Rational{T}(n, d)

base/strings/search.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ function _rsearchindex(s::AbstractVector{<:Union{Int8,UInt8}}, t::AbstractVector
459459
n = length(t)
460460
m = length(s)
461461
k = Int(_k) - sentinel
462-
k < 1 && throw(BoundsError(s, _k))
462+
k < 0 && throw(BoundsError(s, _k))
463463

464464
if n == 0
465465
return 0 <= k <= m ? max(k, 1) : sentinel

deps/checksums/Pkg-13ed9373de1c6da3952ed6db99b1bac37d8deedc.tar.gz/md5

Lines changed: 0 additions & 1 deletion
This file was deleted.

deps/checksums/Pkg-13ed9373de1c6da3952ed6db99b1bac37d8deedc.tar.gz/sha512

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
77b9bf19937476f9b2120dfbafc3322b
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
c9079f0c2b4d6ad34eca479f4db14041ac04f0780feaa1b16de552e55ca862f0d56c9a50437304639b96777a2c941c4b7a5eb0ce23071a456126a5c2da23c2e1

deps/checksums/Statistics-4b3ef9aaa79350510ca0be395458f66051c2f92d.tar.gz/md5

Lines changed: 0 additions & 1 deletion
This file was deleted.

deps/checksums/Statistics-4b3ef9aaa79350510ca0be395458f66051c2f92d.tar.gz/sha512

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4c09536f4f769b23e88fee769f5a09bd
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e409fa943a9683a129b80c78ef74572df316ed414dfc8c208f1500d0f07d4d41870d44654446e2c20d1b9ed11e62c4fc6107b6e5789939edbd049fc2aaf22f63

0 commit comments

Comments
 (0)