Skip to content

Commit 66b6db7

Browse files
KenoKristofferC
authored andcommitted
bpart: Fix reresolution logic on export value changes (#59368)
Fixes #59272. This code was originally introduced in e7efe42. The design of the binding partitions underwent several changes, so I'm not fully sure if it was correct at the time, but regardless, it was rendered incorrect by 60a9f69. In the new design, even a change to the value of a binding (not just its visibility) can affect the resolution outcome, so a full re-resolution is always required. Fix identified by Claude (in one of several rollouts). Correct fix among them identified by me. Actual change/test by me.
1 parent 3220a81 commit 66b6db7

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

base/invalidation.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ function invalidate_code_for_globalref!(b::Core.Binding, invalidated_bpart::Core
155155
latest_bpart = user_binding.partitions
156156
latest_bpart.max_world == typemax(UInt) || continue
157157
is_some_implicit(binding_kind(latest_bpart)) || continue
158-
new_bpart = need_to_invalidate_export ?
159-
ccall(:jl_maybe_reresolve_implicit, Any, (Any, Csize_t), user_binding, new_max_world) :
160-
latest_bpart
158+
new_bpart = ccall(:jl_maybe_reresolve_implicit, Any, (Any, Csize_t), user_binding, new_max_world)
161159
if need_to_invalidate_code || new_bpart !== latest_bpart
162160
push!(queued_bindings, (convert(Core.Binding, user_binding), latest_bpart, new_bpart))
163161
end

test/rebinding.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,19 @@ function create_and_delete_binding()
392392
end
393393
create_and_delete_binding()
394394
@test Base.binding_kind(BindingTestModule, :x) == Base.PARTITION_KIND_GUARD
395+
396+
# Test that we properly invalidate bindings if the value changes, not just the
397+
# export status (#59272)
398+
module Invalidate59272
399+
using Test
400+
module Foo
401+
export Bar
402+
struct Bar
403+
# x
404+
end
405+
end
406+
using .Foo
407+
@test isa(Bar(), Foo.Bar)
408+
Core.eval(Foo, :(struct Bar; x; end))
409+
@test Bar(1) == Foo.Bar(1)
410+
end

0 commit comments

Comments
 (0)