Skip to content

Backports for 1.12 #57444

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

Merged
merged 16 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
7be953f
bpart: Skip implicit import reval if using'd export set is unchanged …
Keno Feb 15, 2025
5aec07f
generated: Switch resolution module back to what it was before (#57419)
Keno Feb 15, 2025
51fa787
Prohibit binding replacement in closed modules during precompile (#57…
Keno Feb 16, 2025
1c9d39d
Prohibit `import`ing or `using` Main during incremental compilation (…
Keno Feb 16, 2025
5e3f967
bpart: Track whether any binding replacement has happened in image mo…
Keno Feb 17, 2025
5518d11
Update LinearAlgebra.version: redirect to the `release-1.12` branch
dkarrasch Feb 20, 2025
83e99fe
Add explicit imports for types and fix bugs (#57302)
Keno Feb 7, 2025
9cfb24a
Run all `--sysimage-native-code=no` cmdlineargs tests single-threaded…
IanButterworth Feb 18, 2025
3c58c10
Only strip invariant.load from special pointers (#57386)
vchuravy Feb 18, 2025
94d7417
Revert "Make emitted egal code more loopy (#54121)" (#57453)
vtjnash Feb 19, 2025
015c535
Change memory indexing to use the type as index instead of i8 (#57389)
gbaraldi Feb 19, 2025
9095265
using/import: ensure world update after each observable operation (#5…
vtjnash Feb 19, 2025
9579515
staticdata: Don't use `newm` pointer after it has been invalidated (#…
topolarity Feb 20, 2025
84c3fd7
lowering: Don't mutate lambda in `linearize` (#57416)
mlechu Feb 20, 2025
c78016e
Don't return null pointer when asking for the type of a declared glob…
Keno Feb 18, 2025
bf42463
bump LinearAlgebra to latest v1.12
KristofferC Feb 25, 2025
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 Compiler/src/Compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ using Base.Order

import Base: ==, _topmod, append!, convert, copy, copy!, findall, first, get, get!,
getindex, haskey, in, isempty, isready, iterate, iterate, last, length, max_world,
min_world, popfirst!, push!, resize!, setindex!, size
min_world, popfirst!, push!, resize!, setindex!, size, intersect

const getproperty = Core.getfield
const setproperty! = Core.setfield!
Expand Down
51 changes: 0 additions & 51 deletions Compiler/test/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -889,57 +889,6 @@ ex54166 = Union{Missing, Int64}[missing -2; missing -2];
dims54166 = (1,2)
@test (minimum(ex54166; dims=dims54166)[1] === missing)

# #54109 - Excessive LLVM time for egal
struct DefaultOr54109{T}
x::T
default::Bool
end

@eval struct Torture1_54109
$((Expr(:(::), Symbol("x$i"), DefaultOr54109{Float64}) for i = 1:897)...)
end
Torture1_54109() = Torture1_54109((DefaultOr54109(1.0, false) for i = 1:897)...)

@eval struct Torture2_54109
$((Expr(:(::), Symbol("x$i"), DefaultOr54109{Float64}) for i = 1:400)...)
$((Expr(:(::), Symbol("x$(i+400)"), DefaultOr54109{Int16}) for i = 1:400)...)
end
Torture2_54109() = Torture2_54109((DefaultOr54109(1.0, false) for i = 1:400)..., (DefaultOr54109(Int16(1), false) for i = 1:400)...)

@noinline egal_any54109(x, @nospecialize(y::Any)) = x === Base.compilerbarrier(:type, y)

let ir1 = get_llvm(egal_any54109, Tuple{Torture1_54109, Any}),
ir2 = get_llvm(egal_any54109, Tuple{Torture2_54109, Any})

# We can't really do timing on CI, so instead, let's look at the length of
# the optimized IR. The original version had tens of thousands of lines and
# was slower, so just check here that we only have < 500 lines. If somebody,
# implements a better comparison that's larger than that, just re-benchmark
# this and adjust the threshold.

@test count(==('\n'), ir1) < 500
@test count(==('\n'), ir2) < 500
end

## Regression test for egal of a struct of this size without padding, but with
## non-bitsegal, to make sure that it doesn't accidentally go down the accelerated
## path.
@eval struct BigStructAnyInt
$((Expr(:(::), Symbol("x$i"), Pair{Any, Int}) for i = 1:33)...)
end
BigStructAnyInt() = BigStructAnyInt((Union{Base.inferencebarrier(Float64), Int}=>i for i = 1:33)...)
@test egal_any54109(BigStructAnyInt(), BigStructAnyInt())

## For completeness, also test correctness, since we don't have a lot of
## large-struct tests.

# The two allocations of the same struct will likely have different padding,
# we want to make sure we find them egal anyway - a naive memcmp would
# accidentally look at it.
@test egal_any54109(Torture1_54109(), Torture1_54109())
@test egal_any54109(Torture2_54109(), Torture2_54109())
@test !egal_any54109(Torture1_54109(), Torture1_54109((DefaultOr54109(2.0, false) for i = 1:897)...))

bar54599() = Base.inferencebarrier(true) ? (Base.PkgId(Main),1) : nothing

function foo54599()
Expand Down
1 change: 1 addition & 0 deletions base/Base_compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ function cld end
function fld end

# Lazy strings
import Core: String
include("strings/lazy.jl")

# array structures
Expand Down
2 changes: 2 additions & 0 deletions base/bool.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

import Core: Bool

# promote Bool to any other numeric type
promote_rule(::Type{Bool}, ::Type{T}) where {T<:Number} = T

Expand Down
2 changes: 2 additions & 0 deletions base/char.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

import Core: AbstractChar, Char

"""
The `AbstractChar` type is the supertype of all character implementations
in Julia. A character represents a Unicode code point, and can be converted
Expand Down
8 changes: 6 additions & 2 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ function exec_options(opts)
distributed_mode = (opts.worker == 1) || (opts.nprocs > 0) || (opts.machine_file != C_NULL)
if distributed_mode
let Distributed = require(PkgId(UUID((0x8ba89e20_285c_5b6f, 0x9357_94700520ee1b)), "Distributed"))
Core.eval(MainInclude, :(const Distributed = $Distributed))
MainInclude.Distributed = Distributed
Core.eval(Main, :(using Base.MainInclude.Distributed))
invokelatest(Distributed.process_opts, opts)
end
Expand Down Expand Up @@ -400,7 +400,7 @@ function load_InteractiveUtils(mod::Module=Main)
try
# TODO: we have to use require_stdlib here because it is a dependency of REPL, but we would sort of prefer not to
let InteractiveUtils = require_stdlib(PkgId(UUID(0xb77e0a4c_d291_57a0_90e8_8db25a27a240), "InteractiveUtils"))
Core.eval(MainInclude, :(const InteractiveUtils = $InteractiveUtils))
MainInclude.InteractiveUtils = InteractiveUtils
end
catch ex
@warn "Failed to import InteractiveUtils into module $mod" exception=(ex, catch_backtrace())
Expand Down Expand Up @@ -535,6 +535,10 @@ The thrown errors are collected in a stack of exceptions.
"""
global err = nothing

# Used for memoizing require_stdlib of these modules
global InteractiveUtils::Module
global Distributed::Module

# weakly exposes ans and err variables to Main
export ans, err
end
Expand Down
2 changes: 1 addition & 1 deletion base/coreir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ while processing a call, then `Conditional` everywhere else.
"""
Core.InterConditional

InterConditional(var::SlotNumber, @nospecialize(thentype), @nospecialize(elsetype)) =
Core.InterConditional(var::SlotNumber, @nospecialize(thentype), @nospecialize(elsetype)) =
InterConditional(slot_id(var), thentype, elsetype)
1 change: 1 addition & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ end
@deprecate one(i::CartesianIndex) oneunit(i)
@deprecate one(I::Type{CartesianIndex{N}}) where {N} oneunit(I)

import .MPFR: BigFloat
@deprecate BigFloat(x, prec::Int) BigFloat(x; precision=prec)
@deprecate BigFloat(x, prec::Int, rounding::RoundingMode) BigFloat(x, rounding; precision=prec)
@deprecate BigFloat(x::Real, prec::Int) BigFloat(x; precision=prec)
Expand Down
2 changes: 1 addition & 1 deletion base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,6 @@ function (g::Core.GeneratedFunctionStub)(world::UInt, source::Method, @nospecial
Expr(:meta, :pop_loc))))
spnames = g.spnames
return generated_body_to_codeinfo(spnames === Core.svec() ? lam : Expr(Symbol("with-static-parameters"), lam, spnames...),
typename(typeof(g.gen)).module,
source.module,
source.isva)
end
6 changes: 3 additions & 3 deletions base/filesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ export File,
S_IROTH, S_IWOTH, S_IXOTH, S_IRWXO

import .Base:
IOError, _UVError, _sizeof_uv_fs, check_open, close, eof, eventloop, fd, isopen,
bytesavailable, position, read, read!, readavailable, seek, seekend, show,
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,
setup_stdio, rawhandle, OS_HANDLE, INVALID_OS_HANDLE, windowserror, filesize,
isexecutable, isreadable, iswritable, MutableDenseArrayType
isexecutable, isreadable, iswritable, MutableDenseArrayType, truncate

import .Base.RefValue

Expand Down
3 changes: 3 additions & 0 deletions base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

const IEEEFloat = Union{Float16, Float32, Float64}

import Core: Float16, Float32, Float64, AbstractFloat
import Core: Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128

## floating point traits ##

"""
Expand Down
2 changes: 2 additions & 0 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import .Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), xor,
sign, hastypemax, isodd, iseven, digits!, hash, hash_integer, top_set_bit,
clamp, unsafe_takestring

import Core: Signed, Float16, Float32, Float64

if Clong == Int32
const ClongMax = Union{Int8, Int16, Int32}
const CulongMax = Union{UInt8, UInt16, UInt32}
Expand Down
10 changes: 5 additions & 5 deletions base/hamt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,19 @@ or grows the HAMT by inserting a new trie instead.
end
end

length(::Leaf) = 1
length(trie::HAMT) = sum((length(trie.data[i]) for i in eachindex(trie.data)), init=0)
Base.length(::Leaf) = 1
Base.length(trie::HAMT) = sum((length(trie.data[i]) for i in eachindex(trie.data)), init=0)

isempty(::Leaf) = false
function isempty(trie::HAMT)
Base.isempty(::Leaf) = false
function Base.isempty(trie::HAMT)
if islevel_empty(trie)
return true
end
return all(isempty(trie.data[i]) for i in eachindex(trie.data))
end

# DFS
function iterate(trie::HAMT, state=nothing)
function Base.iterate(trie::HAMT, state=nothing)
if state === nothing
state = (;parent=nothing, trie, i=1)
end
Expand Down
18 changes: 13 additions & 5 deletions base/invalidation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,26 +180,34 @@
b.partitions.min_world > unsafe_load(cglobal(:jl_require_world, UInt))
end

function scan_new_method!(methods_with_invalidated_source::IdSet{Method}, method::Method)
function scan_new_method!(methods_with_invalidated_source::IdSet{Method}, method::Method, image_backedges_only::Bool)
isdefined(method, :source) || return
if image_backedges_only && !has_image_globalref(method)
return
end
src = _uncompressed_ir(method)
mod = method.module
foreachgr(src) do gr::GlobalRef
b = convert(Core.Binding, gr)
binding_was_invalidated(b) && push!(methods_with_invalidated_source, method)
if binding_was_invalidated(b)
# TODO: We could turn this into an addition if condition. For now, use it as a reasonably cheap
# additional consistency chekc

Check warning on line 194 in base/invalidation.jl

View workflow job for this annotation

GitHub Actions / Check for new typos

perhaps "chekc" should be "check".
@assert !image_backedges_only
push!(methods_with_invalidated_source, method)
end
maybe_add_binding_backedge!(b, method)
end
end

function scan_new_methods(extext_methods::Vector{Any}, internal_methods::Vector{Any})
function scan_new_methods(extext_methods::Vector{Any}, internal_methods::Vector{Any}, image_backedges_only::Bool)
methods_with_invalidated_source = IdSet{Method}()
for method in internal_methods
if isa(method, Method)
scan_new_method!(methods_with_invalidated_source, method)
scan_new_method!(methods_with_invalidated_source, method, image_backedges_only)
end
end
for tme::Core.TypeMapEntry in extext_methods
scan_new_method!(methods_with_invalidated_source, tme.func::Method)
scan_new_method!(methods_with_invalidated_source, tme.func::Method, image_backedges_only)
end
return methods_with_invalidated_source
end
5 changes: 4 additions & 1 deletion base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ import
sinpi, cospi, sincospi, tanpi, sind, cosd, tand, asind, acosd, atand,
uinttype, exponent_max, exponent_min, ieee754_representation, significand_mask

import .Core: AbstractFloat
import .Base: Rational, Float16, Float32, Float64, Bool

using .Base.Libc
import ..Rounding: Rounding,
rounding_raw, setrounding_raw, rounds_to_nearest, rounds_away_from_zero,
tie_breaker_is_to_even, correct_rounding_requires_increment

import ..GMP: ClongMax, CulongMax, CdoubleMax, Limb, libgmp
import ..GMP: ClongMax, CulongMax, CdoubleMax, Limb, libgmp, BigInt

import ..FastMath.sincos_fast

Expand Down
4 changes: 3 additions & 1 deletion base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
module IteratorsMD
import .Base: eltype, length, size, first, last, in, getindex, setindex!,
min, max, zero, oneunit, isless, eachindex,
convert, show, iterate, promote_rule, to_indices, copy
convert, show, iterate, promote_rule, to_indices, copy,
isassigned

import .Base: +, -, *, (:)
import .Base: simd_outer_range, simd_inner_length, simd_index, setindex
import Core: Tuple
using .Base: to_index, fill_to_length, tail, safe_tail
using .Base: IndexLinear, IndexCartesian, AbstractCartesianIndex,
ReshapedArray, ReshapedArrayLF, OneTo, Fix1
Expand Down
2 changes: 2 additions & 0 deletions base/namedtuple.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

import Core: NamedTuple

"""
NamedTuple

Expand Down
2 changes: 2 additions & 0 deletions base/refpointer.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

import Core: Ref

"""
Ref{T}

Expand Down
2 changes: 2 additions & 0 deletions base/runtime_internals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1656,3 +1656,5 @@ isempty(mt::Core.MethodTable) = (mt.defs === nothing)
uncompressed_ir(m::Method) = isdefined(m, :source) ? _uncompressed_ir(m) :
isdefined(m, :generator) ? error("Method is @generated; try `code_lowered` instead.") :
error("Code for this Method is not available.")

has_image_globalref(m::Method) = ccall(:jl_ir_flag_has_image_globalref, Bool, (Any,), m.source)
3 changes: 2 additions & 1 deletion base/staticdata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ end
function insert_backedges(edges::Vector{Any}, ext_ci_list::Union{Nothing,Vector{Any}}, extext_methods::Vector{Any}, internal_methods::Vector{Any})
# determine which CodeInstance objects are still valid in our image
# to enable any applicable new codes
methods_with_invalidated_source = Base.scan_new_methods(extext_methods, internal_methods)
backedges_only = unsafe_load(cglobal(:jl_first_image_replacement_world, UInt)) == typemax(UInt)
methods_with_invalidated_source = Base.scan_new_methods(extext_methods, internal_methods, backedges_only)
stack = CodeInstance[]
visiting = IdDict{CodeInstance,Int}()
_insert_backedges(edges, stack, visiting, methods_with_invalidated_source)
Expand Down
2 changes: 2 additions & 0 deletions base/strings/basic.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

import Core: Symbol

"""
The `AbstractString` type is the supertype of all string implementations in
Julia. Strings are encodings of sequences of [Unicode](https://unicode.org/)
Expand Down
2 changes: 2 additions & 0 deletions base/tuple.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

import Core: Tuple

# Document NTuple here where we have everything needed for the doc system
"""
NTuple{N, T}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5b6db0a9e4e75f998b63ef9b3f62005c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b1bd5744395f692c5902c7074a4e7d3a9cfd7b1905bccdf72b77602ab10d3c1b9a8eb45eac358442da3afc1d26f2e4f4d56f40a0465a70e1d962f0a6a259657e
7 changes: 3 additions & 4 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4710,10 +4710,9 @@ static jl_cgval_t emit_memoryref(jl_codectx_t &ctx, const jl_cgval_t &ref, jl_cg
setName(ctx.emission_context, ovflw, "memoryref_ovflw");
}
#endif
boffset = ctx.builder.CreateMul(offset, elsz);
setName(ctx.emission_context, boffset, "memoryref_byteoffset");
newdata = ctx.builder.CreateGEP(getInt8Ty(ctx.builder.getContext()), data, boffset);
setName(ctx.emission_context, newdata, "memoryref_data_byteoffset");
Type *elty = isboxed ? ctx.types().T_prjlvalue : julia_type_to_llvm(ctx, jl_tparam1(ref.typ));
newdata = ctx.builder.CreateGEP(elty, data, offset);
setName(ctx.emission_context, newdata, "memoryref_data_offset");
(void)boffset; // LLVM is very bad at handling GEP with types different from the load
if (bc) {
BasicBlock *failBB, *endBB;
Expand Down
Loading