11# This file is a part of Julia. License is MIT: https://julialang.org/license
22
3+ using .. Compiler. Base
4+ using .. Compiler: _findsup, store_backedges, JLOptions, get_world_counter,
5+ _methods_by_ftype, get_methodtable, get_ci_mi, should_instrument,
6+ morespecific, RefValue, get_require_world, Vector, IdDict
37using . Core: CodeInstance, MethodInstance
4- using . Base: JLOptions, Compiler, get_world_counter, _methods_by_ftype, get_methodtable, get_ci_mi, morespecific
58
69const WORLD_AGE_REVALIDATION_SENTINEL:: UInt = 1
7- const _jl_debug_method_invalidation = Ref {Union{Nothing,Vector{Any}}} (nothing )
10+ const _jl_debug_method_invalidation = RefValue {Union{Nothing,Vector{Any}}} (nothing )
811debug_method_invalidation (onoff:: Bool ) =
912 _jl_debug_method_invalidation[] = onoff ? Any[] : nothing
1013
@@ -70,7 +73,7 @@ function insert_backedges(edges::Vector{Any}, ext_ci_list::Union{Nothing,Vector{
7073 # determine which CodeInstance objects are still valid in our image
7174 # to enable any applicable new codes
7275 backedges_only = unsafe_load (cglobal (:jl_first_image_replacement_world , UInt)) == typemax (UInt)
73- Base . scan_new_methods! (extext_methods, internal_methods, backedges_only)
76+ scan_new_methods! (extext_methods, internal_methods, backedges_only)
7477 workspace = VerifyMethodWorkspace ()
7578 _insert_backedges (edges, workspace)
7679 if ext_ci_list != = nothing
@@ -135,23 +138,23 @@ function needs_instrumentation(codeinst::CodeInstance, mi::MethodInstance, def::
135138 if JLOptions (). code_coverage != 0 || JLOptions (). malloc_log != 0
136139 # test if the code needs to run with instrumentation, in which case we cannot use existing generated code
137140 if isdefined (def, :debuginfo ) ? # generated_only functions do not have debuginfo, so fall back to considering their codeinst debuginfo though this may be slower and less reliable
138- Compiler . should_instrument (def. module, def. debuginfo) :
139- isdefined (codeinst, :debuginfo ) && Compiler . should_instrument (def. module, codeinst. debuginfo)
141+ should_instrument (def. module, def. debuginfo) :
142+ isdefined (codeinst, :debuginfo ) && should_instrument (def. module, codeinst. debuginfo)
140143 return true
141144 end
142145 gensig = gen_staged_sig (def, mi)
143146 if gensig != = nothing
144147 # if this is defined by a generator, try to consider forcing re-running the generators too, to add coverage for them
145- minworld = Ref {UInt} (1 )
146- maxworld = Ref {UInt} (typemax (UInt))
147- has_ambig = Ref {Int32} (0 )
148+ minworld = RefValue {UInt} (1 )
149+ maxworld = RefValue {UInt} (typemax (UInt))
150+ has_ambig = RefValue {Int32} (0 )
148151 result = _methods_by_ftype (gensig, nothing , - 1 , validation_world, #= ambig=# false , minworld, maxworld, has_ambig)
149152 if result != = nothing
150153 for k = 1 : length (result)
151154 match = result[k]:: Core.MethodMatch
152155 genmethod = match. method
153156 # no, I refuse to refuse to recurse into your cursed generated function generators and will only test one level deep here
154- if isdefined (genmethod, :debuginfo ) && Compiler . should_instrument (genmethod. module, genmethod. debuginfo)
157+ if isdefined (genmethod, :debuginfo ) && should_instrument (genmethod. module, genmethod. debuginfo)
155158 return true
156159 end
157160 end
@@ -194,7 +197,7 @@ function verify_method(codeinst::CodeInstance, validation_world::UInt, workspace
194197 continue
195198 end
196199
197- minworld, maxworld = Base . get_require_world (), validation_world
200+ minworld, maxworld = get_require_world (), validation_world
198201
199202 if haskey (workspace. visiting, initial. codeinst)
200203 workspace. result_states[current_depth] = VerifyMethodResultState (workspace. visiting[initial. codeinst], minworld, maxworld)
@@ -209,7 +212,7 @@ function verify_method(codeinst::CodeInstance, validation_world::UInt, workspace
209212 # Check for invalidation of GlobalRef edges
210213 if (initial. def. did_scan_source & 0x1 ) == 0x0
211214 backedges_only = unsafe_load (cglobal (:jl_first_image_replacement_world , UInt)) == typemax (UInt)
212- Base . scan_new_method! (initial. def, backedges_only)
215+ scan_new_method! (initial. def, backedges_only)
213216 end
214217 if (initial. def. did_scan_source & 0x4 ) != 0x0
215218 maxworld = 0
@@ -220,7 +223,7 @@ function verify_method(codeinst::CodeInstance, validation_world::UInt, workspace
220223 end
221224
222225 # Process all non-CodeInstance edges
223- if ! isempty (initial. callees) && maxworld != Base . get_require_world ()
226+ if ! isempty (initial. callees) && maxworld != get_require_world ()
224227 matches = []
225228 j = 1
226229 while j <= length (initial. callees)
@@ -248,7 +251,7 @@ function verify_method(codeinst::CodeInstance, validation_world::UInt, workspace
248251 j += 1
249252 min_valid2 = minworld
250253 max_valid2 = maxworld
251- if ! Base . binding_was_invalidated (edge)
254+ if ! binding_was_invalidated (edge)
252255 if isdefined (edge, :partitions )
253256 min_valid2 = edge. partitions. min_world
254257 max_valid2 = edge. partitions. max_world
@@ -333,7 +336,7 @@ function verify_method(codeinst::CodeInstance, validation_world::UInt, workspace
333336 end
334337 @atomic :monotonic child. max_world = result. result_maxworld
335338 if result. result_maxworld == validation_world && validation_world == get_world_counter ()
336- Compiler . store_backedges (child, child. edges)
339+ store_backedges (child, child. edges)
337340 end
338341 @assert workspace. visiting[child] == length (workspace. stack) + 1
339342 delete! (workspace. visiting, child)
@@ -559,9 +562,9 @@ function verify_call(@nospecialize(sig), expecteds::Core.SimpleVector, i::Int, n
559562 end
560563 # next, compare the current result of ml_matches to the old result
561564 lim = _jl_debug_method_invalidation[] != = nothing ? Int (typemax (Int32)) : n
562- minworld = Ref {UInt} (1 )
563- maxworld = Ref {UInt} (typemax (UInt))
564- has_ambig = Ref {Int32} (0 )
565+ minworld = RefValue {UInt} (1 )
566+ maxworld = RefValue {UInt} (typemax (UInt))
567+ has_ambig = RefValue {Int32} (0 )
565568 result = _methods_by_ftype (sig, nothing , lim, world, #= ambig=# false , minworld, maxworld, has_ambig)
566569 if result === nothing
567570 empty! (matches)
@@ -626,7 +629,7 @@ function verify_invokesig(@nospecialize(invokesig), expected::Method, world::UIn
626629 minworld = 1
627630 maxworld = 0
628631 else
629- matched, valid_worlds = Compiler . _findsup (invokesig, mt, world)
632+ matched, valid_worlds = _findsup (invokesig, mt, world)
630633 minworld, maxworld = valid_worlds. min_world, valid_worlds. max_world
631634 if matched === nothing
632635 maxworld = 0
@@ -641,3 +644,9 @@ function verify_invokesig(@nospecialize(invokesig), expected::Method, world::UIn
641644 end
642645 return minworld, maxworld
643646end
647+
648+ # Wrapper to call insert_backedges in typeinf_world for external calls
649+ function insert_backedges_typeinf (edges:: Vector{Any} , ext_ci_list:: Union{Nothing,Vector{Any}} , extext_methods:: Vector{Any} , internal_methods:: Vector{Any} )
650+ args = Any[insert_backedges, edges, ext_ci_list, extext_methods, internal_methods]
651+ return ccall (:jl_call_in_typeinf_world , Any, (Ptr{Any}, Cint), args, length (args))
652+ end
0 commit comments