Skip to content

Commit 49263b7

Browse files
authored
Backports for 1.12 (#57444)
Backported PRs: - [x] #57302 <!-- Add explicit imports for types and fix bugs --> - [x] #57420 <!-- Compiler: Fix check for IRShow definedness --> - [x] #57419 <!-- generated: Switch resolution module back to what it was before --> - [x] #57421 <!-- bpart: Skip implicit import reval if using'd export set is unchanged --> - [x] #57425 <!-- Prohibit binding replacement in closed modules during precompile --> - [x] #57426 <!-- Prohibit `import`ing or `using` Main during incremental compilation --> - [x] #57433 <!-- bpart: Track whether any binding replacement has happened in image modules --> - [x] #57445 <!-- Run all `--sysimage-native-code=no` cmdlineargs tests single-threaded --> - [x] #57386 <!-- Only strip invariant.load from special pointers --> - [x] #57453 <!-- Revert "Make emitted egal code more loopy (#54121)" --> - [x] #57389 <!-- Change memory indexing to use the type as index instead of i8 --> - [x] #57447 <!-- Don't return null pointer when asking for the type of a declared global --> - [x] #57467 <!-- using/import: ensure world update after each observable operation --> - [x] #57471 <!-- staticdata: Don't use `newm` pointer after it has been invalidated --> - [x] #57416 <!-- lowering: Don't mutate lambda in `linearize` -->
2 parents b0c5f61 + bf42463 commit 49263b7

Some content is hidden

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

49 files changed

+448
-327
lines changed

Compiler/src/Compiler.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ using Base.Order
7272

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

7777
const getproperty = Core.getfield
7878
const setproperty! = Core.setfield!

Compiler/test/codegen.jl

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -889,57 +889,6 @@ ex54166 = Union{Missing, Int64}[missing -2; missing -2];
889889
dims54166 = (1,2)
890890
@test (minimum(ex54166; dims=dims54166)[1] === missing)
891891

892-
# #54109 - Excessive LLVM time for egal
893-
struct DefaultOr54109{T}
894-
x::T
895-
default::Bool
896-
end
897-
898-
@eval struct Torture1_54109
899-
$((Expr(:(::), Symbol("x$i"), DefaultOr54109{Float64}) for i = 1:897)...)
900-
end
901-
Torture1_54109() = Torture1_54109((DefaultOr54109(1.0, false) for i = 1:897)...)
902-
903-
@eval struct Torture2_54109
904-
$((Expr(:(::), Symbol("x$i"), DefaultOr54109{Float64}) for i = 1:400)...)
905-
$((Expr(:(::), Symbol("x$(i+400)"), DefaultOr54109{Int16}) for i = 1:400)...)
906-
end
907-
Torture2_54109() = Torture2_54109((DefaultOr54109(1.0, false) for i = 1:400)..., (DefaultOr54109(Int16(1), false) for i = 1:400)...)
908-
909-
@noinline egal_any54109(x, @nospecialize(y::Any)) = x === Base.compilerbarrier(:type, y)
910-
911-
let ir1 = get_llvm(egal_any54109, Tuple{Torture1_54109, Any}),
912-
ir2 = get_llvm(egal_any54109, Tuple{Torture2_54109, Any})
913-
914-
# We can't really do timing on CI, so instead, let's look at the length of
915-
# the optimized IR. The original version had tens of thousands of lines and
916-
# was slower, so just check here that we only have < 500 lines. If somebody,
917-
# implements a better comparison that's larger than that, just re-benchmark
918-
# this and adjust the threshold.
919-
920-
@test count(==('\n'), ir1) < 500
921-
@test count(==('\n'), ir2) < 500
922-
end
923-
924-
## Regression test for egal of a struct of this size without padding, but with
925-
## non-bitsegal, to make sure that it doesn't accidentally go down the accelerated
926-
## path.
927-
@eval struct BigStructAnyInt
928-
$((Expr(:(::), Symbol("x$i"), Pair{Any, Int}) for i = 1:33)...)
929-
end
930-
BigStructAnyInt() = BigStructAnyInt((Union{Base.inferencebarrier(Float64), Int}=>i for i = 1:33)...)
931-
@test egal_any54109(BigStructAnyInt(), BigStructAnyInt())
932-
933-
## For completeness, also test correctness, since we don't have a lot of
934-
## large-struct tests.
935-
936-
# The two allocations of the same struct will likely have different padding,
937-
# we want to make sure we find them egal anyway - a naive memcmp would
938-
# accidentally look at it.
939-
@test egal_any54109(Torture1_54109(), Torture1_54109())
940-
@test egal_any54109(Torture2_54109(), Torture2_54109())
941-
@test !egal_any54109(Torture1_54109(), Torture1_54109((DefaultOr54109(2.0, false) for i = 1:897)...))
942-
943892
bar54599() = Base.inferencebarrier(true) ? (Base.PkgId(Main),1) : nothing
944893

945894
function foo54599()

base/Base_compiler.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ function cld end
227227
function fld end
228228

229229
# Lazy strings
230+
import Core: String
230231
include("strings/lazy.jl")
231232

232233
# array structures

base/bool.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3+
import Core: Bool
4+
35
# promote Bool to any other numeric type
46
promote_rule(::Type{Bool}, ::Type{T}) where {T<:Number} = T
57

base/char.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3+
import Core: AbstractChar, Char
4+
35
"""
46
The `AbstractChar` type is the supertype of all character implementations
57
in Julia. A character represents a Unicode code point, and can be converted

base/client.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ function exec_options(opts)
265265
distributed_mode = (opts.worker == 1) || (opts.nprocs > 0) || (opts.machine_file != C_NULL)
266266
if distributed_mode
267267
let Distributed = require(PkgId(UUID((0x8ba89e20_285c_5b6f, 0x9357_94700520ee1b)), "Distributed"))
268-
Core.eval(MainInclude, :(const Distributed = $Distributed))
268+
MainInclude.Distributed = Distributed
269269
Core.eval(Main, :(using Base.MainInclude.Distributed))
270270
invokelatest(Distributed.process_opts, opts)
271271
end
@@ -400,7 +400,7 @@ function load_InteractiveUtils(mod::Module=Main)
400400
try
401401
# TODO: we have to use require_stdlib here because it is a dependency of REPL, but we would sort of prefer not to
402402
let InteractiveUtils = require_stdlib(PkgId(UUID(0xb77e0a4c_d291_57a0_90e8_8db25a27a240), "InteractiveUtils"))
403-
Core.eval(MainInclude, :(const InteractiveUtils = $InteractiveUtils))
403+
MainInclude.InteractiveUtils = InteractiveUtils
404404
end
405405
catch ex
406406
@warn "Failed to import InteractiveUtils into module $mod" exception=(ex, catch_backtrace())
@@ -535,6 +535,10 @@ The thrown errors are collected in a stack of exceptions.
535535
"""
536536
global err = nothing
537537

538+
# Used for memoizing require_stdlib of these modules
539+
global InteractiveUtils::Module
540+
global Distributed::Module
541+
538542
# weakly exposes ans and err variables to Main
539543
export ans, err
540544
end

base/coreir.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ while processing a call, then `Conditional` everywhere else.
4949
"""
5050
Core.InterConditional
5151

52-
InterConditional(var::SlotNumber, @nospecialize(thentype), @nospecialize(elsetype)) =
52+
Core.InterConditional(var::SlotNumber, @nospecialize(thentype), @nospecialize(elsetype)) =
5353
InterConditional(slot_id(var), thentype, elsetype)

base/deprecated.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ end
353353
@deprecate one(i::CartesianIndex) oneunit(i)
354354
@deprecate one(I::Type{CartesianIndex{N}}) where {N} oneunit(I)
355355

356+
import .MPFR: BigFloat
356357
@deprecate BigFloat(x, prec::Int) BigFloat(x; precision=prec)
357358
@deprecate BigFloat(x, prec::Int, rounding::RoundingMode) BigFloat(x, rounding; precision=prec)
358359
@deprecate BigFloat(x::Real, prec::Int) BigFloat(x; precision=prec)

base/expr.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,6 @@ function (g::Core.GeneratedFunctionStub)(world::UInt, source::Method, @nospecial
16941694
Expr(:meta, :pop_loc))))
16951695
spnames = g.spnames
16961696
return generated_body_to_codeinfo(spnames === Core.svec() ? lam : Expr(Symbol("with-static-parameters"), lam, spnames...),
1697-
typename(typeof(g.gen)).module,
1697+
source.module,
16981698
source.isva)
16991699
end

base/filesystem.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ export File,
137137
S_IROTH, S_IWOTH, S_IXOTH, S_IRWXO
138138

139139
import .Base:
140-
IOError, _UVError, _sizeof_uv_fs, check_open, close, eof, eventloop, fd, isopen,
141-
bytesavailable, position, read, read!, readavailable, seek, seekend, show,
140+
IOError, _UVError, _sizeof_uv_fs, check_open, close, closewrite, eof, eventloop, fd, isopen,
141+
bytesavailable, position, read, read!, readbytes!, readavailable, seek, seekend, show,
142142
skip, stat, unsafe_read, unsafe_write, write, transcode, uv_error,
143143
setup_stdio, rawhandle, OS_HANDLE, INVALID_OS_HANDLE, windowserror, filesize,
144-
isexecutable, isreadable, iswritable, MutableDenseArrayType
144+
isexecutable, isreadable, iswritable, MutableDenseArrayType, truncate
145145

146146
import .Base.RefValue
147147

base/float.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
const IEEEFloat = Union{Float16, Float32, Float64}
44

5+
import Core: Float16, Float32, Float64, AbstractFloat
6+
import Core: Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128
7+
58
## floating point traits ##
69

710
"""

base/gmp.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import .Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), xor,
1313
sign, hastypemax, isodd, iseven, digits!, hash, hash_integer, top_set_bit,
1414
clamp, unsafe_takestring
1515

16+
import Core: Signed, Float16, Float32, Float64
17+
1618
if Clong == Int32
1719
const ClongMax = Union{Int8, Int16, Int32}
1820
const CulongMax = Union{UInt8, UInt16, UInt32}

base/hamt.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,19 +239,19 @@ or grows the HAMT by inserting a new trie instead.
239239
end
240240
end
241241

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

245-
isempty(::Leaf) = false
246-
function isempty(trie::HAMT)
245+
Base.isempty(::Leaf) = false
246+
function Base.isempty(trie::HAMT)
247247
if islevel_empty(trie)
248248
return true
249249
end
250250
return all(isempty(trie.data[i]) for i in eachindex(trie.data))
251251
end
252252

253253
# DFS
254-
function iterate(trie::HAMT, state=nothing)
254+
function Base.iterate(trie::HAMT, state=nothing)
255255
if state === nothing
256256
state = (;parent=nothing, trie, i=1)
257257
end

base/invalidation.jl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,26 +180,34 @@ function binding_was_invalidated(b::Core.Binding)
180180
b.partitions.min_world > unsafe_load(cglobal(:jl_require_world, UInt))
181181
end
182182

183-
function scan_new_method!(methods_with_invalidated_source::IdSet{Method}, method::Method)
183+
function scan_new_method!(methods_with_invalidated_source::IdSet{Method}, method::Method, image_backedges_only::Bool)
184184
isdefined(method, :source) || return
185+
if image_backedges_only && !has_image_globalref(method)
186+
return
187+
end
185188
src = _uncompressed_ir(method)
186189
mod = method.module
187190
foreachgr(src) do gr::GlobalRef
188191
b = convert(Core.Binding, gr)
189-
binding_was_invalidated(b) && push!(methods_with_invalidated_source, method)
192+
if binding_was_invalidated(b)
193+
# TODO: We could turn this into an addition if condition. For now, use it as a reasonably cheap
194+
# additional consistency chekc
195+
@assert !image_backedges_only
196+
push!(methods_with_invalidated_source, method)
197+
end
190198
maybe_add_binding_backedge!(b, method)
191199
end
192200
end
193201

194-
function scan_new_methods(extext_methods::Vector{Any}, internal_methods::Vector{Any})
202+
function scan_new_methods(extext_methods::Vector{Any}, internal_methods::Vector{Any}, image_backedges_only::Bool)
195203
methods_with_invalidated_source = IdSet{Method}()
196204
for method in internal_methods
197205
if isa(method, Method)
198-
scan_new_method!(methods_with_invalidated_source, method)
206+
scan_new_method!(methods_with_invalidated_source, method, image_backedges_only)
199207
end
200208
end
201209
for tme::Core.TypeMapEntry in extext_methods
202-
scan_new_method!(methods_with_invalidated_source, tme.func::Method)
210+
scan_new_method!(methods_with_invalidated_source, tme.func::Method, image_backedges_only)
203211
end
204212
return methods_with_invalidated_source
205213
end

base/mpfr.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ import
2020
sinpi, cospi, sincospi, tanpi, sind, cosd, tand, asind, acosd, atand,
2121
uinttype, exponent_max, exponent_min, ieee754_representation, significand_mask
2222

23+
import .Core: AbstractFloat
24+
import .Base: Rational, Float16, Float32, Float64, Bool
25+
2326
using .Base.Libc
2427
import ..Rounding: Rounding,
2528
rounding_raw, setrounding_raw, rounds_to_nearest, rounds_away_from_zero,
2629
tie_breaker_is_to_even, correct_rounding_requires_increment
2730

28-
import ..GMP: ClongMax, CulongMax, CdoubleMax, Limb, libgmp
31+
import ..GMP: ClongMax, CulongMax, CdoubleMax, Limb, libgmp, BigInt
2932

3033
import ..FastMath.sincos_fast
3134

base/multidimensional.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
module IteratorsMD
55
import .Base: eltype, length, size, first, last, in, getindex, setindex!,
66
min, max, zero, oneunit, isless, eachindex,
7-
convert, show, iterate, promote_rule, to_indices, copy
7+
convert, show, iterate, promote_rule, to_indices, copy,
8+
isassigned
89

910
import .Base: +, -, *, (:)
1011
import .Base: simd_outer_range, simd_inner_length, simd_index, setindex
12+
import Core: Tuple
1113
using .Base: to_index, fill_to_length, tail, safe_tail
1214
using .Base: IndexLinear, IndexCartesian, AbstractCartesianIndex,
1315
ReshapedArray, ReshapedArrayLF, OneTo, Fix1

base/namedtuple.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3+
import Core: NamedTuple
4+
35
"""
46
NamedTuple
57

base/refpointer.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3+
import Core: Ref
4+
35
"""
46
Ref{T}
57

base/runtime_internals.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,3 +1656,5 @@ isempty(mt::Core.MethodTable) = (mt.defs === nothing)
16561656
uncompressed_ir(m::Method) = isdefined(m, :source) ? _uncompressed_ir(m) :
16571657
isdefined(m, :generator) ? error("Method is @generated; try `code_lowered` instead.") :
16581658
error("Code for this Method is not available.")
1659+
1660+
has_image_globalref(m::Method) = ccall(:jl_ir_flag_has_image_globalref, Bool, (Any,), m.source)

base/staticdata.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ end
2525
function insert_backedges(edges::Vector{Any}, ext_ci_list::Union{Nothing,Vector{Any}}, extext_methods::Vector{Any}, internal_methods::Vector{Any})
2626
# determine which CodeInstance objects are still valid in our image
2727
# to enable any applicable new codes
28-
methods_with_invalidated_source = Base.scan_new_methods(extext_methods, internal_methods)
28+
backedges_only = unsafe_load(cglobal(:jl_first_image_replacement_world, UInt)) == typemax(UInt)
29+
methods_with_invalidated_source = Base.scan_new_methods(extext_methods, internal_methods, backedges_only)
2930
stack = CodeInstance[]
3031
visiting = IdDict{CodeInstance,Int}()
3132
_insert_backedges(edges, stack, visiting, methods_with_invalidated_source)

base/strings/basic.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3+
import Core: Symbol
4+
35
"""
46
The `AbstractString` type is the supertype of all string implementations in
57
Julia. Strings are encodings of sequences of [Unicode](https://unicode.org/)

base/tuple.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3+
import Core: Tuple
4+
35
# Document NTuple here where we have everything needed for the doc system
46
"""
57
NTuple{N, T}

deps/checksums/LinearAlgebra-e7da19f2764ba36bd0a9eb8ec67dddce19d87114.tar.gz/md5

Lines changed: 0 additions & 1 deletion
This file was deleted.

deps/checksums/LinearAlgebra-e7da19f2764ba36bd0a9eb8ec67dddce19d87114.tar.gz/sha512

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5b6db0a9e4e75f998b63ef9b3f62005c
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b1bd5744395f692c5902c7074a4e7d3a9cfd7b1905bccdf72b77602ab10d3c1b9a8eb45eac358442da3afc1d26f2e4f4d56f40a0465a70e1d962f0a6a259657e

src/cgutils.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4710,10 +4710,9 @@ static jl_cgval_t emit_memoryref(jl_codectx_t &ctx, const jl_cgval_t &ref, jl_cg
47104710
setName(ctx.emission_context, ovflw, "memoryref_ovflw");
47114711
}
47124712
#endif
4713-
boffset = ctx.builder.CreateMul(offset, elsz);
4714-
setName(ctx.emission_context, boffset, "memoryref_byteoffset");
4715-
newdata = ctx.builder.CreateGEP(getInt8Ty(ctx.builder.getContext()), data, boffset);
4716-
setName(ctx.emission_context, newdata, "memoryref_data_byteoffset");
4713+
Type *elty = isboxed ? ctx.types().T_prjlvalue : julia_type_to_llvm(ctx, jl_tparam1(ref.typ));
4714+
newdata = ctx.builder.CreateGEP(elty, data, offset);
4715+
setName(ctx.emission_context, newdata, "memoryref_data_offset");
47174716
(void)boffset; // LLVM is very bad at handling GEP with types different from the load
47184717
if (bc) {
47194718
BasicBlock *failBB, *endBB;

0 commit comments

Comments
 (0)