Skip to content

Backports for 1.12.0-beta2 #58270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: release-1.12
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Compiler/src/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,10 @@ end
return Const(true)
end
end
# datatype_fieldcount is what `fieldcount` uses internally
# and returns nothing (!==0) for non-definite field counts.
elseif datatype_fieldcount(a1) === 0
return Const(false)
end
elseif isa(a1, Union)
# Results can only be `Const` or `Bool`
Expand Down
1 change: 1 addition & 0 deletions Compiler/test/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,7 @@ let isdefined_tfunc(@nospecialize xs...) =
@test isdefined_tfunc(Union{UnionIsdefinedA,UnionIsdefinedB}, Const(:x)) === Const(true)
@test isdefined_tfunc(Union{UnionIsdefinedA,UnionIsdefinedB}, Const(:y)) === Const(false)
@test isdefined_tfunc(Union{UnionIsdefinedA,Nothing}, Const(:x)) === Bool
@test isdefined_tfunc(Nothing, Any) === Const(false)
end

# https://github.com/aviatesk/JET.jl/issues/379
Expand Down
55 changes: 32 additions & 23 deletions base/accumulate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
# it does double the number of operations compared to accumulate,
# though for cheap operations like + this does not have much impact (20%)
function _accumulate_pairwise!(op::Op, c::AbstractVector{T}, v::AbstractVector, s, i1, n)::T where {T,Op}
@inbounds if n < 128
s_ = v[i1]
c[i1] = op(s, s_)
if n < 128
@inbounds s_ = v[i1]
ci1 = op(s, s_)
@inbounds c[i1] = ci1
for i = i1+1:i1+n-1
s_ = op(s_, v[i])
c[i] = op(s, s_)
s_ = op(s_, @inbounds(v[i]))
ci = op(s, s_)
@inbounds c[i] = ci
end
else
n2 = n >> 1
Expand All @@ -26,7 +28,8 @@ function accumulate_pairwise!(op::Op, result::AbstractVector, v::AbstractVector)
n = length(li)
n == 0 && return result
i1 = first(li)
@inbounds result[i1] = v1 = reduce_first(op,v[i1])
v1 = reduce_first(op, @inbounds(v[i1]))
@inbounds result[i1] = v1
n == 1 && return result
_accumulate_pairwise!(op, result, v, v1, i1+1, n-1)
return result
Expand Down Expand Up @@ -378,16 +381,16 @@ function _accumulate!(op, B, A, dims::Integer, init::Union{Nothing, Some})
# We can accumulate to a temporary variable, which allows
# register usage and will be slightly faster
ind1 = inds_t[1]
@inbounds for I in CartesianIndices(tail(inds_t))
for I in CartesianIndices(tail(inds_t))
if init === nothing
tmp = reduce_first(op, A[first(ind1), I])
tmp = reduce_first(op, @inbounds(A[first(ind1), I]))
else
tmp = op(something(init), A[first(ind1), I])
tmp = op(something(init), @inbounds(A[first(ind1), I]))
end
B[first(ind1), I] = tmp
@inbounds B[first(ind1), I] = tmp
for i_1 = first(ind1)+1:last(ind1)
tmp = op(tmp, A[i_1, I])
B[i_1, I] = tmp
tmp = op(tmp, @inbounds(A[i_1, I]))
@inbounds B[i_1, I] = tmp
end
end
else
Expand All @@ -401,25 +404,31 @@ end
@noinline function _accumulaten!(op, B, A, R1, ind, R2, init::Nothing)
# Copy the initial element in each 1d vector along dimension `dim`
ii = first(ind)
@inbounds for J in R2, I in R1
B[I, ii, J] = reduce_first(op, A[I, ii, J])
for J in R2, I in R1
tmp = reduce_first(op, @inbounds(A[I, ii, J]))
@inbounds B[I, ii, J] = tmp
end
# Accumulate
@inbounds for J in R2, i in first(ind)+1:last(ind), I in R1
B[I, i, J] = op(B[I, i-1, J], A[I, i, J])
for J in R2, i in first(ind)+1:last(ind), I in R1
@inbounds Bv, Av = B[I, i-1, J], A[I, i, J]
tmp = op(Bv, Av)
@inbounds B[I, i, J] = tmp
end
B
end

@noinline function _accumulaten!(op, B, A, R1, ind, R2, init::Some)
# Copy the initial element in each 1d vector along dimension `dim`
ii = first(ind)
@inbounds for J in R2, I in R1
B[I, ii, J] = op(something(init), A[I, ii, J])
for J in R2, I in R1
tmp = op(something(init), @inbounds(A[I, ii, J]))
@inbounds B[I, ii, J] = tmp
end
# Accumulate
@inbounds for J in R2, i in first(ind)+1:last(ind), I in R1
B[I, i, J] = op(B[I, i-1, J], A[I, i, J])
for J in R2, i in first(ind)+1:last(ind), I in R1
@inbounds Bv, Av = B[I, i-1, J], A[I, i, J]
tmp = op(Bv, Av)
@inbounds B[I, i, J] = tmp
end
B
end
Expand All @@ -433,10 +442,10 @@ function _accumulate1!(op, B, v1, A::AbstractVector, dim::Integer)
cur_val = v1
B[i1] = cur_val
next = iterate(inds, state)
@inbounds while next !== nothing
while next !== nothing
(i, state) = next
cur_val = op(cur_val, A[i])
B[i] = cur_val
cur_val = op(cur_val, @inbounds(A[i]))
@inbounds B[i] = cur_val
next = iterate(inds, state)
end
return B
Expand Down
2 changes: 2 additions & 0 deletions base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,8 @@ function UndefVarError_hint(io::IO, ex::UndefVarError)
print(io, "\nSuggestion: check for spelling errors or missing imports.")
elseif Base.is_some_explicit_imported(kind)
print(io, "\nSuggestion: this global was defined as `$(Base.partition_restriction(bpart).globalref)` but not assigned a value.")
elseif kind === Base.PARTITION_KIND_BACKDATED_CONST
print(io, "\nSuggestion: define the const at top-level before running function that uses it (stricter Julia v1.12+ rule).")
end
elseif scope === :static_parameter
print(io, "\nSuggestion: run Test.detect_unbound_args to detect method arguments that do not fully constrain a type parameter.")
Expand Down
2 changes: 1 addition & 1 deletion base/filesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export File,
import .Base:
IOError, _UVError, _sizeof_uv_fs, check_open, close, closewrite, eof, eventloop, fd, isopen,
bytesavailable, position, read, read!, readbytes!, readavailable, seek, seekend, show,
skip, stat, unsafe_read, unsafe_write, write, transcode, uv_error,
skip, stat, unsafe_read, unsafe_write, write, transcode, uv_error, _uv_error,
setup_stdio, rawhandle, OS_HANDLE, INVALID_OS_HANDLE, windowserror, filesize,
isexecutable, isreadable, iswritable, MutableDenseArrayType, truncate

Expand Down
3 changes: 2 additions & 1 deletion base/libuv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ struverror(err::Int32) = unsafe_string(ccall(:uv_strerror, Cstring, (Int32,), er
uverrorname(err::Int32) = unsafe_string(ccall(:uv_err_name, Cstring, (Int32,), err))

uv_error(prefix::Symbol, c::Integer) = uv_error(string(prefix), c)
uv_error(prefix::AbstractString, c::Integer) = c < 0 ? throw(_UVError(prefix, c)) : nothing
uv_error(prefix::AbstractString, c::Integer) = c < 0 ? _uv_error(prefix, c) : nothing
_uv_error(prefix::AbstractString, c::Integer) = throw(_UVError(prefix, c))

## event loop ##

Expand Down
2 changes: 1 addition & 1 deletion base/runtime_internals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ function datatype_fieldcount(t::DataType)
return length(names)
end
if types isa DataType && types <: Tuple
return fieldcount(types)
return datatype_fieldcount(types)
end
return nothing
elseif isabstracttype(t)
Expand Down
3 changes: 2 additions & 1 deletion base/stat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ show(io::IO, ::MIME"text/plain", st::StatStruct) = show_statstruct(io, st, false

# stat & lstat functions

checkstat(s::StatStruct) = Int(s.ioerrno) in (0, Base.UV_ENOENT, Base.UV_ENOTDIR, Base.UV_EINVAL) ? s : uv_error(string("stat(", repr(s.desc), ")"), s.ioerrno)
checkstat(s::StatStruct) = Int(s.ioerrno) in (0, Base.UV_ENOENT, Base.UV_ENOTDIR, Base.UV_EINVAL) ? s :
_uv_error(string("stat(", repr(s.desc), ")"), s.ioerrno)

macro stat_call(sym, arg1type, arg)
return quote
Expand Down
3 changes: 2 additions & 1 deletion base/staticdata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function verify_method(codeinst::CodeInstance, stack::Vector{CodeInstance}, visi
edge = get_ci_mi(edge)
end
if edge isa MethodInstance
sig = typeintersect((edge.def::Method).sig, edge.specTypes) # TODO??
sig = edge.specTypes
min_valid2, max_valid2, matches = verify_call(sig, callees, j, 1, world)
j += 1
elseif edge isa Int
Expand Down Expand Up @@ -346,6 +346,7 @@ function verify_invokesig(@nospecialize(invokesig), expected::Method, world::UIn
matched = nothing
if invokesig === expected.sig
# the invoke match is `expected` for `expected->sig`, unless `expected` is invalid
# TODO: this is broken since PR #53415
minworld = expected.primary_world
maxworld = expected.deleted_world
@assert minworld ≤ world
Expand Down
52 changes: 38 additions & 14 deletions base/timing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,35 @@ function gc_bytes()
b[]
end

function allocated(f, args::Vararg{Any,N}) where {N}
b0 = Ref{Int64}(0)
b1 = Ref{Int64}(0)
Base.gc_bytes(b0)
f(args...)
Base.gc_bytes(b1)
return b1[] - b0[]
end
only(methods(allocated)).called = 0xff

function allocations(f, args::Vararg{Any,N}) where {N}
stats = Base.gc_num()
f(args...)
diff = Base.GC_Diff(Base.gc_num(), stats)
return Base.gc_alloc_count(diff)
end
only(methods(allocations)).called = 0xff

function is_simply_call(@nospecialize ex)
Meta.isexpr(ex, :call) || return false
for a in ex.args
a isa QuoteNode && continue
a isa Symbol && continue
Base.is_self_quoting(a) && continue
return false
end
return true
end

"""
@allocated

Expand All @@ -487,15 +516,11 @@ julia> @allocated rand(10^6)
```
"""
macro allocated(ex)
quote
Experimental.@force_compile
local b0 = Ref{Int64}(0)
local b1 = Ref{Int64}(0)
gc_bytes(b0)
$(esc(ex))
gc_bytes(b1)
b1[] - b0[]
if !is_simply_call(ex)
ex = :((() -> $ex)())
end
pushfirst!(ex.args, GlobalRef(Base, :allocated))
return esc(ex)
end

"""
Expand All @@ -516,15 +541,14 @@ julia> @allocations rand(10^6)
This macro was added in Julia 1.9.
"""
macro allocations(ex)
quote
Experimental.@force_compile
local stats = Base.gc_num()
$(esc(ex))
local diff = Base.GC_Diff(Base.gc_num(), stats)
Base.gc_alloc_count(diff)
if !is_simply_call(ex)
ex = :((() -> $ex)())
end
pushfirst!(ex.args, GlobalRef(Base, :allocations))
return esc(ex)
end


"""
@lock_conflicts

Expand Down
1 change: 0 additions & 1 deletion deps/checksums/cacert-2024-12-31.pem/md5

This file was deleted.

1 change: 0 additions & 1 deletion deps/checksums/cacert-2024-12-31.pem/sha512

This file was deleted.

1 change: 1 addition & 0 deletions deps/checksums/cacert-2025-02-25.pem/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1a7de82bb9f0fcc779ca18a7a9310898
1 change: 1 addition & 0 deletions deps/checksums/cacert-2025-02-25.pem/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e5fe41820460e6b65e8cd463d1a5f01b7103e1ef66cb75fedc15ebcba3ba6600d77e5e7c2ab94cbb1f11c63b688026a04422bbe2d7a861f7a988f67522ffae3c
Loading