Skip to content

Commit aee98f8

Browse files
authored
Backports release 1.12 (#57536)
2 parents 49263b7 + ed23a99 commit aee98f8

File tree

144 files changed

+4153
-2286
lines changed

Some content is hidden

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

144 files changed

+4153
-2286
lines changed

Compiler/src/Compiler.jl

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ else
3535

3636
@eval baremodule Compiler
3737

38-
# Needs to match UUID defined in Project.toml
39-
ccall(:jl_set_module_uuid, Cvoid, (Any, NTuple{2, UInt64}), Compiler,
40-
(0x807dbc54_b67e_4c79, 0x8afb_eafe4df6f2e1))
41-
4238
using Core.Intrinsics, Core.IR
4339

4440
using Core: ABIOverride, Builtin, CodeInstance, IntrinsicFunction, MethodInstance, MethodMatch,
@@ -49,7 +45,8 @@ using Core: ABIOverride, Builtin, CodeInstance, IntrinsicFunction, MethodInstanc
4945

5046
using Base
5147
using Base: @_foldable_meta, @_gc_preserve_begin, @_gc_preserve_end, @nospecializeinfer,
52-
BINDING_KIND_GLOBAL, BINDING_KIND_UNDEF_CONST, BINDING_KIND_BACKDATED_CONST, BINDING_KIND_DECLARED,
48+
PARTITION_KIND_GLOBAL, PARTITION_KIND_UNDEF_CONST, PARTITION_KIND_BACKDATED_CONST, PARTITION_KIND_DECLARED,
49+
PARTITION_FLAG_DEPWARN,
5350
Base, BitVector, Bottom, Callable, DataTypeFieldDesc,
5451
EffectsOverride, Filter, Generator, IteratorSize, JLOptions, NUM_EFFECTS_OVERRIDES,
5552
OneTo, Ordering, RefValue, SizeUnknown, _NAMEDTUPLE_NAME,
@@ -60,7 +57,7 @@ using Base: @_foldable_meta, @_gc_preserve_begin, @_gc_preserve_end, @nospeciali
6057
generating_output, get_nospecializeinfer_sig, get_world_counter, has_free_typevars,
6158
hasgenerator, hasintersect, indexed_iterate, isType, is_file_tracked, is_function_def,
6259
is_meta_expr, is_meta_expr_head, is_nospecialized, is_nospecializeinfer, is_defined_const_binding,
63-
is_some_const_binding, is_some_guard, is_some_imported, is_valid_intrinsic_elptr,
60+
is_some_const_binding, is_some_guard, is_some_imported, is_some_explicit_imported, is_some_binding_imported, is_valid_intrinsic_elptr,
6461
isbitsunion, isconcretedispatch, isdispatchelem, isexpr, isfieldatomic, isidentityfree,
6562
iskindtype, ismutabletypename, ismutationfree, issingletontype, isvarargtype, isvatuple,
6663
kwerr, lookup_binding_partition, may_invoke_generator, methods, midpoint, moduleroot,
@@ -74,6 +71,10 @@ import Base: ==, _topmod, append!, convert, copy, copy!, findall, first, get, ge
7471
getindex, haskey, in, isempty, isready, iterate, iterate, last, length, max_world,
7572
min_world, popfirst!, push!, resize!, setindex!, size, intersect
7673

74+
# Needs to match UUID defined in Project.toml
75+
ccall(:jl_set_module_uuid, Cvoid, (Any, NTuple{2, UInt64}), Compiler,
76+
(0x807dbc54_b67e_4c79, 0x8afb_eafe4df6f2e1))
77+
7778
const getproperty = Core.getfield
7879
const setproperty! = Core.setfield!
7980
const swapproperty! = Core.swapfield!
@@ -129,7 +130,7 @@ something(x::Any, y...) = x
129130
############
130131

131132
baremodule BuildSettings
132-
using Core: ARGS, include
133+
using Core: ARGS, include, Int, ===
133134
using ..Compiler: >, getindex, length
134135

135136
global MAX_METHODS::Int = 3
@@ -188,21 +189,25 @@ macro __SOURCE_FILE__()
188189
return QuoteNode(__source__.file::Symbol)
189190
end
190191

191-
module IRShow end
192-
function load_irshow!()
193-
if isdefined(Base, :end_base_include)
194-
# This code path is exclusively for Revise, which may want to re-run this
195-
# after bootstrap.
196-
include(IRShow, Base.joinpath(Base.dirname(Base.String(@__SOURCE_FILE__)), "ssair/show.jl"))
197-
else
192+
module IRShow end # relies on string and IO operations defined in Base
193+
baremodule TrimVerifier using Core end # relies on IRShow, so define this afterwards
194+
195+
if isdefined(Base, :end_base_include)
196+
# When this module is loaded as the standard library, include these files as usual
197+
include(IRShow, "ssair/show.jl")
198+
include(TrimVerifier, "verifytrim.jl")
199+
else
200+
function load_irshow!()
201+
Base.delete_method(Base.which(verify_typeinf_trim, (IO, Vector{Any}, Bool)),)
198202
include(IRShow, "ssair/show.jl")
203+
include(TrimVerifier, "verifytrim.jl")
199204
end
200-
end
201-
if !isdefined(Base, :end_base_include)
202-
# During bootstrap, skip including this file and defer it to base/show.jl to include later
203-
else
204-
# When this module is loaded as the standard library, include this file as usual
205-
load_irshow!()
205+
function verify_typeinf_trim(io::IO, codeinfos::Vector{Any}, onlywarn::Bool)
206+
# stub implementation
207+
msg = "--trim verifier not defined"
208+
onlywarn ? println(io, msg) : error(msg)
209+
end
210+
# During bootstrap, skip including these files and defer to base/show.jl to include it later
206211
end
207212

208213
end # baremodule Compiler

Compiler/src/abstractinterpretation.jl

Lines changed: 181 additions & 103 deletions
Large diffs are not rendered by default.

Compiler/src/bootstrap.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function bootstrap!()
7171
end
7272
end
7373
end
74-
codeinfos = typeinf_ext_toplevel(methods, [world], false)
74+
codeinfos = typeinf_ext_toplevel(methods, [world], TRIM_NO)
7575
for i = 1:2:length(codeinfos)
7676
ci = codeinfos[i]::CodeInstance
7777
src = codeinfos[i + 1]::CodeInfo

Compiler/src/cicache.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ function intersect(a::WorldRange, b::WorldRange)
4040
return ret
4141
end
4242

43+
function union(a::WorldRange, b::WorldRange)
44+
if b.min_world < a.min_world
45+
(b, a) = (a, b)
46+
end
47+
@assert a.max_world >= b.min_world - 1
48+
return WorldRange(a.min_world, b.max_world)
49+
end
50+
4351
"""
4452
struct WorldView
4553

Compiler/src/inferenceresult.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ function cache_lookup(𝕃::AbstractLattice, mi::MethodInstance, given_argtypes:
183183
method = mi.def::Method
184184
nargtypes = length(given_argtypes)
185185
for cached_result in cache
186-
cached_result.linfo === mi || @goto next_cache
186+
cached_result.tombstone && continue # ignore deleted entries (due to LimitedAccuracy)
187+
cached_result.linfo === mi || continue
187188
cache_argtypes = cached_result.argtypes
188189
@assert length(cache_argtypes) == nargtypes "invalid `cache_argtypes` for `mi`"
189190
cache_overridden_by_const = cached_result.overridden_by_const::BitVector

Compiler/src/inferencestate.jl

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ mutable struct InferenceState
292292

293293
# IPO tracking of in-process work, shared with all frames given AbstractInterpreter
294294
callstack #::Vector{AbsIntState}
295-
parentid::Int # index into callstack of the parent frame that originally added this frame (call frame_parent to extract the current parent of the SCC)
295+
parentid::Int # index into callstack of the parent frame that originally added this frame (call cycle_parent to extract the current parent of the SCC)
296296
frameid::Int # index into callstack at which this object is found (or zero, if this is not a cached frame and has no parent)
297297
cycleid::Int # index into the callstack of the topmost frame in the cycle (all frames in the same cycle share the same cycleid)
298298

@@ -302,6 +302,10 @@ mutable struct InferenceState
302302
bestguess #::Type
303303
exc_bestguess
304304
ipo_effects::Effects
305+
time_start::UInt64
306+
time_caches::Float64
307+
time_paused::UInt64
308+
time_self_ns::UInt64
305309

306310
#= flags =#
307311
# Whether to restrict inference of abstract call sites to avoid excessive work
@@ -392,6 +396,7 @@ mutable struct InferenceState
392396
currbb, currpc, ip, handler_info, ssavalue_uses, bb_vartables, bb_saw_latestworld, ssavaluetypes, ssaflags, edges, stmt_info,
393397
tasks, pclimitations, limitations, cycle_backedges, callstack, parentid, frameid, cycleid,
394398
result, unreachable, bestguess, exc_bestguess, ipo_effects,
399+
_time_ns(), 0.0, 0, 0,
395400
restrict_abstract_call_sites, cache_mode, insert_coverage,
396401
interp)
397402

@@ -815,6 +820,8 @@ mutable struct IRInterpretationState
815820
const mi::MethodInstance
816821
world::WorldWithRange
817822
curridx::Int
823+
time_caches::Float64
824+
time_paused::UInt64
818825
const argtypes_refined::Vector{Bool}
819826
const sptypes::Vector{VarState}
820827
const tpdum::TwoPhaseDefUseMap
@@ -849,7 +856,8 @@ mutable struct IRInterpretationState
849856
tasks = WorkThunk[]
850857
edges = Any[]
851858
callstack = AbsIntState[]
852-
return new(spec_info, ir, mi, WorldWithRange(world, valid_worlds), curridx, argtypes_refined, ir.sptypes, tpdum,
859+
return new(spec_info, ir, mi, WorldWithRange(world, valid_worlds),
860+
curridx, 0.0, 0, argtypes_refined, ir.sptypes, tpdum,
853861
ssa_refined, lazyreachability, tasks, edges, callstack, 0, 0)
854862
end
855863
end
@@ -908,14 +916,17 @@ function frame_module(sv::AbsIntState)
908916
return def.module
909917
end
910918

911-
function frame_parent(sv::InferenceState)
919+
frame_parent(sv::AbsIntState) = sv.parentid == 0 ? nothing : (sv.callstack::Vector{AbsIntState})[sv.parentid]
920+
921+
function cycle_parent(sv::InferenceState)
912922
sv.parentid == 0 && return nothing
913923
callstack = sv.callstack::Vector{AbsIntState}
914924
sv = callstack[sv.cycleid]::InferenceState
915925
sv.parentid == 0 && return nothing
916926
return callstack[sv.parentid]
917927
end
918-
frame_parent(sv::IRInterpretationState) = sv.parentid == 0 ? nothing : (sv.callstack::Vector{AbsIntState})[sv.parentid]
928+
cycle_parent(sv::IRInterpretationState) = frame_parent(sv)
929+
919930

920931
# add the orphan child to the parent and the parent to the child
921932
function assign_parentchild!(child::InferenceState, parent::AbsIntState)
@@ -986,12 +997,12 @@ ascending the tree from the given `AbsIntState`).
986997
Note that cycles may be visited in any order.
987998
"""
988999
struct AbsIntStackUnwind
989-
sv::AbsIntState
1000+
callstack::Vector{AbsIntState}
1001+
AbsIntStackUnwind(sv::AbsIntState) = new(sv.callstack::Vector{AbsIntState})
9901002
end
991-
iterate(unw::AbsIntStackUnwind) = (unw.sv, length(unw.sv.callstack::Vector{AbsIntState}))
992-
function iterate(unw::AbsIntStackUnwind, frame::Int)
1003+
function iterate(unw::AbsIntStackUnwind, frame::Int=length(unw.callstack))
9931004
frame == 0 && return nothing
994-
return ((unw.sv.callstack::Vector{AbsIntState})[frame], frame - 1)
1005+
return (unw.callstack[frame], frame - 1)
9951006
end
9961007

9971008
struct AbsIntCycle

Compiler/src/ssair/EscapeAnalysis.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ using Base: Base
1515
# imports
1616
import Base: ==, copy, getindex, setindex!
1717
# usings
18+
using Core
1819
using Core: Builtin, IntrinsicFunction, SimpleVector, ifelse, sizeof
1920
using Core.IR
2021
using Base: # Base definitions

Compiler/src/ssair/irinterp.jl

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

33
function collect_limitations!(@nospecialize(typ), ::IRInterpretationState)
4-
@assert !isa(typ, LimitedAccuracy) "irinterp is unable to handle heavy recursion"
4+
@assert !isa(typ, LimitedAccuracy) "irinterp is unable to handle heavy recursion correctly"
55
return typ
66
end
77

@@ -212,6 +212,7 @@ function reprocess_instruction!(interp::AbstractInterpreter, inst::Instruction,
212212
else
213213
rt = argextype(stmt, irsv.ir)
214214
end
215+
@assert !(rt isa LimitedAccuracy)
215216
if rt !== nothing
216217
if has_flag(inst, IR_FLAG_UNUSED)
217218
# Don't bother checking the type if we know it's unused

Compiler/src/ssair/passes.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,17 +1027,19 @@ end
10271027
sig = sig.body
10281028
isa(sig, DataType) || return nothing
10291029
sig.name === Tuple.name || return nothing
1030-
length(sig.parameters) >= 1 || return nothing
1030+
sig_parameters = sig.parameters::SimpleVector
1031+
length_sig_parameters = length(sig_parameters)
1032+
length_sig_parameters >= 1 || return nothing
10311033

1032-
i = let sig=sig
1033-
findfirst(j::Int->has_typevar(sig.parameters[j], tvar), 1:length(sig.parameters))
1034+
function has_typevar_closure(j::Int)
1035+
has_typevar(sig_parameters[j], tvar)
10341036
end
1037+
1038+
i = findfirst(has_typevar_closure, 1:length_sig_parameters)
10351039
i === nothing && return nothing
1036-
let sig=sig
1037-
any(j::Int->has_typevar(sig.parameters[j], tvar), i+1:length(sig.parameters))
1038-
end && return nothing
1040+
any(has_typevar_closure, i+1:length_sig_parameters) && return nothing
10391041

1040-
arg = sig.parameters[i]
1042+
arg = sig_parameters[i]
10411043

10421044
rarg = def.args[2 + i]
10431045
isa(rarg, SSAValue) || return nothing

Compiler/src/ssair/show.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function builtin_call_has_dispatch(
6767
return true
6868
end
6969
end
70-
elseif (f === Core._apply_pure || f === Core._call_in_world || f === Core._call_in_world_total || f === Core._call_latest)
70+
elseif (f === Core.invoke_in_world || f === Core._call_in_world_total || f === Core.invokelatest)
7171
# These apply-like builtins are effectively dynamic calls
7272
return true
7373
end

Compiler/src/ssair/verify.jl

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,14 @@ function check_op(ir::IRCode, domtree::DomTree, @nospecialize(op), use_bb::Int,
6262
raise_error()
6363
end
6464
elseif isa(op, GlobalRef)
65-
bpart = lookup_binding_partition(min_world(ir.valid_worlds), op)
66-
while is_some_imported(binding_kind(bpart)) && max_world(ir.valid_worlds) <= bpart.max_world
67-
imported_binding = partition_restriction(bpart)::Core.Binding
68-
bpart = lookup_binding_partition(min_world(ir.valid_worlds), imported_binding)
69-
end
70-
if (!is_defined_const_binding(binding_kind(bpart)) || (bpart.max_world < max_world(ir.valid_worlds))) &&
71-
(op.mod !== Core) && (op.mod !== Base)
72-
# Core and Base are excluded because the frontend uses them for intrinsics, etc.
73-
# TODO: Decide which way to go with these.
74-
@verify_error "Unbound or partitioned GlobalRef not allowed in value position"
75-
raise_error()
65+
if op.mod !== Core && op.mod !== Base
66+
(valid_worlds, alldef) = scan_leaf_partitions(nothing, op, WorldWithRange(min_world(ir.valid_worlds), ir.valid_worlds)) do _, _, bpart
67+
is_defined_const_binding(binding_kind(bpart))
68+
end
69+
if !alldef || max_world(valid_worlds) < max_world(ir.valid_worlds) || min_world(valid_worlds) > min_world(ir.valid_worlds)
70+
@verify_error "Unbound or partitioned GlobalRef not allowed in value position"
71+
raise_error()
72+
end
7673
end
7774
elseif isa(op, Expr)
7875
# Only Expr(:boundscheck) is allowed in value position

Compiler/src/stmtinfo.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,7 @@ perform such accesses.
490490
"""
491491
struct GlobalAccessInfo <: CallInfo
492492
b::Core.Binding
493-
bpart::Core.BindingPartition
494493
end
495-
GlobalAccessInfo(::Core.Binding, ::Nothing) = NoCallInfo()
496494
function add_edges_impl(edges::Vector{Any}, info::GlobalAccessInfo)
497495
push!(edges, info.b)
498496
end

0 commit comments

Comments
 (0)