Skip to content

Commit 3f2c5a3

Browse files
authored
Merge pull request #50090 from JuliaLang/backports-release-1.9
Backports for 1.9.2
2 parents 13751df + 01a5a7c commit 3f2c5a3

Some content is hidden

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

51 files changed

+739
-241
lines changed

base/Enums.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ Base.cconvert(::Type{T}, x::Enum{T2}) where {T<:Integer,T2<:Integer} = T(x)::T
2121
Base.write(io::IO, x::Enum{T}) where {T<:Integer} = write(io, T(x))
2222
Base.read(io::IO, ::Type{T}) where {T<:Enum} = T(read(io, basetype(T)))
2323

24+
"""
25+
_enum_hash(x::Enum, h::UInt)
26+
27+
Compute hash for an enum value `x`. This internal method will be specialized
28+
for every enum type created through [`@enum`](@ref).
29+
"""
30+
_enum_hash(x::Enum, h::UInt) = invoke(hash, Tuple{Any, UInt}, x, h)
31+
Base.hash(x::Enum, h::UInt) = _enum_hash(x, h)
2432
Base.isless(x::T, y::T) where {T<:Enum} = isless(basetype(T)(x), basetype(T)(y))
2533

2634
Base.Symbol(x::Enum) = namemap(typeof(x))[Integer(x)]::Symbol
@@ -206,8 +214,12 @@ macro enum(T::Union{Symbol,Expr}, syms...)
206214
Enums.namemap(::Type{$(esc(typename))}) = $(esc(namemap))
207215
Base.typemin(x::Type{$(esc(typename))}) = $(esc(typename))($lo)
208216
Base.typemax(x::Type{$(esc(typename))}) = $(esc(typename))($hi)
209-
let enum_hash = hash($(esc(typename)))
210-
Base.hash(x::$(esc(typename)), h::UInt) = hash(enum_hash, hash(Integer(x), h))
217+
let type_hash = hash($(esc(typename)))
218+
# Use internal `_enum_hash` to allow users to specialize
219+
# `Base.hash` for their own enum types without overwriting the
220+
# method we would define here. This avoids a warning for
221+
# precompilation.
222+
Enums._enum_hash(x::$(esc(typename)), h::UInt) = hash(type_hash, hash(Integer(x), h))
211223
end
212224
let insts = (Any[ $(esc(typename))(v) for v in $values ]...,)
213225
Base.instances(::Type{$(esc(typename))}) = insts

base/compiler/abstractinterpretation.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,11 +2441,9 @@ function abstract_eval_globalref(interp::AbstractInterpreter, g::GlobalRef, fram
24412441
nothrow = false
24422442
if isa(rt, Const)
24432443
consistent = ALWAYS_TRUE
2444+
nothrow = true
24442445
if is_mutation_free_argtype(rt)
24452446
inaccessiblememonly = ALWAYS_TRUE
2446-
nothrow = true
2447-
else
2448-
nothrow = true
24492447
end
24502448
elseif isdefined_globalref(g)
24512449
nothrow = true

base/compiler/ssair/inlining.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ function compute_inlining_cases(@nospecialize(info::CallInfo), flag::UInt8, sig:
14011401
fully_covered &= split_fully_covered
14021402
end
14031403

1404-
joint_effects = Effects(joint_effects; nothrow=fully_covered)
1404+
fully_covered || (joint_effects = Effects(joint_effects; nothrow=false))
14051405

14061406
if handled_all_cases && revisit_idx !== nothing
14071407
# we handled everything except one match with unmatched sparams,

base/compiler/tfuncs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ function apply_type_nothrow(@specialize(lattice::AbstractLattice), argtypes::Vec
14881488
end
14891489
else
14901490
istype || return false
1491-
if !(T <: u.var.ub)
1491+
if isa(u.var.ub, TypeVar) || !(T <: u.var.ub)
14921492
return false
14931493
end
14941494
if exact ? !(u.var.lb <: T) : !(u.var.lb === Bottom)

base/compiler/typeinfer.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,9 @@ end
367367
function transform_result_for_cache(interp::AbstractInterpreter,
368368
linfo::MethodInstance, valid_worlds::WorldRange, result::InferenceResult)
369369
inferred_result = result.src
370-
# If we decided not to optimize, drop the OptimizationState now.
371-
# External interpreters can override as necessary to cache additional information
372370
if inferred_result isa OptimizationState{typeof(interp)}
373-
inferred_result = ir_to_codeinf!(inferred_result)
371+
# TODO respect must_be_codeinf setting here?
372+
result.src = inferred_result = ir_to_codeinf!(inferred_result)
374373
end
375374
if inferred_result isa CodeInfo
376375
inferred_result.min_world = first(valid_worlds)

base/expr.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,7 @@ end
925925
@atomic order ex
926926
927927
Mark `var` or `ex` as being performed atomically, if `ex` is a supported expression.
928+
If no `order` is specified it defaults to :sequentially_consistent.
928929
929930
@atomic a.b.x = new
930931
@atomic a.b.x += addend

base/gmp.jl

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -808,8 +808,8 @@ Base.deepcopy_internal(x::BigInt, stackdict::IdDict) = get!(() -> MPZ.set(x), st
808808

809809
## streamlined hashing for BigInt, by avoiding allocation from shifts ##
810810

811-
if Limb === UInt
812-
# this condition is true most (all?) of the time, and in this case we can define
811+
if Limb === UInt64 === UInt
812+
# On 64 bit systems we can define
813813
# an optimized version for BigInt of hash_integer (used e.g. for Rational{BigInt}),
814814
# and of hash
815815

@@ -819,7 +819,7 @@ if Limb === UInt
819819
GC.@preserve n begin
820820
s = n.size
821821
s == 0 && return hash_integer(0, h)
822-
p = convert(Ptr{UInt}, n.d)
822+
p = convert(Ptr{UInt64}, n.d)
823823
b = unsafe_load(p)
824824
h ⊻= hash_uint(ifelse(s < 0, -b, b) h)
825825
for k = 2:abs(s)
@@ -829,14 +829,11 @@ if Limb === UInt
829829
end
830830
end
831831

832-
_divLimb(n) = UInt === UInt64 ? n >>> 6 : n >>> 5
833-
_modLimb(n) = UInt === UInt64 ? n & 63 : n & 31
834-
835832
function hash(x::BigInt, h::UInt)
836833
GC.@preserve x begin
837834
sz = x.size
838835
sz == 0 && return hash(0, h)
839-
ptr = Ptr{UInt}(x.d)
836+
ptr = Ptr{UInt64}(x.d)
840837
if sz == 1
841838
return hash(unsafe_load(ptr), h)
842839
elseif sz == -1
@@ -845,8 +842,8 @@ if Limb === UInt
845842
end
846843
pow = trailing_zeros(x)
847844
nd = Base.ndigits0z(x, 2)
848-
idx = _divLimb(pow) + 1
849-
shift = _modLimb(pow) % UInt
845+
idx = (pow >>> 6) + 1
846+
shift = (pow & 63) % UInt
850847
upshift = BITS_PER_LIMB - shift
851848
asz = abs(sz)
852849
if shift == 0

base/initdefs.jl

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ const atexit_hooks = Callable[
354354
() -> Filesystem.temp_cleanup_purge(force=true)
355355
]
356356
const _atexit_hooks_lock = ReentrantLock()
357+
global _atexit_hooks_finished::Bool = false
357358

358359
"""
359360
atexit(f)
@@ -374,12 +375,40 @@ exit code `n` (instead of the original exit code). If more than one exit hook
374375
calls `exit(n)`, then Julia will exit with the exit code corresponding to the
375376
last called exit hook that calls `exit(n)`. (Because exit hooks are called in
376377
LIFO order, "last called" is equivalent to "first registered".)
378+
379+
Note: Once all exit hooks have been called, no more exit hooks can be registered,
380+
and any call to `atexit(f)` after all hooks have completed will throw an exception.
381+
This situation may occur if you are registering exit hooks from background Tasks that
382+
may still be executing concurrently during shutdown.
377383
"""
378-
atexit(f::Function) = Base.@lock _atexit_hooks_lock (pushfirst!(atexit_hooks, f); nothing)
384+
function atexit(f::Function)
385+
Base.@lock _atexit_hooks_lock begin
386+
_atexit_hooks_finished && error("cannot register new atexit hook; already exiting.")
387+
pushfirst!(atexit_hooks, f)
388+
return nothing
389+
end
390+
end
379391

380392
function _atexit(exitcode::Cint)
381-
while !isempty(atexit_hooks)
382-
f = popfirst!(atexit_hooks)
393+
# Don't hold the lock around the iteration, just in case any other thread executing in
394+
# parallel tries to register a new atexit hook while this is running. We don't want to
395+
# block that thread from proceeding, and we can allow it to register its hook which we
396+
# will immediately run here.
397+
while true
398+
local f
399+
Base.@lock _atexit_hooks_lock begin
400+
# If this is the last iteration, atomically disable atexit hooks to prevent
401+
# someone from registering a hook that will never be run.
402+
# (We do this inside the loop, so that it is atomic: no one can have registered
403+
# a hook that never gets run, and we run all the hooks we know about until
404+
# the vector is empty.)
405+
if isempty(atexit_hooks)
406+
global _atexit_hooks_finished = true
407+
break
408+
end
409+
410+
f = popfirst!(atexit_hooks)
411+
end
383412
try
384413
if hasmethod(f, (Cint,))
385414
f(exitcode)

base/loading.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1810,7 +1810,7 @@ function _require(pkg::PkgId, env=nothing)
18101810
else
18111811
@warn "The call to compilecache failed to create a usable precompiled cache file for $pkg" exception=m
18121812
end
1813-
# fall-through to loading the file locally
1813+
# fall-through to loading the file locally if not incremental
18141814
else
18151815
cachefile, ocachefile = cachefile::Tuple{String, Union{Nothing, String}}
18161816
m = _tryrequire_from_serialized(pkg, cachefile, ocachefile)
@@ -1820,6 +1820,10 @@ function _require(pkg::PkgId, env=nothing)
18201820
return m
18211821
end
18221822
end
1823+
if JLOptions().incremental != 0
1824+
# during incremental precompilation, this should be fail-fast
1825+
throw(PrecompilableError())
1826+
end
18231827
end
18241828
end
18251829

base/options.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct JLOptions
5353
rr_detach::Int8
5454
strip_metadata::Int8
5555
strip_ir::Int8
56+
permalloc_pkgimg::Int8
5657
heap_size_hint::UInt64
5758
end
5859

0 commit comments

Comments
 (0)