Skip to content

Commit c581d7c

Browse files
authored
Merge branch 'master' into vc/excise_random
2 parents 3cbf778 + ba98467 commit c581d7c

File tree

241 files changed

+8630
-6386
lines changed

Some content is hidden

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

241 files changed

+8630
-6386
lines changed

.github/workflows/Typos.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Typos
2+
3+
permissions: {}
4+
5+
on: [pull_request]
6+
7+
jobs:
8+
typos-check:
9+
name: Check for new typos
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 5
12+
steps:
13+
- name: Checkout the JuliaLang/julia repository
14+
uses: actions/checkout@v4
15+
with:
16+
persist-credentials: false
17+
- name: Check spelling with typos
18+
#uses: crate-ci/typos@master
19+
env:
20+
GH_TOKEN: "${{ github.token }}"
21+
run: |
22+
git fetch --depth=1 origin ${{ github.base_ref }}
23+
OLD_FILES=$(git diff-index --name-only --diff-filter=ad FETCH_HEAD)
24+
NEW_FILES=$(git diff-index --name-only --diff-filter=d FETCH_HEAD)
25+
26+
mkdir -p "${{ runner.temp }}/typos"
27+
RELEASE_ASSET_URL="$(
28+
gh api /repos/crate-ci/typos/releases/latest \
29+
--jq '."assets"[] | select(."name" | test("^typos-.+-x86_64-unknown-linux-musl\\.tar\\.gz$")) | ."browser_download_url"'
30+
)"
31+
wget --secure-protocol=TLSv1_3 --max-redirect=1 --retry-on-host-error --retry-connrefused --tries=3 \
32+
--quiet --output-document=- "${RELEASE_ASSET_URL}" \
33+
| tar -xz -C "${{ runner.temp }}/typos" ./typos
34+
"${{ runner.temp }}/typos/typos" --version
35+
36+
echo -n $NEW_FILES | xargs "${{ runner.temp }}/typos/typos" --format json >> ${{ runner.temp }}/new_typos.jsonl || true
37+
git checkout FETCH_HEAD -- $OLD_FILES
38+
echo -n $OLD_FILES | xargs "${{ runner.temp }}/typos/typos" --format json >> ${{ runner.temp }}/old_typos.jsonl || true
39+
40+
python -c '
41+
import sys, json
42+
old = set()
43+
with open(sys.argv[1]) as old_file:
44+
for line in old_file:
45+
old.add(json.loads(line)["typo"])
46+
clean = True
47+
with open(sys.argv[2]) as new_file:
48+
for line in new_file:
49+
new = json.loads(line)
50+
if new["typo"] not in old:
51+
if len(new["typo"]) > 6: # Short typos might be false positives. Long are probably real.
52+
clean = False
53+
print("::warning file={},line={},col={}::perhaps \"{}\" should be \"{}\".".format(
54+
new["path"], new["line_num"], new["byte_offset"],
55+
new["typo"], " or ".join(new["corrections"])))
56+
sys.exit(1 if not clean else 0)' "${{ runner.temp }}/old_typos.jsonl" "${{ runner.temp }}/new_typos.jsonl"

NEWS.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ New language features
88
difference between `public` and `export` is that `public` names do not become
99
available when `using` a package/module. ([#50105])
1010
* `ScopedValue` implement dynamic scope with inheritance across tasks ([#50958]).
11+
* The new macro `Base.Cartesian.@ncallkw` is analogous to `Base.Cartesian.@ncall`,
12+
but allows to add keyword arguments to the function call ([#51501]).
13+
* Support for Unicode 15.1 ([#51799]).
14+
* A new `AbstractString` type, `AnnotatedString`, is introduced that allows for
15+
regional annotations to be attached to an underlying string. This type is
16+
particularly useful for holding styling information, and is used extensively
17+
in the new `StyledStrings` standard library. There is also a new `AnnotatedChar`
18+
type, that is the equivalent new `AbstractChar` type.
1119

1220
Language changes
1321
----------------
@@ -51,6 +59,17 @@ New library features
5159
Standard library changes
5260
------------------------
5361

62+
#### StyledStrings
63+
64+
* A new standard library for handling styling in a more comprehensive and structured way.
65+
* The new `Faces` struct serves as a container for text styling information
66+
(think typeface, as well as color and decoration), and comes with a framework
67+
to provide a convenient, extensible (via `addface!`), and customisable (with a
68+
user's `Faces.toml` and `loadfaces!`) approach to
69+
styled content.
70+
* The new `@styled_str` string macro provides a convenient way of creating a
71+
`AnnotatedString` with various faces or other attributes applied.
72+
5473
#### Package Manager
5574

5675
#### LinearAlgebra
@@ -70,6 +89,7 @@ Standard library changes
7089

7190
* Tab complete hints now show in lighter text while typing in the repl. To disable
7291
set `Base.active_repl.options.hint_tab_completes = false` ([#51229])
92+
* Meta-M with an empty prompt now returns the contextual module of the REPL to `Main`.
7393

7494
#### SuiteSparse
7595

@@ -107,5 +127,8 @@ External dependencies
107127
Tooling Improvements
108128
--------------------
109129

130+
* CI now performs limited automatic typo detection on all PRs. If you merge a PR with a
131+
failing typo CI check, then the reported typos will be automatically ignored in future CI
132+
runs on PRs that edit those same files. ([#51704])
110133

111134
<!--- generated by NEWS-update.jl: -->

base/Base.jl

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,19 @@ using Core.Intrinsics, Core.IR
66

77
# to start, we're going to use a very simple definition of `include`
88
# that doesn't require any function (except what we can get from the `Core` top-module)
9-
const _included_files = Array{Tuple{Module,String},1}(Core.undef, 1)
9+
# start this big so that we don't have to resize before we have defined how to grow an array
10+
const _included_files = Array{Tuple{Module,String},1}(Core.undef, 400)
11+
setfield!(_included_files, :size, (1,))
1012
function include(mod::Module, path::String)
11-
ccall(:jl_array_grow_end, Cvoid, (Any, UInt), _included_files, UInt(1))
12-
Core.arrayset(true, _included_files, (mod, ccall(:jl_prepend_cwd, Any, (Any,), path)), arraylen(_included_files))
13+
len = getfield(_included_files.size, 1)
14+
memlen = _included_files.ref.mem.length
15+
lenp1 = Core.add_int(len, 1)
16+
if len === memlen # by the time this is true we hopefully will have defined _growend!
17+
_growend!(_included_files, UInt(1))
18+
else
19+
setfield!(_included_files, :size, (lenp1,))
20+
end
21+
Core.memoryrefset!(Core.memoryref(_included_files.ref, lenp1), (mod, ccall(:jl_prepend_cwd, Any, (Any,), path)), :not_atomic, true)
1322
Core.println(path)
1423
ccall(:jl_uv_flush, Nothing, (Ptr{Nothing},), Core.io_pointer(Core.stdout))
1524
Core.include(mod, path)
@@ -31,6 +40,7 @@ macro noinline() Expr(:meta, :noinline) end
3140
getproperty(x::Module, f::Symbol) = (@inline; getglobal(x, f))
3241
getproperty(x::Type, f::Symbol) = (@inline; getfield(x, f))
3342
setproperty!(x::Type, f::Symbol, v) = error("setfield! fields of Types should not be changed")
43+
setproperty!(x::Array, f::Symbol, v) = error("setfield! fields of Array should not be changed")
3444
getproperty(x::Tuple, f::Int) = (@inline; getfield(x, f))
3545
setproperty!(x::Tuple, f::Int, v) = setfield!(x, f, v) # to get a decent error
3646

@@ -115,6 +125,12 @@ time_ns() = ccall(:jl_hrtime, UInt64, ())
115125

116126
start_base_include = time_ns()
117127

128+
# A warning to be interpolated in the docstring of every dangerous mutating function in Base, see PR #50824
129+
const _DOCS_ALIASING_WARNING = """
130+
!!! warning
131+
Behavior can be unexpected when any mutated argument shares memory with any other argument.
132+
"""
133+
118134
## Load essential files and libraries
119135
include("essentials.jl")
120136
include("ctypes.jl")
@@ -186,23 +202,22 @@ include("strings/lazy.jl")
186202

187203
# array structures
188204
include("indices.jl")
205+
include("genericmemory.jl")
189206
include("array.jl")
190207
include("abstractarray.jl")
191208
include("subarray.jl")
192209
include("views.jl")
193210
include("baseext.jl")
194211

212+
include("c.jl")
195213
include("ntuple.jl")
196-
197214
include("abstractdict.jl")
198215
include("iddict.jl")
199216
include("idset.jl")
200-
201217
include("iterators.jl")
202218
using .Iterators: zip, enumerate, only
203219
using .Iterators: Flatten, Filter, product # for generators
204220
using .Iterators: Stateful # compat (was formerly used in reinterpretarray.jl)
205-
206221
include("namedtuple.jl")
207222

208223
# For OS specific stuff
@@ -218,6 +233,17 @@ function strcat(x::String, y::String)
218233
end
219234
include(strcat((length(Core.ARGS)>=2 ? Core.ARGS[2] : ""), "build_h.jl")) # include($BUILDROOT/base/build_h.jl)
220235
include(strcat((length(Core.ARGS)>=2 ? Core.ARGS[2] : ""), "version_git.jl")) # include($BUILDROOT/base/version_git.jl)
236+
# Initialize DL_LOAD_PATH as early as possible. We are defining things here in
237+
# a slightly more verbose fashion than usual, because we're running so early.
238+
const DL_LOAD_PATH = String[]
239+
let os = ccall(:jl_get_UNAME, Any, ())
240+
if os === :Darwin || os === :Apple
241+
if Base.DARWIN_FRAMEWORK
242+
push!(DL_LOAD_PATH, "@loader_path/Frameworks")
243+
end
244+
push!(DL_LOAD_PATH, "@loader_path")
245+
end
246+
end
221247

222248
# numeric operations
223249
include("hashing.jl")
@@ -265,24 +291,24 @@ include("set.jl")
265291

266292
# Strings
267293
include("char.jl")
294+
function array_new_memory(mem::Memory{UInt8}, newlen::Int)
295+
# add an optimization to array_new_memory for StringVector
296+
if (@assume_effects :total @ccall jl_genericmemory_owner(mem::Any,)::Any) isa String
297+
# If data is in a String, keep it that way.
298+
# When implemented, this could use jl_gc_expand_string(oldstr, newlen) as an optimization
299+
str = _string_n(newlen)
300+
return (@assume_effects :total !:consistent @ccall jl_string_to_genericmemory(str::Any,)::Memory{UInt8})
301+
else
302+
# TODO: when implemented, this should use a memory growing call
303+
return typeof(mem)(undef, newlen)
304+
end
305+
end
268306
include("strings/basic.jl")
269307
include("strings/string.jl")
270308
include("strings/substring.jl")
271-
272-
# Initialize DL_LOAD_PATH as early as possible. We are defining things here in
273-
# a slightly more verbose fashion than usual, because we're running so early.
274-
const DL_LOAD_PATH = String[]
275-
let os = ccall(:jl_get_UNAME, Any, ())
276-
if os === :Darwin || os === :Apple
277-
if Base.DARWIN_FRAMEWORK
278-
push!(DL_LOAD_PATH, "@loader_path/Frameworks")
279-
end
280-
push!(DL_LOAD_PATH, "@loader_path")
281-
end
282-
end
309+
include("strings/cstring.jl")
283310

284311
include("osutils.jl")
285-
include("c.jl")
286312

287313
# Core I/O
288314
include("io.jl")

base/abstractarray.jl

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ julia> ndims(A)
268268
3
269269
```
270270
"""
271-
ndims(::AbstractArray{T,N}) where {T,N} = N
272-
ndims(::Type{<:AbstractArray{<:Any,N}}) where {N} = N
271+
ndims(::AbstractArray{T,N}) where {T,N} = N::Int
272+
ndims(::Type{<:AbstractArray{<:Any,N}}) where {N} = N::Int
273273
ndims(::Type{Union{}}, slurp...) = throw(ArgumentError("Union{} does not have elements"))
274274

275275
"""
@@ -731,8 +731,6 @@ end
731731
checkbounds_indices(::Type{Bool}, IA::Tuple, ::Tuple{}) = (@inline; all(x->length(x)==1, IA))
732732
checkbounds_indices(::Type{Bool}, ::Tuple{}, ::Tuple{}) = true
733733

734-
throw_boundserror(A, I) = (@noinline; throw(BoundsError(A, I)))
735-
736734
# check along a single dimension
737735
"""
738736
checkindex(Bool, inds::AbstractUnitRange, index)
@@ -905,6 +903,8 @@ If `dst` and `src` are of the same type, `dst == src` should hold after
905903
the call. If `dst` and `src` are multidimensional arrays, they must have
906904
equal [`axes`](@ref).
907905
906+
$(_DOCS_ALIASING_WARNING)
907+
908908
See also [`copyto!`](@ref).
909909
910910
!!! compat "Julia 1.1"
@@ -1080,28 +1080,45 @@ function copyto_unaliased!(deststyle::IndexStyle, dest::AbstractArray, srcstyle:
10801080
if srcstyle isa IndexLinear
10811081
# Single-index implementation
10821082
@inbounds for i in srcinds
1083-
dest[i + Δi] = src[i]
1083+
if isassigned(src, i)
1084+
dest[i + Δi] = src[i]
1085+
else
1086+
_unsetindex!(dest, i + Δi)
1087+
end
10841088
end
10851089
else
10861090
# Dual-index implementation
10871091
i = idf - 1
1088-
@inbounds for a in src
1089-
dest[i+=1] = a
1092+
@inbounds for a in eachindex(src)
1093+
i += 1
1094+
if isassigned(src, a)
1095+
dest[i] = src[a]
1096+
else
1097+
_unsetindex!(dest, i)
1098+
end
10901099
end
10911100
end
10921101
else
10931102
iterdest, itersrc = eachindex(dest), eachindex(src)
10941103
if iterdest == itersrc
10951104
# Shared-iterator implementation
10961105
for I in iterdest
1097-
@inbounds dest[I] = src[I]
1106+
if isassigned(src, I)
1107+
@inbounds dest[I] = src[I]
1108+
else
1109+
_unsetindex!(dest, I)
1110+
end
10981111
end
10991112
else
11001113
# Dual-iterator implementation
11011114
ret = iterate(iterdest)
1102-
@inbounds for a in src
1115+
@inbounds for a in itersrc
11031116
idx, state = ret::NTuple{2,Any}
1104-
dest[idx] = a
1117+
if isassigned(src, a)
1118+
dest[idx] = src[a]
1119+
else
1120+
_unsetindex!(dest, idx)
1121+
end
11051122
ret = iterate(iterdest, state)
11061123
end
11071124
end
@@ -1120,8 +1137,8 @@ function copyto!(dest::AbstractArray, dstart::Integer, src::AbstractArray, sstar
11201137
end
11211138

11221139
function copyto!(dest::AbstractArray, dstart::Integer,
1123-
src::AbstractArray, sstart::Integer,
1124-
n::Integer)
1140+
src::AbstractArray, sstart::Integer,
1141+
n::Integer)
11251142
n == 0 && return dest
11261143
n < 0 && throw(ArgumentError(LazyString("tried to copy n=",
11271144
n," elements, but n should be non-negative")))
@@ -1130,7 +1147,11 @@ function copyto!(dest::AbstractArray, dstart::Integer,
11301147
(checkbounds(Bool, srcinds, sstart) && checkbounds(Bool, srcinds, sstart+n-1)) || throw(BoundsError(src, sstart:sstart+n-1))
11311148
src′ = unalias(dest, src)
11321149
@inbounds for i = 0:n-1
1133-
dest[dstart+i] = src′[sstart+i]
1150+
if isassigned(src′, sstart+i)
1151+
dest[dstart+i] = src′[sstart+i]
1152+
else
1153+
_unsetindex!(dest, dstart+i)
1154+
end
11341155
end
11351156
return dest
11361157
end
@@ -1141,7 +1162,7 @@ function copy(a::AbstractArray)
11411162
end
11421163

11431164
function copyto!(B::AbstractVecOrMat{R}, ir_dest::AbstractRange{Int}, jr_dest::AbstractRange{Int},
1144-
A::AbstractVecOrMat{S}, ir_src::AbstractRange{Int}, jr_src::AbstractRange{Int}) where {R,S}
1165+
A::AbstractVecOrMat{S}, ir_src::AbstractRange{Int}, jr_src::AbstractRange{Int}) where {R,S}
11451166
if length(ir_dest) != length(ir_src)
11461167
throw(ArgumentError(LazyString("source and destination must have same size (got ",
11471168
length(ir_src)," and ",length(ir_dest),")")))
@@ -1229,10 +1250,10 @@ end
12291250
# note: the following type definitions don't mean any AbstractArray is convertible to
12301251
# a data Ref. they just map the array element type to the pointer type for
12311252
# convenience in cases that work.
1232-
pointer(x::AbstractArray{T}) where {T} = unsafe_convert(Ptr{T}, x)
1253+
pointer(x::AbstractArray{T}) where {T} = unsafe_convert(Ptr{T}, cconvert(Ptr{T}, x))
12331254
function pointer(x::AbstractArray{T}, i::Integer) where T
12341255
@inline
1235-
unsafe_convert(Ptr{T}, x) + Int(_memory_offset(x, i))::Int
1256+
pointer(x) + Int(_memory_offset(x, i))::Int
12361257
end
12371258

12381259
# The distance from pointer(x) to the element at x[I...] in bytes
@@ -1370,6 +1391,8 @@ _unsafe_ind2sub(sz, i) = (@inline; _ind2sub(sz, i))
13701391
Store values from array `X` within some subset of `A` as specified by `inds`.
13711392
The syntax `A[inds...] = X` is equivalent to `(setindex!(A, X, inds...); X)`.
13721393
1394+
$(_DOCS_ALIASING_WARNING)
1395+
13731396
# Examples
13741397
```jldoctest
13751398
julia> A = zeros(2,2);
@@ -1426,6 +1449,8 @@ function _setindex!(::IndexCartesian, A::AbstractArray, v, I::Vararg{Int,M}) whe
14261449
r
14271450
end
14281451

1452+
_unsetindex!(A::AbstractArray, i::Integer) = _unsetindex!(A, to_index(i))
1453+
14291454
"""
14301455
parent(A)
14311456
@@ -1531,7 +1556,8 @@ their component parts. A typical definition for an array that wraps a parent is
15311556
`Base.dataids(C::CustomArray) = dataids(C.parent)`.
15321557
"""
15331558
dataids(A::AbstractArray) = (UInt(objectid(A)),)
1534-
dataids(A::Array) = (UInt(pointer(A)),)
1559+
dataids(A::Memory) = (B = ccall(:jl_genericmemory_owner, Any, (Any,), A); (UInt(pointer(B isa typeof(A) ? B : A)),))
1560+
dataids(A::Array) = dataids(A.ref.mem)
15351561
dataids(::AbstractRange) = ()
15361562
dataids(x) = ()
15371563

@@ -3344,6 +3370,8 @@ end
33443370
Like [`map`](@ref), but stores the result in `destination` rather than a new
33453371
collection. `destination` must be at least as large as the smallest collection.
33463372
3373+
$(_DOCS_ALIASING_WARNING)
3374+
33473375
See also: [`map`](@ref), [`foreach`](@ref), [`zip`](@ref), [`copyto!`](@ref).
33483376
33493377
# Examples

0 commit comments

Comments
 (0)