Skip to content

Commit fc1fb41

Browse files
authored
bpart: Fix reresolution logic on export value changes (JuliaLang#59368)
Fixes JuliaLang#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 ceeb661 commit fc1fb41

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Compiler/src/bindinginvalidations.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ function invalidate_code_for_globalref!(b::Core.Binding, invalidated_bpart::Core
146146
latest_bpart = user_binding.partitions
147147
latest_bpart.max_world == typemax(UInt) || continue
148148
is_some_implicit(binding_kind(latest_bpart)) || continue
149-
new_bpart = need_to_invalidate_export ?
150-
ccall(:jl_maybe_reresolve_implicit, Any, (Any, Csize_t), user_binding, new_max_world) :
151-
latest_bpart
149+
new_bpart = ccall(:jl_maybe_reresolve_implicit, Any, (Any, Csize_t), user_binding, new_max_world)
152150
if need_to_invalidate_code || new_bpart !== latest_bpart
153151
push!(queued_bindings, (convert(Core.Binding, user_binding), latest_bpart, new_bpart))
154152
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)