Skip to content

Commit cd3f239

Browse files
committed
Merge remote-tracking branch 'origin/master' into sb/test-scope
2 parents e083c75 + 4cdd864 commit cd3f239

23 files changed

+221
-117
lines changed

base/array.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ function fill!(a::Union{Array{UInt8}, Array{Int8}}, x::Integer)
415415
ref = a.ref
416416
t = @_gc_preserve_begin ref
417417
p = unsafe_convert(Ptr{Cvoid}, ref)
418-
memset(p, x isa eltype(a) ? x : convert(eltype(a), x), length(a))
418+
memset(p, x isa eltype(a) ? x : convert(eltype(a), x), length(a) % UInt)
419419
@_gc_preserve_end t
420420
return a
421421
end

base/deprecated.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ const All16{T,N} = Tuple{T,T,T,T,T,T,T,T,
432432

433433
# the plan is to eventually overload getproperty to access entries of the dict
434434
@noinline function getproperty(x::Pairs, s::Symbol)
435-
depwarn("use values(kwargs) and keys(kwargs) instead of kwargs.data and kwargs.itr", :getproperty, force=true)
435+
s == :data && depwarn("use values(kwargs) instead of kwargs.data", :getproperty, force=true)
436+
s == :itr && depwarn("use keys(kwargs) instead of kwargs.itr", :getproperty, force=true)
436437
return getfield(x, s)
437438
end
438439

base/div.jl

+15
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@ julia> div(4, 3, RoundFromZero)
4343
julia> div(-4, 3, RoundFromZero)
4444
-2
4545
```
46+
Because `div(x, y)` implements strictly correct truncated rounding based on the true
47+
value of floating-point numbers, unintuitive situations can arise. For example:
48+
```jldoctest
49+
julia> div(6.0, 0.1)
50+
59.0
51+
julia> 6.0 / 0.1
52+
60.0
53+
julia> 6.0 / big(0.1)
54+
59.99999999999999666933092612453056361837965690217069245739573412231113406246995
55+
```
56+
What is happening here is that the true value of the floating-point number written
57+
as `0.1` is slightly larger than the numerical value 1/10 while `6.0` represents
58+
the number 6 precisely. Therefore the true value of `6.0 / 0.1` is slightly less
59+
than 60. When doing division, this is rounded to precisely `60.0`, but
60+
`div(6.0, 0.1, RoundToZero)` always truncates the true value, so the result is `59.0`.
4661
"""
4762
div(x, y, r::RoundingMode)
4863

base/genericmemory.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ function fill!(a::Union{Memory{UInt8}, Memory{Int8}}, x::Integer)
190190
t = @_gc_preserve_begin a
191191
p = unsafe_convert(Ptr{Cvoid}, a)
192192
T = eltype(a)
193-
memset(p, x isa T ? x : convert(T, x), length(a))
193+
memset(p, x isa T ? x : convert(T, x), length(a) % UInt)
194194
@_gc_preserve_end t
195195
return a
196196
end

base/iddict.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function empty!(d::IdDict)
126126
d.ht = Memory{Any}(undef, 32)
127127
ht = d.ht
128128
t = @_gc_preserve_begin ht
129-
memset(unsafe_convert(Ptr{Cvoid}, ht), 0, sizeof(ht))
129+
memset(unsafe_convert(Ptr{Cvoid}, ht), 0, sizeof(ht) % UInt)
130130
@_gc_preserve_end t
131131
d.ndel = 0
132132
d.count = 0

base/loading.jl

+42-1
Original file line numberDiff line numberDiff line change
@@ -2397,12 +2397,13 @@ const module_keys = IdDict{Module,PkgId}() # the reverse of loaded_modules
23972397
root_module_key(m::Module) = @lock require_lock module_keys[m]
23982398

23992399
function maybe_loaded_precompile(key::PkgId, buildid::UInt128)
2400-
assert_havelock(require_lock)
2400+
@lock require_lock begin
24012401
mods = get(loaded_precompiles, key, nothing)
24022402
mods === nothing && return
24032403
for mod in mods
24042404
module_build_id(mod) == buildid && return mod
24052405
end
2406+
end
24062407
end
24072408

24082409
function module_build_id(m::Module)
@@ -2610,6 +2611,46 @@ function _require_from_serialized(uuidkey::PkgId, path::String, ocachepath::Unio
26102611
end
26112612

26122613
# load a serialized file directly from append_bundled_depot_path for uuidkey without stalechecks
2614+
"""
2615+
require_stdlib(package_uuidkey::PkgId, ext::Union{Nothing, String}=nothing)
2616+
2617+
!!! warning "May load duplicate copies of stdlib packages."
2618+
2619+
This requires that all stdlib packages loaded are compatible with having concurrent
2620+
copies of themselves loaded into memory. It also places additional restrictions on
2621+
the kinds of type-piracy that are allowed in stdlibs, since type-piracy can cause the
2622+
dispatch table to become visibly "torn" across multiple different packages.
2623+
2624+
The specific requirements are:
2625+
2626+
The import side (caller of `require_stdlib`) must not leak any stdlib types, esp.
2627+
to any context that may have a conflicting copy of the stdlib(s) (or vice-versa).
2628+
- e.g., if an output is forwarded to user code, it must contain only Base types.
2629+
- e.g., if an output contains types from the stdlib, it must be consumed "internally"
2630+
before reaching user code.
2631+
2632+
The imported code (loaded stdlibs) must be very careful about type piracy:
2633+
- It must not access any global state that may differ between stdlib copies in
2634+
type-pirated methods.
2635+
- It must not return any stdlib types from any type-pirated public methods (since
2636+
a loaded duplicate would overwrite the Base method again, returning different
2637+
types that don't correspond to the user-accessible copy of the stdlib).
2638+
- It must not pass / discriminate stdlib types in type-pirated methods, except
2639+
indirectly via methods defined in Base and implemented (w/o type-piracy) in
2640+
all copies of the stdlib over their respective types.
2641+
2642+
The idea behind the above restrictions is that any type-pirated methods in the stdlib
2643+
must return a result that is simultaneously correct for all of the stdlib's loaded
2644+
copies, including accounting for global state differences and split type identities.
2645+
2646+
Furthermore, any imported code must not leak any stdlib types to globals and containers
2647+
(e.g. Vectors and mutable structs) in upstream Modules, since this will also lead to
2648+
type-confusion when the type is later pulled out in user / stdlib code.
2649+
2650+
For examples of issues like the above, see:
2651+
[1] https://github.com/JuliaLang/Pkg.jl/issues/4017#issuecomment-2377589989
2652+
[2] https://github.com/JuliaLang/StyledStrings.jl/issues/91#issuecomment-2379602914
2653+
"""
26132654
function require_stdlib(package_uuidkey::PkgId, ext::Union{Nothing, String}=nothing)
26142655
@lock require_lock begin
26152656
# the PkgId of the ext, or package if not an ext

base/math.jl

+3-5
Original file line numberDiff line numberDiff line change
@@ -1276,14 +1276,12 @@ end
12761276
return ifelse(isfinite(x) & isfinite(err), muladd(x, y, err), x*y)
12771277
end
12781278

1279-
function ^(x::Float32, n::Integer)
1279+
function ^(x::Union{Float16,Float32}, n::Integer)
12801280
n == -2 && return (i=inv(x); i*i)
12811281
n == 3 && return x*x*x #keep compatibility with literal_pow
1282-
n < 0 && return Float32(Base.power_by_squaring(inv(Float64(x)),-n))
1283-
Float32(Base.power_by_squaring(Float64(x),n))
1282+
n < 0 && return oftype(x, Base.power_by_squaring(inv(widen(x)),-n))
1283+
oftype(x, Base.power_by_squaring(widen(x),n))
12841284
end
1285-
@inline ^(x::Float16, y::Integer) = Float16(Float32(x) ^ y)
1286-
@inline literal_pow(::typeof(^), x::Float16, ::Val{p}) where {p} = Float16(literal_pow(^,Float32(x),Val(p)))
12871285

12881286
## rem2pi-related calculations ##
12891287

base/range.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ end
14851485
"""
14861486
mod(x::Integer, r::AbstractUnitRange)
14871487
1488-
Find `y` in the range `r` such that ``xy (\\mod n)``, where `n = length(r)`,
1488+
Find `y` in the range `r` such that `x``y` (mod `n`), where `n = length(r)`,
14891489
i.e. `y = mod(x - first(r), n) + first(r)`.
14901490
14911491
See also [`mod1`](@ref).

base/scopedvalues.jl

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ struct Scope
8585
values::ScopeStorage
8686
end
8787

88+
Scope(scope::Scope) = scope
89+
8890
function Scope(parent::Union{Nothing, Scope}, key::ScopedValue{T}, value) where T
8991
val = convert(T, value)
9092
if parent === nothing

base/strings/string.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -570,9 +570,10 @@ julia> repeat('A', 3)
570570
```
571571
"""
572572
function repeat(c::AbstractChar, r::Integer)
573+
r < 0 && throw(ArgumentError("can't repeat a character $r times"))
574+
r = UInt(r)::UInt
573575
c = Char(c)::Char
574576
r == 0 && return ""
575-
r < 0 && throw(ArgumentError("can't repeat a character $r times"))
576577
u = bswap(reinterpret(UInt32, c))
577578
n = 4 - (leading_zeros(u | 0xff) >> 3)
578579
s = _string_n(n*r)

base/strings/substring.jl

+1
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ end
272272

273273
function repeat(s::Union{String, SubString{String}}, r::Integer)
274274
r < 0 && throw(ArgumentError("can't repeat a string $r times"))
275+
r = UInt(r)::UInt
275276
r == 0 && return ""
276277
r == 1 && return String(s)
277278
n = sizeof(s)

doc/src/devdocs/build/distributing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Alternatively, Julia may be built as a framework by invoking `make` with the
108108
Windows
109109
-------
110110

111-
Instructions for reating a Julia distribution on Windows are described in the
111+
Instructions for creating a Julia distribution on Windows are described in the
112112
[build devdocs for Windows](https://github.com/JuliaLang/julia/blob/master/doc/src/devdocs/build/windows.md).
113113

114114
Notes on BLAS and LAPACK

doc/src/devdocs/gc.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ lists. Metadata for free pages, however, may be stored into three separate lock-
2121

2222
Julia's pool allocator follows a "tiered" allocation discipline. When requesting a memory page for the pool allocator, Julia will:
2323

24-
- Try to claim a page from `page_pool_lazily_freed`, which contains pages which were empty on the last stop-the-world phase, but not yet madivsed by a concurrent sweeper GC thread.
24+
- Try to claim a page from `page_pool_lazily_freed`, which contains pages which were empty on the last stop-the-world phase, but not yet madvised by a concurrent sweeper GC thread.
2525

2626
- If it failed claiming a page from `page_pool_lazily_freed`, it will try to claim a page from `the page_pool_clean`, which contains pages which were mmaped on a previous page allocation request but never accessed.
2727

doc/src/devdocs/llvm.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The code for lowering Julia AST to LLVM IR or interpreting it directly is in dir
1717
| `cgutils.cpp` | Lowering utilities, notably for array and tuple accesses |
1818
| `codegen.cpp` | Top-level of code generation, pass list, lowering builtins |
1919
| `debuginfo.cpp` | Tracks debug information for JIT code |
20-
| `disasm.cpp` | Handles native object file and JIT code diassembly |
20+
| `disasm.cpp` | Handles native object file and JIT code disassembly |
2121
| `gf.c` | Generic functions |
2222
| `intrinsics.cpp` | Lowering intrinsics |
2323
| `jitlayers.cpp` | JIT-specific code, ORC compilation layers/utilities |

doc/src/manual/environment-variables.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ files, artifacts, etc. For example, to switch the user depot to `/foo/bar` just
144144
```sh
145145
export JULIA_DEPOT_PATH="/foo/bar:"
146146
```
147-
All package operations, like cloning registrise or installing packages, will now write to
147+
All package operations, like cloning registries or installing packages, will now write to
148148
`/foo/bar`, but since the empty entry is expanded to the default system depot, any bundled
149149
resources will still be available. If you really only want to use the depot at `/foo/bar`,
150150
and not load any bundled resources, simply set the environment variable to `/foo/bar`

stdlib/InteractiveUtils/test/runtests.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,9 @@ if Sys.ARCH === :x86_64 || occursin(ix86, string(Sys.ARCH))
547547
output = replace(String(take!(buf)), r"#[^\r\n]+" => "")
548548
@test !occursin(rgx, output)
549549

550-
code_native(buf, linear_foo, ())
551-
output = String(take!(buf))
552-
@test occursin(rgx, output)
550+
code_native(buf, linear_foo, (), debuginfo = :none)
551+
output = replace(String(take!(buf)), r"#[^\r\n]+" => "")
552+
@test !occursin(rgx, output)
553553

554554
@testset "binary" begin
555555
# check the RET instruction (opcode: C3)

stdlib/LinearAlgebra/src/LinearAlgebra.jl

+6-23
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ public AbstractTriangular,
174174
isbanded,
175175
peakflops,
176176
symmetric,
177-
symmetric_type
177+
symmetric_type,
178+
matprod_dest
178179

179180
const BlasFloat = Union{Float64,Float32,ComplexF64,ComplexF32}
180181
const BlasReal = Union{Float64,Float32}
@@ -394,17 +395,8 @@ julia> Y = zero(X);
394395
395396
julia> ldiv!(Y, qr(A), X);
396397
397-
julia> Y
398-
3-element Vector{Float64}:
399-
0.7128099173553719
400-
-0.051652892561983674
401-
0.10020661157024757
402-
403-
julia> A\\X
404-
3-element Vector{Float64}:
405-
0.7128099173553719
406-
-0.05165289256198333
407-
0.10020661157024785
398+
julia> Y ≈ A\\X
399+
true
408400
```
409401
"""
410402
ldiv!(Y, A, B)
@@ -435,17 +427,8 @@ julia> Y = copy(X);
435427
436428
julia> ldiv!(qr(A), X);
437429
438-
julia> X
439-
3-element Vector{Float64}:
440-
0.7128099173553719
441-
-0.051652892561983674
442-
0.10020661157024757
443-
444-
julia> A\\Y
445-
3-element Vector{Float64}:
446-
0.7128099173553719
447-
-0.05165289256198333
448-
0.10020661157024785
430+
julia> X ≈ A\\Y
431+
true
449432
```
450433
"""
451434
ldiv!(A, B)

stdlib/LinearAlgebra/src/hessenberg.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ This is useful because multiple shifted solves `(F + μ*I) \\ b`
446446
Iterating the decomposition produces the factors `F.Q, F.H, F.μ`.
447447
448448
# Examples
449-
```jldoctest
449+
```julia-repl
450450
julia> A = [4. 9. 7.; 4. 4. 1.; 4. 3. 2.]
451451
3×3 Matrix{Float64}:
452452
4.0 9.0 7.0

stdlib/LinearAlgebra/src/matmul.jl

+9-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,15 @@ function (*)(A::AbstractMatrix, B::AbstractMatrix)
123123
mul!(matprod_dest(A, B, TS), A, B)
124124
end
125125

126-
matprod_dest(A, B, TS) = similar(B, TS, (size(A, 1), size(B, 2)))
126+
"""
127+
matprod_dest(A, B, T)
128+
129+
Return an appropriate `AbstractArray` with element type `T` that may be used to store the result of `A * B`.
130+
131+
!!! compat
132+
This function requires at least Julia 1.11
133+
"""
134+
matprod_dest(A, B, T) = similar(B, T, (size(A, 1), size(B, 2)))
127135

128136
# optimization for dispatching to BLAS, e.g. *(::Matrix{Float32}, ::Matrix{Float64})
129137
# but avoiding the case *(::Matrix{<:BlasComplex}, ::Matrix{<:BlasReal})

0 commit comments

Comments
 (0)