Skip to content

Commit

Permalink
Merge branch 'master' into LilithHafner-patch-3
Browse files Browse the repository at this point in the history
  • Loading branch information
LilithHafner authored Aug 15, 2024
2 parents 042cde5 + c7309d0 commit fbbd5f6
Show file tree
Hide file tree
Showing 271 changed files with 5,250 additions and 3,314 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
open-pull-requests-limit: 100
labels:
- "dependencies"
- "github-actions"
- "domain:ci"
2 changes: 1 addition & 1 deletion .github/workflows/LabelCheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- uses: yogevbd/[email protected]
- uses: yogevbd/enforce-label-action@a3c219da6b8fa73f6ba62b68ff09c469b3a1c024 # 2.2.2
with:
# REQUIRED_LABELS_ANY: "bug,enhancement,skip-changelog"
# REQUIRED_LABELS_ANY_DESCRIPTION: "Select at least one label ['bug','enhancement','skip-changelog']"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/Typos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
timeout-minutes: 5
steps:
- name: Checkout the JuliaLang/julia repository
uses: actions/checkout@v4
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
persist-credentials: false
- name: Check spelling with typos
#uses: crate-ci/typos@master
#uses: crate-ci/typos@c7af4712eda24dd1ef54bd8212973888489eb0ce # v1.23.5
env:
GH_TOKEN: "${{ github.token }}"
run: |
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/Whitespace.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Whitespace

permissions: {}

on:
push:
branches:
- master
pull_request:

jobs:
whitespace:
name: Check whitespace
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- name: Checkout the JuliaLang/julia repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
persist-credentials: false
- name: Check whitespace
run: |
contrib/check-whitespace.jl
4 changes: 2 additions & 2 deletions .github/workflows/cffconvert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out a copy of the repository
uses: actions/checkout@v4
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
persist-credentials: false

- name: Check whether the citation metadata from CITATION.cff is valid
uses: citation-file-format/[email protected]
uses: citation-file-format/cffconvert-github-action@4cf11baa70a673bfdf9dad0acc7ee33b3f4b6084 # 2.0.0
with:
args: "--validate"
3 changes: 3 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ Multi-threading changes
Build system changes
--------------------

* There is a new `Makefile` to build Julia and LLVM using the profile-guided and link-time optimizations (PGO and LTO) strategies, see `contrib/pgo-lto/Makefile` ([#45641]).

New library functions
---------------------

Expand Down Expand Up @@ -414,6 +416,7 @@ Deprecated or removed
[#44247]: https://github.com/JuliaLang/julia/issues/44247
[#45164]: https://github.com/JuliaLang/julia/issues/45164
[#45396]: https://github.com/JuliaLang/julia/issues/45396
[#45641]: https://github.com/JuliaLang/julia/issues/45641
[#45962]: https://github.com/JuliaLang/julia/issues/45962
[#46196]: https://github.com/JuliaLang/julia/issues/46196
[#46372]: https://github.com/JuliaLang/julia/issues/46372
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ endif
# Install appdata file
mkdir -p $(DESTDIR)$(datarootdir)/metainfo/
$(INSTALL_F) $(JULIAHOME)/contrib/julia.appdata.xml $(DESTDIR)$(datarootdir)/metainfo/
# Install terminal info database
ifneq ($(WITH_TERMINFO),0)
cp -R -L $(build_datarootdir)/terminfo $(DESTDIR)$(datarootdir)
endif

# Update RPATH entries and JL_SYSTEM_IMAGE_PATH if $(private_libdir_rel) != $(build_private_libdir_rel)
ifneq ($(private_libdir_rel),$(build_private_libdir_rel))
Expand Down
12 changes: 12 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,17 @@ Multi-threading changes
Build system changes
--------------------

* There are new `Makefile`s to build Julia and LLVM using the Binary Optimization and Layout Tool (BOLT), see `contrib/bolt` and `contrib/pgo-lto-bolt` ([#54107]).

New library functions
---------------------

* `logrange(start, stop; length)` makes a range of constant ratio, instead of constant step ([#39071])
* The new `isfull(c::Channel)` function can be used to check if `put!(c, some_value)` will block. ([#53159])
* `waitany(tasks; throw=false)` and `waitall(tasks; failfast=false, throw=false)` which wait multiple tasks at once ([#53341]).
* `uuid7()` creates an RFC 9652 compliant UUID with version 7 ([#54834]).
* `insertdims(array; dims)` allows to insert singleton dimensions into an array which is the inverse operation to `dropdims`
* The new `Fix` type is a generalization of `Fix1/Fix2` for fixing a single argument ([#54653]).

New library features
--------------------
Expand All @@ -90,11 +94,15 @@ New library features
data-races. Or use the callback form of `open` to have all that handled
automatically.
* `@timed` now additionally returns the elapsed compilation and recompilation time ([#52889])
* `escape_string` takes additional keyword arguments `ascii=true` (to escape all
non-ASCII characters) and `fullhex=true` (to require full 4/8-digit hex numbers
for u/U escapes, e.g. for C compatibility) [#55099]).
* `filter` can now act on a `NamedTuple` ([#50795]).
* `tempname` can now take a suffix string to allow the file name to include a suffix and include that suffix in
the uniquing checking ([#53474])
* `RegexMatch` objects can now be used to construct `NamedTuple`s and `Dict`s ([#50988])
* `Lockable` is now exported ([#54595])
* New `ltruncate`, `rtruncate` and `ctruncate` functions for truncating strings to text width, accounting for char widths ([#55351])

Standard library changes
------------------------
Expand Down Expand Up @@ -163,6 +171,10 @@ Deprecated or removed
External dependencies
---------------------

- The terminal info database, `terminfo`, is now vendored by default, providing a better
REPL user experience when `terminfo` is not available on the system. Julia can be built
without vendoring the database using the Makefile option `WITH_TERMINFO=0`. ([#55411])

Tooling Improvements
--------------------

Expand Down
3 changes: 3 additions & 0 deletions base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ function setproperty!(x, f::Symbol, v)
return setfield!(x, f, val)
end

typeof(function getproperty end).name.constprop_heuristic = Core.FORCE_CONST_PROP
typeof(function setproperty! end).name.constprop_heuristic = Core.FORCE_CONST_PROP

dotgetproperty(x, f) = getproperty(x, f)

getproperty(x::Module, f::Symbol, order::Symbol) = (@inline; getglobal(x, f, order))
Expand Down
40 changes: 39 additions & 1 deletion base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,10 @@ function _memory_offset(x::AbstractArray, I::Vararg{Any,N}) where {N}
return sum(map((i, s, o)->s*(i-o), J, strides(x), Tuple(first(CartesianIndices(x)))))*elsize(x)
end

## Special constprop heuristics for getindex/setindex
typename(typeof(function getindex end)).constprop_heuristic = Core.ARRAY_INDEX_HEURISTIC
typename(typeof(function setindex! end)).constprop_heuristic = Core.ARRAY_INDEX_HEURISTIC

## Approach:
# We only define one fallback method on getindex for all argument types.
# That dispatches to an (inlined) internal _getindex function, where the goal is
Expand Down Expand Up @@ -1917,7 +1921,7 @@ julia> vcat(range(1, 2, length=3)) # collects lazy ranges
2.0
julia> two = ([10, 20, 30]', Float64[4 5 6; 7 8 9]) # row vector and a matrix
([10 20 30], [4.0 5.0 6.0; 7.0 8.0 9.0])
(adjoint([10, 20, 30]), [4.0 5.0 6.0; 7.0 8.0 9.0])
julia> vcat(two...)
3×3 Matrix{Float64}:
Expand Down Expand Up @@ -3404,6 +3408,8 @@ mapany(f, itr) = Any[f(x) for x in itr]
Transform collection `c` by applying `f` to each element. For multiple collection arguments,
apply `f` elementwise, and stop when any of them is exhausted.
The element type of the result is determined in the same manner as in [`collect`](@ref).
See also [`map!`](@ref), [`foreach`](@ref), [`mapreduce`](@ref), [`mapslices`](@ref), [`zip`](@ref), [`Iterators.map`](@ref).
# Examples
Expand Down Expand Up @@ -3519,13 +3525,45 @@ julia> map(+, [1 2; 3 4], [1,10,100,1000], zeros(3,1)) # iterates until 3rd is
"""
map(f, it, iters...) = collect(Generator(f, it, iters...))

# Generic versions of push! for AbstractVector
# These are specialized further for Vector for faster resizing and setindexing
function push!(a::AbstractVector{T}, item) where T
# convert first so we don't grow the array if the assignment won't work
itemT = item isa T ? item : convert(T, item)::T
new_length = length(a) + 1
resize!(a, new_length)
a[new_length] = itemT
return a
end

# specialize and optimize the single argument case
function push!(a::AbstractVector{Any}, @nospecialize x)
new_length = length(a) + 1
resize!(a, new_length)
a[new_length] = x
return a
end
function push!(a::AbstractVector{Any}, @nospecialize x...)
@_terminates_locally_meta
na = length(a)
nx = length(x)
resize!(a, na + nx)
for i = 1:nx
a[na+i] = x[i]
end
return a
end

# multi-item push!, pushfirst! (built on top of type-specific 1-item version)
# (note: must not cause a dispatch loop when 1-item case is not defined)
push!(A, a, b) = push!(push!(A, a), b)
push!(A, a, b, c...) = push!(push!(A, a, b), c...)
pushfirst!(A, a, b) = pushfirst!(pushfirst!(A, b), a)
pushfirst!(A, a, b, c...) = pushfirst!(pushfirst!(A, c...), a, b)

# sizehint! does not nothing by default
sizehint!(a::AbstractVector, _) = a

## hashing AbstractArray ##

const hash_abstractarray_seed = UInt === UInt64 ? 0x7e2d6fb6448beb77 : 0xd4514ce5
Expand Down
64 changes: 64 additions & 0 deletions base/abstractarraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,70 @@ function _dropdims(A::AbstractArray, dims::Dims)
end
_dropdims(A::AbstractArray, dim::Integer) = _dropdims(A, (Int(dim),))


"""
insertdims(A; dims)
Inverse of [`dropdims`](@ref); return an array with new singleton dimensions
at every dimension in `dims`.
Repeated dimensions are forbidden and the largest entry in `dims` must be
less than or equal than `ndims(A) + length(dims)`.
The result shares the same underlying data as `A`, such that the
result is mutable if and only if `A` is mutable, and setting elements of one
alters the values of the other.
See also: [`dropdims`](@ref), [`reshape`](@ref), [`vec`](@ref).
# Examples
```jldoctest
julia> x = [1 2 3; 4 5 6]
2×3 Matrix{Int64}:
1 2 3
4 5 6
julia> insertdims(x, dims=3)
2×3×1 Array{Int64, 3}:
[:, :, 1] =
1 2 3
4 5 6
julia> insertdims(x, dims=(1,2,5)) == reshape(x, 1, 1, 2, 3, 1)
true
julia> dropdims(insertdims(x, dims=(1,2,5)), dims=(1,2,5))
2×3 Matrix{Int64}:
1 2 3
4 5 6
```
!!! compat "Julia 1.12"
Requires Julia 1.12 or later.
"""
insertdims(A; dims) = _insertdims(A, dims)
function _insertdims(A::AbstractArray{T, N}, dims::NTuple{M, Int}) where {T, N, M}
for i in eachindex(dims)
1 dims[i] || throw(ArgumentError("the smallest entry in dims must be ≥ 1."))
dims[i] N+M || throw(ArgumentError("the largest entry in dims must be not larger than the dimension of the array and the length of dims added"))
for j = 1:i-1
dims[j] == dims[i] && throw(ArgumentError("inserted dims must be unique"))
end
end

# acc is a tuple, where the first entry is the final shape
# the second entry off acc is a counter for the axes of A
inds= Base._foldoneto((acc, i) ->
i dims
? ((acc[1]..., Base.OneTo(1)), acc[2])
: ((acc[1]..., axes(A, acc[2])), acc[2] + 1),
((), 1), Val(N+M))
new_shape = inds[1]
return reshape(A, new_shape)
end
_insertdims(A::AbstractArray, dim::Integer) = _insertdims(A, (Int(dim),))



## Unary operators ##

"""
Expand Down
73 changes: 72 additions & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ _array_for(::Type{T}, itr, isz) where {T} = _array_for(T, isz, _similar_shape(it


"""
collect(collection)
collect(iterator)
Return an `Array` of all items in a collection or iterator. For dictionaries, returns
a `Vector` of `key=>value` [Pair](@ref Pair)s. If the argument is array-like or is an iterator
Expand All @@ -671,6 +671,9 @@ Used by [comprehensions](@ref man-comprehensions) to turn a [generator expressio
into an `Array`. Thus, *on generators*, the square-brackets notation may be used instead of calling `collect`,
see second example.
The element type of the returned array is based on the types of the values collected. However, if the
iterator is empty then the element type of the returned (empty) array is determined by type inference.
# Examples
Collect items from a `UnitRange{Int64}` collection:
Expand All @@ -692,6 +695,21 @@ julia> collect(x^2 for x in 1:3)
4
9
```
Collecting an empty iterator where the result type depends on type inference:
```jldoctest
julia> [rand(Bool) ? 1 : missing for _ in []]
Union{Missing, Int64}[]
```
When the iterator is non-empty, the result type depends only on values:
```julia-repl
julia> [rand(Bool) ? 1 : missing for _ in [""]]
1-element Vector{Int64}:
1
```
"""
collect(itr) = _collect(1:1 #= Array =#, itr, IteratorEltype(itr), IteratorSize(itr))

Expand Down Expand Up @@ -3064,3 +3082,56 @@ intersect(r::AbstractRange, v::AbstractVector) = intersect(v, r)
_getindex(v, i)
end
end

"""
wrap(Array, m::Union{Memory{T}, MemoryRef{T}}, dims)
Create an array of size `dims` using `m` as the underlying memory. This can be thought of as a safe version
of [`unsafe_wrap`](@ref) utilizing `Memory` or `MemoryRef` instead of raw pointers.
"""
function wrap end

# validity checking for _wrap calls, separate from allocation of Array so that it can be more likely to inline into the caller
function _wrap(ref::MemoryRef{T}, dims::NTuple{N, Int}) where {T, N}
mem = ref.mem
mem_len = length(mem) + 1 - memoryrefoffset(ref)
len = Core.checked_dims(dims...)
@boundscheck mem_len >= len || invalid_wrap_err(mem_len, dims, len)
if N != 1 && !(ref === GenericMemoryRef(mem) && len === mem_len)
mem = ccall(:jl_genericmemory_slice, Memory{T}, (Any, Ptr{Cvoid}, Int), mem, ref.ptr_or_offset, len)
ref = memoryref(mem)
end
return ref
end

@noinline invalid_wrap_err(len, dims, proddims) = throw(DimensionMismatch(LazyString(
"Attempted to wrap a MemoryRef of length ", len, " with an Array of size dims=", dims,
" which is invalid because prod(dims) = ", proddims, " > ", len,
" so that the array would have more elements than the underlying memory can store.")))

@eval @propagate_inbounds function wrap(::Type{Array}, m::MemoryRef{T}, dims::NTuple{N, Integer}) where {T, N}
dims = convert(Dims, dims)
ref = _wrap(m, dims)
$(Expr(:new, :(Array{T, N}), :ref, :dims))
end

@eval @propagate_inbounds function wrap(::Type{Array}, m::Memory{T}, dims::NTuple{N, Integer}) where {T, N}
dims = convert(Dims, dims)
ref = _wrap(memoryref(m), dims)
$(Expr(:new, :(Array{T, N}), :ref, :dims))
end
@eval @propagate_inbounds function wrap(::Type{Array}, m::MemoryRef{T}, l::Integer) where {T}
dims = (Int(l),)
ref = _wrap(m, dims)
$(Expr(:new, :(Array{T, 1}), :ref, :dims))
end
@eval @propagate_inbounds function wrap(::Type{Array}, m::Memory{T}, l::Integer) where {T}
dims = (Int(l),)
ref = _wrap(memoryref(m), (l,))
$(Expr(:new, :(Array{T, 1}), :ref, :dims))
end
@eval @propagate_inbounds function wrap(::Type{Array}, m::Memory{T}) where {T}
ref = memoryref(m)
dims = (length(m),)
$(Expr(:new, :(Array{T, 1}), :ref, :dims))
end
Loading

0 comments on commit fbbd5f6

Please sign in to comment.