@@ -67,20 +67,25 @@ function invalidate_method_for_globalref!(gr::GlobalRef, method::Method, invalid
6767 binding = convert (Core. Binding, gr)
6868 if isdefined (method, :source )
6969 src = _uncompressed_ir (method)
70- old_stmts = src. code
7170 invalidate_all = should_invalidate_code_for_globalref (gr, src)
7271 end
72+ invalidated_any = false
7373 for mi in specializations (method)
7474 isdefined (mi, :cache ) || continue
7575 ci = mi. cache
76+ invalidated = false
7677 while true
7778 if ci. max_world > new_max_world && (invalidate_all || scan_edge_list (ci, binding))
7879 ccall (:jl_invalidate_code_instance , Cvoid, (Any, UInt), ci, new_max_world)
80+ invalidated = true
7981 end
8082 isdefined (ci, :next ) || break
8183 ci = ci. next
8284 end
85+ invalidated && ccall (:jl_maybe_log_binding_invalidation , Cvoid, (Any,), mi)
86+ invalidated_any |= invalidated
8387 end
88+ return invalidated_any
8489end
8590
8691export_affecting_partition_flags (bpart:: Core.BindingPartition ) =
@@ -104,18 +109,21 @@ function invalidate_code_for_globalref!(b::Core.Binding, invalidated_bpart::Core
104109 need_to_invalidate_export = export_affecting_partition_flags (invalidated_bpart) != =
105110 export_affecting_partition_flags (new_bpart)
106111
112+ invalidated_any = false
113+ queued_bindings = Tuple{Core. Binding, Core. BindingPartition, Core. BindingPartition}[] # defer handling these to keep the logging coherent
107114 if need_to_invalidate_code
108115 if (b. flags & BINDING_FLAG_ANY_IMPLICIT_EDGES) != 0
109116 nmethods = ccall (:jl_module_scanned_methods_length , Csize_t, (Any,), gr. mod)
110117 for i = 1 : nmethods
111118 method = ccall (:jl_module_scanned_methods_getindex , Any, (Any, Csize_t), gr. mod, i):: Method
112- invalidate_method_for_globalref! (gr, method, invalidated_bpart, new_max_world)
119+ invalidated_any |= invalidate_method_for_globalref! (gr, method, invalidated_bpart, new_max_world)
113120 end
114121 end
115122 if isdefined (b, :backedges )
116123 for edge in b. backedges
117124 if isa (edge, CodeInstance)
118125 ccall (:jl_invalidate_code_instance , Cvoid, (Any, UInt), edge, new_max_world)
126+ invalidated_any = true
119127 elseif isa (edge, Core. Binding)
120128 isdefined (edge, :partitions ) || continue
121129 latest_bpart = edge. partitions
@@ -124,9 +132,9 @@ function invalidate_code_for_globalref!(b::Core.Binding, invalidated_bpart::Core
124132 if is_some_binding_imported (binding_kind (latest_bpart))
125133 partition_restriction (latest_bpart) === b || continue
126134 end
127- invalidate_code_for_globalref! (edge, latest_bpart , latest_bpart, new_max_world )
135+ push! (queued_bindings, (edge , latest_bpart, latest_bpart) )
128136 else
129- invalidate_method_for_globalref! (gr, edge:: Method , invalidated_bpart, new_max_world)
137+ invalidated_any |= invalidate_method_for_globalref! (gr, edge:: Method , invalidated_bpart, new_max_world)
130138 end
131139 end
132140 end
@@ -148,11 +156,16 @@ function invalidate_code_for_globalref!(b::Core.Binding, invalidated_bpart::Core
148156 ccall (:jl_maybe_reresolve_implicit , Any, (Any, Csize_t), user_binding, new_max_world) :
149157 latest_bpart
150158 if need_to_invalidate_code || new_bpart != = latest_bpart
151- invalidate_code_for_globalref! ( convert (Core. Binding, user_binding), latest_bpart, new_bpart, new_max_world )
159+ push! (queued_bindings, ( convert (Core. Binding, user_binding), latest_bpart, new_bpart) )
152160 end
153161 end
154162 end
155163 end
164+ invalidated_any && ccall (:jl_maybe_log_binding_invalidation , Cvoid, (Any,), invalidated_bpart)
165+ for (edge, invalidated_bpart, new_bpart) in queued_bindings
166+ invalidated_any |= invalidate_code_for_globalref! (edge, invalidated_bpart, new_bpart, new_max_world)
167+ end
168+ return invalidated_any
156169end
157170invalidate_code_for_globalref! (gr:: GlobalRef , invalidated_bpart:: Core.BindingPartition , new_bpart:: Core.BindingPartition , new_max_world:: UInt ) =
158171 invalidate_code_for_globalref! (convert (Core. Binding, gr), invalidated_bpart, new_bpart, new_max_world)
0 commit comments