Skip to content

Commit 0cf5a4d

Browse files
authored
Make delete_binding operate in the latest world (#58043)
Fixes #58016
1 parent edbad8b commit 0cf5a4d

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/module.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,16 +1727,20 @@ JL_DLLEXPORT void jl_disable_binding(jl_globalref_t *gr)
17271727
jl_binding_t *b = gr->binding;
17281728
if (!b)
17291729
b = jl_get_module_binding(gr->mod, gr->name, 1);
1730-
jl_binding_partition_t *bpart = jl_get_binding_partition(b, jl_current_task->world_age);
17311730

1732-
if (jl_binding_kind(bpart) == PARTITION_KIND_GUARD) {
1733-
// Already guard
1731+
for (;;) {
1732+
jl_binding_partition_t *bpart = jl_get_binding_partition(b, jl_atomic_load_acquire(&jl_world_counter));
1733+
1734+
if (jl_binding_kind(bpart) == PARTITION_KIND_GUARD) {
1735+
// Already guard
1736+
return;
1737+
}
1738+
1739+
if (!jl_replace_binding(b, bpart, NULL, PARTITION_KIND_GUARD))
1740+
continue;
1741+
17341742
return;
17351743
}
1736-
1737-
for (;;)
1738-
if (jl_replace_binding(b, bpart, NULL, PARTITION_KIND_GUARD))
1739-
break;
17401744
}
17411745

17421746
JL_DLLEXPORT int jl_is_const(jl_module_t *m, jl_sym_t *var)

test/rebinding.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,12 @@ end
383383

384384
# M3 connects all, so we should have a single partition
385385
@test access_and_count(:afterM3) == 1
386+
387+
# Test that delete_binding in an outdated world age works
388+
module BindingTestModule; end
389+
function create_and_delete_binding()
390+
Core.eval(BindingTestModule, :(const x = 1))
391+
Base.delete_binding(BindingTestModule, :x)
392+
end
393+
create_and_delete_binding()
394+
@test Base.binding_kind(BindingTestModule, :x) == Base.PARTITION_KIND_GUARD

0 commit comments

Comments
 (0)