Skip to content

Backports for julia 1.11.7 #59336

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 14 commits into
base: release-1.11
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
2 changes: 1 addition & 1 deletion base/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct JLOptions
commands::Ptr{Ptr{UInt8}} # (e)eval, (E)print, (L)load
image_file::Ptr{UInt8}
cpu_target::Ptr{UInt8}
nthreadpools::Int16
nthreadpools::Int8
nthreads::Int16
nmarkthreads::Int16
nsweepthreads::Int8
Expand Down
4 changes: 2 additions & 2 deletions base/precompilation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ Base.show(io::IO, err::PkgPrecompileError) = print(io, "PkgPrecompileError: ", e

import Base: StaleCacheKey

can_fancyprint(io::IO) = io isa Base.TTY && (get(ENV, "CI", nothing) != "true")
can_fancyprint(io::IO) = @something(get(io, :force_fancyprint, nothing), (io isa Base.TTY && (get(ENV, "CI", nothing) != "true")))

function printpkgstyle(io, header, msg; color=:light_green)
printstyled(io, header; color, bold=true)
Expand Down Expand Up @@ -892,7 +892,7 @@ function _precompilepkgs(pkgs::Vector{String},
flags, cacheflags = config
task = @async begin
try
loaded = haskey(Base.loaded_modules, pkg)
loaded = warn_loaded && haskey(Base.loaded_modules, pkg)
for dep in deps # wait for deps to finish
wait(was_processed[(dep,config)])
end
Expand Down
8 changes: 4 additions & 4 deletions base/reinterpretarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,13 @@ end
_maybe_reshape(::IndexSCartesian2, A::ReshapedReinterpretArray, I...) = A

# fallbacks
function _getindex(::IndexSCartesian2, A::AbstractArray{T,N}, I::Vararg{Int, N}) where {T,N}
function _getindex(::IndexSCartesian2, A::AbstractArray, I::Vararg{Int, N}) where {N}
@_propagate_inbounds_meta
getindex(A, I...)
_getindex(IndexCartesian(), A, I...)
end
function _setindex!(::IndexSCartesian2, A::AbstractArray{T,N}, v, I::Vararg{Int, N}) where {T,N}
function _setindex!(::IndexSCartesian2, A::AbstractArray, v, I::Vararg{Int, N}) where {N}
@_propagate_inbounds_meta
setindex!(A, v, I...)
_setindex!(IndexCartesian(), A, v, I...)
end
# fallbacks for array types that use "pass-through" indexing (e.g., `IndexStyle(A) = IndexStyle(parent(A))`)
# but which don't handle SCartesianIndex2
Expand Down
2 changes: 2 additions & 0 deletions base/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,8 @@ write(io::IO, s::CodeUnits) = write(io, s.s)
cconvert(::Type{Ptr{T}}, s::CodeUnits{T}) where {T} = cconvert(Ptr{T}, s.s)
cconvert(::Type{Ptr{Int8}}, s::CodeUnits{UInt8}) = cconvert(Ptr{Int8}, s.s)

similar(::Type{<:CodeUnits{T}}, dims::Dims) where {T} = similar(Array{T}, dims)

"""
codeunits(s::AbstractString)

Expand Down
9 changes: 8 additions & 1 deletion src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1395,10 +1395,17 @@ static void undef_var_error_ifnot(jl_codectx_t &ctx, Value *ok, jl_sym_t *name,
ctx.builder.SetInsertPoint(ifok);
}

// ctx.builder.CreateIsNotNull(v) lowers incorrectly in non-standard
// address spaces where null is not zero
// TODO: adapt to https://github.com/llvm/llvm-project/pull/131557 once merged
static Value *null_pointer_cmp(jl_codectx_t &ctx, Value *v)
{
++EmittedNullchecks;
return ctx.builder.CreateIsNotNull(v);
Type *T = v->getType();
return ctx.builder.CreateICmpNE(
v,
ctx.builder.CreateAddrSpaceCast(
Constant::getNullValue(ctx.builder.getPtrTy(0)), T));
}


Expand Down
4 changes: 3 additions & 1 deletion src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static int8_t jl_cachearg_offset(jl_methtable_t *mt)

static uint_t speccache_hash(size_t idx, jl_value_t *data)
{
jl_method_instance_t *ml = (jl_method_instance_t*)jl_svecref(data, idx);
jl_method_instance_t *ml = (jl_method_instance_t*)jl_svecref(data, idx); // This must always happen inside the lock
jl_value_t *sig = ml->specTypes;
if (jl_is_unionall(sig))
sig = jl_unwrap_unionall(sig);
Expand All @@ -122,6 +122,8 @@ static uint_t speccache_hash(size_t idx, jl_value_t *data)

static int speccache_eq(size_t idx, const void *ty, jl_value_t *data, uint_t hv)
{
if (idx >= jl_svec_len(data))
return 0; // We got a OOB access, probably due to a data race
jl_method_instance_t *ml = (jl_method_instance_t*)jl_svecref(data, idx);
jl_value_t *sig = ml->specTypes;
if (ty == sig)
Expand Down
2 changes: 1 addition & 1 deletion src/julia_atomics.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ T jl_atomic_exchange_explicit(std::atomic<T> *ptr, S desired, std::memory_order
{
return std::atomic_exchange_explicit<T>(ptr, desired, order);
}
#define jl_atomic_exchange_release(ptr, val) jl_atomic_exchange_explicit(ptr, val, memory_order_reease)
#define jl_atomic_exchange_release(ptr, val) jl_atomic_exchange_explicit(ptr, val, memory_order_release)
#define jl_atomic_exchange_relaxed(ptr, val) jl_atomic_exchange_explicit(ptr, val, memory_order_relaxed)
extern "C" {
#else
Expand Down
2 changes: 1 addition & 1 deletion src/llvm-late-gc-lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ void RecursivelyVisit(callback f, Value *V) {
if (isa<CallInst>(TheUser) || isa<LoadInst>(TheUser) ||
isa<SelectInst>(TheUser) || isa<PHINode>(TheUser) || // TODO: should these be removed from this list?
isa<StoreInst>(TheUser) || isa<PtrToIntInst>(TheUser) ||
isa<ICmpInst>(TheUser) || // ICmpEQ/ICmpNE can be used with ptr types
isa<ICmpInst>(TheUser) || isa<InsertElementInst>(TheUser)|| // ICmpEQ/ICmpNE can be used with ptr types
isa<AtomicCmpXchgInst>(TheUser) || isa<AtomicRMWInst>(TheUser))
continue;
if (isa<GetElementPtrInst>(TheUser) || isa<BitCastInst>(TheUser) || isa<AddrSpaceCastInst>(TheUser)) {
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Distributed.version
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DISTRIBUTED_BRANCH = master
DISTRIBUTED_BRANCH = release-julia-1.11
DISTRIBUTED_SHA1 = 6c7cdb5860fa5cb9ca191ce9c52a3d25a9ab3781
DISTRIBUTED_GIT_URL := https://github.com/JuliaLang/Distributed.jl
DISTRIBUTED_TAR_URL = https://api.github.com/repos/JuliaLang/Distributed.jl/tarball/$1
8 changes: 4 additions & 4 deletions stdlib/Mmap/src/Mmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,16 @@ like HDF5 (which can be used with memory-mapping).
"""
function mmap(io::IO,
::Type{Array{T,N}}=Vector{UInt8},
dims::NTuple{N,Integer}=(div(filesize(io)-position(io),sizeof(T)),),
dims::NTuple{N,Integer}=(div(filesize(io)-position(io),Base.aligned_sizeof(T)),),
offset::Integer=position(io); grow::Bool=true, shared::Bool=true) where {T,N}
# check inputs
isopen(io) || throw(ArgumentError("$io must be open to mmap"))
isbitstype(T) || throw(ArgumentError("unable to mmap $T; must satisfy isbitstype(T) == true"))

len = sizeof(T)
len = Base.aligned_sizeof(T)
for l in dims
len, overflow = Base.Checked.mul_with_overflow(promote(len, l)...)
overflow && throw(ArgumentError("requested size prod($((sizeof(T), dims...))) too large, would overflow typeof(size(T)) == $(typeof(len))"))
overflow && throw(ArgumentError("requested size prod($((len, dims...))) too large, would overflow typeof(size(T)) == $(typeof(len))"))
end
len >= 0 || throw(ArgumentError("requested size must be ≥ 0, got $len"))
len == 0 && return Array{T}(undef, ntuple(x->0,Val(N)))
Expand Down Expand Up @@ -272,7 +272,7 @@ end

mmap(file::AbstractString,
::Type{T}=Vector{UInt8},
dims::NTuple{N,Integer}=(div(filesize(file),sizeof(eltype(T))),),
dims::NTuple{N,Integer}=(div(filesize(file),Base.aligned_sizeof(eltype(T))),),
offset::Integer=Int64(0); grow::Bool=true, shared::Bool=true) where {T<:Array,N} =
open(io->mmap(io, T, dims, offset; grow=grow, shared=shared), file, isfile(file) ? "r" : "w+")::Array{eltype(T),N}

Expand Down
15 changes: 14 additions & 1 deletion stdlib/Mmap/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ s = open(file)
@test length(@inferred mmap(s, Vector{Int8}, 12, 0; grow=false)) == 12
@test length(@inferred mmap(s, Vector{Int8}, 12, 0; shared=false)) == 12
close(s)
@test_throws ErrorException mmap(file, Vector{Ref}) # must be bit-type
@test_throws ArgumentError mmap(file, Vector{Ref}) # must be bit-type
GC.gc(); GC.gc()

s = open(f->f,file,"w")
Expand Down Expand Up @@ -341,6 +341,19 @@ end
GC.gc()
rm(file)

@testset "test for #58982 - mmap with primitive types" begin
file = tempname()
primitive type PrimType9Bytes 9*8 end
arr = Vector{PrimType9Bytes}(undef, 2)
write(file, arr)
m = mmap(file, Vector{PrimType9Bytes})
@test length(m) == 2
@test m[1] == arr[1]
@test m[2] == arr[2]
finalize(m); m = nothing; GC.gc()
rm(file)
end

@testset "Docstrings" begin
@test isempty(Docs.undocumented_names(Mmap))
end
2 changes: 2 additions & 0 deletions stdlib/Unicode/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ end
@test_throws BoundsError graphemes("äöüx", 2:5)
@test_throws BoundsError graphemes("äöüx", 5:5)
@test_throws ArgumentError graphemes("äöüx", 0:1)

@test @allocated(length(graphemes("äöüx"))) == 0
end

@testset "#3721, #6939 up-to-date character widths" begin
Expand Down
20 changes: 20 additions & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,26 @@ generic_map_tests(map, map!)
# @test_throws BoundsError map!(+, ones(3), ones(2, 2), ones(2, 2))
end

@testset "#30624" begin
### unstructured
@test map!(+, ones(3), ones(3), ones(3), [1]) == [3, 1, 1]
@test map!(+, ones(3), [1], ones(3), ones(3)) == [3, 1, 1]
@test map!(+, [1], [1], [], []) == [1]
@test map!(+, [[1]], [1], [], []) == [[1]]

# TODO: decide if input axes & lengths should be validated
# @test_throws BoundsError map!(+, ones(1), ones(2))
# @test_throws BoundsError map!(+, ones(1), ones(2, 2))

@test map!(+, ones(3), view(ones(2, 3), 1:2, 2:3), ones(3)) == [2, 2, 2]
@test map!(+, ones(3), ones(2, 2), ones(3)) == [2, 2, 2]

### structured (all mapped arguments are <:AbstractArray equal ndims > 1)
@test map!(+, ones(4), ones(2, 2), ones(2, 2)) == [2, 2, 2, 2]
@test map!(+, ones(4), ones(2, 2), ones(1, 2)) == [2, 2, 1, 1]
# @test_throws BoundsError map!(+, ones(3), ones(2, 2), ones(2, 2))
end

test_UInt_indexing(TestAbstractArray)
test_13315(TestAbstractArray)
test_checksquare()
Expand Down
14 changes: 14 additions & 0 deletions test/llvmpasses/late-lower-gc.ll
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,20 @@ define void @decayar([2 x {} addrspace(10)* addrspace(11)*] %ar) {
; OPAQUE: %r = call i32 @callee_root(ptr addrspace(10) %l0, ptr addrspace(10) %l1)
; OPAQUE: call void @julia.pop_gc_frame(ptr %gcframe)

define swiftcc ptr addrspace(10) @insert_element(ptr swiftself %0) {
; CHECK-LABEL: @insert_element
%2 = alloca [10 x i64], i32 1, align 8
; CHECK: %gcframe = call ptr @julia.new_gc_frame(i32 10)
; CHECK: [[gc_slot_addr_:%.*]] = call ptr @julia.get_gc_frame_slot(ptr %gcframe, i32 0)
; CHECK: call void @julia.push_gc_frame(ptr %gcframe, i32 10)
call void null(ptr sret([2 x [5 x ptr addrspace(10)]]) %2, ptr null, ptr addrspace(11) null, ptr null)
%4 = insertelement <4 x ptr> zeroinitializer, ptr %2, i32 0
; CHECK: [[gc_slot_addr_:%.*]] = insertelement <4 x ptr> zeroinitializer, ptr [[gc_slot_addr_:%.*]], i32 0
; CHECK: call void @julia.pop_gc_frame(ptr %gcframe)
ret ptr addrspace(10) null
}


!0 = !{i64 0, i64 23}
!1 = !{!1}
!2 = !{!7} ; scope list
Expand Down
5 changes: 4 additions & 1 deletion test/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,10 @@ precompile_test_harness(false) do dir
error("the \"break me\" test failed")
catch exc
isa(exc, ErrorException) || rethrow()
occursin("ERROR: LoadError: break me", exc.msg) && rethrow()
# The LoadError shouldn't be surfaced but is printed to stderr, hence the `@test_warn` capture tests
occursin("LoadError: break me", exc.msg) && rethrow()
# The actual error that is thrown
occursin("Failed to precompile FooBar2", exc.msg) || rethrow()
end

# Test that trying to eval into closed modules during precompilation is an error
Expand Down
23 changes: 23 additions & 0 deletions test/reinterpretarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,23 @@ test_many_wrappers(fill(1.0, 5, 3), (identity, wrapper)) do a_
@test r[goodinds...] == -5
end
end

let a = rand(ComplexF32, 5)
r = reinterpret(reshape, Float32, a)
ref = Array(r)

@test r[1, :, 1] == ref[1, :]
@test r[1, :, 1, 1, 1] == ref[1, :]
@test r[1, :, UInt8(1)] == ref[1, :]

r[2, :, 1] .= 0f0
ref[2, :] .= 0f0
@test r[2, :, 1] == ref[2, :]

@test r[4] == ref[4]
@test_throws BoundsError r[1, :, 2]
end

let ar = [(1,2), (3,4)]
arr = reinterpret(reshape, Int, ar)
@test @inferred(IndexStyle(arr)) == Base.IndexSCartesian2{2}()
Expand Down Expand Up @@ -607,3 +624,9 @@ let R = reinterpret(reshape, Float32, ComplexF32[1.0f0+2.0f0*im, 4.0f0+3.0f0*im]
@test !isassigned(R, 5)
@test Array(R)::Matrix{Float32} == [1.0f0 4.0f0; 2.0f0 3.0f0]
end

@testset "issue #54623" begin
x = 0xabcdef01234567
@test reinterpret(reshape, UInt8, fill(x)) == [0x67, 0x45, 0x23, 0x01, 0xef, 0xcd, 0xab, 0x00]
@test reinterpret(reshape, UInt8, [x]) == [0x67; 0x45; 0x23; 0x01; 0xef; 0xcd; 0xab; 0x00;;]
end
1 change: 1 addition & 0 deletions test/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,7 @@ let s = "∀x∃y", u = codeunits(s)
@test_throws Base.CanonicalIndexError (u[1] = 0x00)
@test collect(u) == b"∀x∃y"
@test Base.elsize(u) == Base.elsize(typeof(u)) == 1
@test similar(typeof(u), 3) isa Vector{UInt8}
end

# issue #24388
Expand Down