Skip to content

Commit f4160cf

Browse files
KenoKristofferC
authored andcommitted
Make delete_binding operate in the latest world (#58043)
Fixes #58016
1 parent bf1efa3 commit f4160cf

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
@@ -1775,16 +1775,20 @@ JL_DLLEXPORT void jl_disable_binding(jl_globalref_t *gr)
17751775
jl_binding_t *b = gr->binding;
17761776
if (!b)
17771777
b = jl_get_module_binding(gr->mod, gr->name, 1);
1778-
jl_binding_partition_t *bpart = jl_get_binding_partition(b, jl_current_task->world_age);
17791778

1780-
if (jl_binding_kind(bpart) == PARTITION_KIND_GUARD) {
1781-
// Already guard
1779+
for (;;) {
1780+
jl_binding_partition_t *bpart = jl_get_binding_partition(b, jl_atomic_load_acquire(&jl_world_counter));
1781+
1782+
if (jl_binding_kind(bpart) == PARTITION_KIND_GUARD) {
1783+
// Already guard
1784+
return;
1785+
}
1786+
1787+
if (!jl_replace_binding(b, bpart, NULL, PARTITION_KIND_GUARD))
1788+
continue;
1789+
17821790
return;
17831791
}
1784-
1785-
for (;;)
1786-
if (jl_replace_binding(b, bpart, NULL, PARTITION_KIND_GUARD))
1787-
break;
17881792
}
17891793

17901794
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)