Skip to content

Commit 115b46a

Browse files
authored
Merge branch 'master' into test_for_no_invalidations
2 parents c66af9f + 69a22cf commit 115b46a

File tree

25 files changed

+193
-84
lines changed

25 files changed

+193
-84
lines changed

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ New library functions
2525
New library features
2626
--------------------
2727

28-
`sort(keys(::Dict))` and `sort(values(::Dict))` now automatically collect, they previously threw ([#56978]).
28+
* `sort(keys(::Dict))` and `sort(values(::Dict))` now automatically collect, they previously threw ([#56978]).
29+
* `Base.AbstractOneTo` is added as a supertype of one-based axes, with `Base.OneTo` as its subtype ([#56902]).
2930

3031
Standard library changes
3132
------------------------

base/abstractarray.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -818,15 +818,18 @@ julia> similar(falses(10), Float64, 2, 4)
818818
See also: [`undef`](@ref), [`isassigned`](@ref).
819819
"""
820820
similar(a::AbstractArray{T}) where {T} = similar(a, T)
821-
similar(a::AbstractArray, ::Type{T}) where {T} = similar(a, T, to_shape(axes(a)))
822-
similar(a::AbstractArray{T}, dims::Tuple) where {T} = similar(a, T, to_shape(dims))
823-
similar(a::AbstractArray{T}, dims::DimOrInd...) where {T} = similar(a, T, to_shape(dims))
824-
similar(a::AbstractArray, ::Type{T}, dims::DimOrInd...) where {T} = similar(a, T, to_shape(dims))
821+
similar(a::AbstractArray, ::Type{T}) where {T} = similar(a, T, axes(a))
822+
similar(a::AbstractArray{T}, dims::Tuple) where {T} = similar(a, T, dims)
823+
similar(a::AbstractArray{T}, dims::DimOrInd...) where {T} = similar(a, T, dims)
824+
similar(a::AbstractArray, ::Type{T}, dims::DimOrInd...) where {T} = similar(a, T, dims)
825825
# Similar supports specifying dims as either Integers or AbstractUnitRanges or any mixed combination
826826
# thereof. Ideally, we'd just convert Integers to OneTos and then call a canonical method with the axes,
827827
# but we don't want to require all AbstractArray subtypes to dispatch on Base.OneTo. So instead we
828828
# define this method to convert supported axes to Ints, with the expectation that an offset array
829829
# package will define a method with dims::Tuple{Union{Integer, UnitRange}, Vararg{Union{Integer, UnitRange}}}
830+
similar(a::AbstractArray, ::Type{T}, dims::Tuple{Union{Integer, AbstractOneTo}, Vararg{Union{Integer, AbstractOneTo}}}) where {T} = similar(a, T, to_shape(dims))
831+
# legacy method for packages that specialize similar(A::AbstractArray, ::Type{T}, dims::Tuple{Union{Integer, OneTo, CustomAxis}, Vararg{Union{Integer, OneTo, CustomAxis}}}
832+
# leaving this method in ensures that Base owns the more specific method
830833
similar(a::AbstractArray, ::Type{T}, dims::Tuple{Union{Integer, OneTo}, Vararg{Union{Integer, OneTo}}}) where {T} = similar(a, T, to_shape(dims))
831834
# similar creates an Array by default
832835
similar(a::AbstractArray, ::Type{T}, dims::Dims{N}) where {T,N} = Array{T,N}(undef, dims)
@@ -837,7 +840,7 @@ to_shape(dims::DimsOrInds) = map(to_shape, dims)::DimsOrInds
837840
# each dimension
838841
to_shape(i::Int) = i
839842
to_shape(i::Integer) = Int(i)
840-
to_shape(r::OneTo) = Int(last(r))
843+
to_shape(r::AbstractOneTo) = Int(last(r))
841844
to_shape(r::AbstractUnitRange) = r
842845

843846
"""
@@ -863,6 +866,8 @@ would create a 1-dimensional logical array whose indices match those
863866
of the columns of `A`.
864867
"""
865868
similar(::Type{T}, dims::DimOrInd...) where {T<:AbstractArray} = similar(T, dims)
869+
similar(::Type{T}, shape::Tuple{Union{Integer, AbstractOneTo}, Vararg{Union{Integer, AbstractOneTo}}}) where {T<:AbstractArray} = similar(T, to_shape(shape))
870+
# legacy method for packages that specialize similar(::Type{T}, dims::Tuple{Union{Integer, OneTo, CustomAxis}, Vararg{Union{Integer, OneTo, CustomAxis}})
866871
similar(::Type{T}, shape::Tuple{Union{Integer, OneTo}, Vararg{Union{Integer, OneTo}}}) where {T<:AbstractArray} = similar(T, to_shape(shape))
867872
similar(::Type{T}, dims::Dims) where {T<:AbstractArray} = T(undef, dims)
868873

base/intfuncs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ function append_c_digits(olength::Int, digits::Unsigned, buf, pos::Int)
845845
while i >= 2
846846
d, c = divrem(digits, 0x64)
847847
digits = oftype(digits, d)
848-
@inbounds d100 = _dec_d100[(c % Int) + 1]
848+
@inbounds d100 = _dec_d100[(c % Int)::Int + 1]
849849
@inbounds buf[pos + i - 2] = d100 % UInt8
850850
@inbounds buf[pos + i - 1] = (d100 >> 0x8) % UInt8
851851
i -= 2

base/precompilation.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,8 +835,8 @@ function _precompilepkgs(pkgs::Vector{String},
835835
# window between print cycles
836836
termwidth = displaysize(io)[2] - 4
837837
if !final_loop
838-
str = sprint(io -> show_progress(io, bar; termwidth, carriagereturn=false); context=io)
839-
print(iostr, Base._truncate_at_width_or_chars(true, str, termwidth), "\n")
838+
s = sprint(io -> show_progress(io, bar; termwidth, carriagereturn=false); context=io)
839+
print(iostr, Base._truncate_at_width_or_chars(true, s, termwidth), "\n")
840840
end
841841
for pkg_config in pkg_queue_show
842842
dep, config = pkg_config

base/range.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,14 +451,21 @@ if isdefined(Main, :Base)
451451
end
452452
end
453453

454+
"""
455+
Base.AbstractOneTo
456+
457+
Abstract type for ranges that start at 1 and have a step size of 1.
458+
"""
459+
abstract type AbstractOneTo{T} <: AbstractUnitRange{T} end
460+
454461
"""
455462
Base.OneTo(n)
456463
457464
Define an `AbstractUnitRange` that behaves like `1:n`, with the added
458465
distinction that the lower limit is guaranteed (by the type system) to
459466
be 1.
460467
"""
461-
struct OneTo{T<:Integer} <: AbstractUnitRange{T}
468+
struct OneTo{T<:Integer} <: AbstractOneTo{T}
462469
stop::T # invariant: stop >= zero(stop)
463470
function OneTo{T}(stop) where {T<:Integer}
464471
throwbool(r) = (@noinline; throw(ArgumentError("invalid index: $r of type Bool")))

base/reshapedarray.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ julia> reshape(1:6, 2, 3)
120120
reshape
121121

122122
reshape(parent::AbstractArray, dims::IntOrInd...) = reshape(parent, dims)
123+
reshape(parent::AbstractArray, shp::Tuple{Union{Integer,AbstractOneTo}, Vararg{Union{Integer,AbstractOneTo}}}) = reshape(parent, to_shape(shp))
124+
# legacy method for packages that specialize reshape(parent::AbstractArray, shp::Tuple{Union{Integer,OneTo,CustomAxis}, Vararg{Union{Integer,OneTo,CustomAxis}}})
125+
# leaving this method in ensures that Base owns the more specific method
123126
reshape(parent::AbstractArray, shp::Tuple{Union{Integer,OneTo}, Vararg{Union{Integer,OneTo}}}) = reshape(parent, to_shape(shp))
124127
reshape(parent::AbstractArray, dims::Tuple{Integer, Vararg{Integer}}) = reshape(parent, map(Int, dims))
125128
reshape(parent::AbstractArray, dims::Dims) = _reshape(parent, dims)

base/show.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ get(io::IO, key, default) = default
442442
keys(io::IOContext) = keys(io.dict)
443443
keys(io::IO) = keys(ImmutableDict{Symbol,Any}())
444444

445-
displaysize(io::IOContext) = haskey(io, :displaysize) ? io[:displaysize]::Tuple{Int,Int} : displaysize(io.io)
445+
displaysize(io::IOContext) = haskey(io, :displaysize) ? io[:displaysize]::Tuple{Int,Int} : displaysize(io.io)::Tuple{Int,Int}
446446

447447
show_circular(io::IO, @nospecialize(x)) = false
448448
function show_circular(io::IOContext, @nospecialize(x))

base/task.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ end
11521152
end
11531153

11541154
const get_sched_task = OncePerThread{Task}() do
1155-
@task wait_forever()
1155+
Task(wait_forever)
11561156
end
11571157

11581158
function ensure_rescheduled(othertask::Task)

contrib/juliac-buildscript.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ let mod = Base.include(Base.__toplevel__, inputfile)
197197
#entrypoint(join, (Base.GenericIOBuffer{Memory{UInt8}}, Array{String, 1}, Char))
198198
entrypoint(Base.task_done_hook, (Task,))
199199
entrypoint(Base.wait, ())
200+
entrypoint(Base.wait_forever, ())
200201
entrypoint(Base.trypoptask, (Base.StickyWorkqueue,))
201202
entrypoint(Base.checktaskempty, ())
202203
if add_ccallables
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cdbbe19efa29dcaa89fe167e15de449d

0 commit comments

Comments
 (0)