1
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2
2
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
3
7
using . Core: CodeInstance, MethodInstance
4
- using . Base: JLOptions, Compiler, get_world_counter, _methods_by_ftype, get_methodtable, get_ci_mi, morespecific
5
8
6
9
const 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 )
8
11
debug_method_invalidation (onoff:: Bool ) =
9
12
_jl_debug_method_invalidation[] = onoff ? Any[] : nothing
10
13
@@ -70,7 +73,7 @@ function insert_backedges(edges::Vector{Any}, ext_ci_list::Union{Nothing,Vector{
70
73
# determine which CodeInstance objects are still valid in our image
71
74
# to enable any applicable new codes
72
75
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)
74
77
workspace = VerifyMethodWorkspace ()
75
78
_insert_backedges (edges, workspace)
76
79
if ext_ci_list != = nothing
@@ -135,23 +138,23 @@ function needs_instrumentation(codeinst::CodeInstance, mi::MethodInstance, def::
135
138
if JLOptions (). code_coverage != 0 || JLOptions (). malloc_log != 0
136
139
# test if the code needs to run with instrumentation, in which case we cannot use existing generated code
137
140
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)
140
143
return true
141
144
end
142
145
gensig = gen_staged_sig (def, mi)
143
146
if gensig != = nothing
144
147
# 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 )
148
151
result = _methods_by_ftype (gensig, nothing , - 1 , validation_world, #= ambig=# false , minworld, maxworld, has_ambig)
149
152
if result != = nothing
150
153
for k = 1 : length (result)
151
154
match = result[k]:: Core.MethodMatch
152
155
genmethod = match. method
153
156
# 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)
155
158
return true
156
159
end
157
160
end
@@ -194,7 +197,7 @@ function verify_method(codeinst::CodeInstance, validation_world::UInt, workspace
194
197
continue
195
198
end
196
199
197
- minworld, maxworld = Base . get_require_world (), validation_world
200
+ minworld, maxworld = get_require_world (), validation_world
198
201
199
202
if haskey (workspace. visiting, initial. codeinst)
200
203
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
209
212
# Check for invalidation of GlobalRef edges
210
213
if (initial. def. did_scan_source & 0x1 ) == 0x0
211
214
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)
213
216
end
214
217
if (initial. def. did_scan_source & 0x4 ) != 0x0
215
218
maxworld = 0
@@ -220,7 +223,7 @@ function verify_method(codeinst::CodeInstance, validation_world::UInt, workspace
220
223
end
221
224
222
225
# Process all non-CodeInstance edges
223
- if ! isempty (initial. callees) && maxworld != Base . get_require_world ()
226
+ if ! isempty (initial. callees) && maxworld != get_require_world ()
224
227
matches = []
225
228
j = 1
226
229
while j <= length (initial. callees)
@@ -248,7 +251,7 @@ function verify_method(codeinst::CodeInstance, validation_world::UInt, workspace
248
251
j += 1
249
252
min_valid2 = minworld
250
253
max_valid2 = maxworld
251
- if ! Base . binding_was_invalidated (edge)
254
+ if ! binding_was_invalidated (edge)
252
255
if isdefined (edge, :partitions )
253
256
min_valid2 = edge. partitions. min_world
254
257
max_valid2 = edge. partitions. max_world
@@ -333,7 +336,7 @@ function verify_method(codeinst::CodeInstance, validation_world::UInt, workspace
333
336
end
334
337
@atomic :monotonic child. max_world = result. result_maxworld
335
338
if result. result_maxworld == validation_world && validation_world == get_world_counter ()
336
- Compiler . store_backedges (child, child. edges)
339
+ store_backedges (child, child. edges)
337
340
end
338
341
@assert workspace. visiting[child] == length (workspace. stack) + 1
339
342
delete! (workspace. visiting, child)
@@ -559,9 +562,9 @@ function verify_call(@nospecialize(sig), expecteds::Core.SimpleVector, i::Int, n
559
562
end
560
563
# next, compare the current result of ml_matches to the old result
561
564
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 )
565
568
result = _methods_by_ftype (sig, nothing , lim, world, #= ambig=# false , minworld, maxworld, has_ambig)
566
569
if result === nothing
567
570
empty! (matches)
@@ -626,7 +629,7 @@ function verify_invokesig(@nospecialize(invokesig), expected::Method, world::UIn
626
629
minworld = 1
627
630
maxworld = 0
628
631
else
629
- matched, valid_worlds = Compiler . _findsup (invokesig, mt, world)
632
+ matched, valid_worlds = _findsup (invokesig, mt, world)
630
633
minworld, maxworld = valid_worlds. min_world, valid_worlds. max_world
631
634
if matched === nothing
632
635
maxworld = 0
@@ -641,3 +644,9 @@ function verify_invokesig(@nospecialize(invokesig), expected::Method, world::UIn
641
644
end
642
645
return minworld, maxworld
643
646
end
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