Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid racy double-load of binding restriction in import_module #56395

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,11 +665,16 @@ static void import_module(jl_module_t *JL_NONNULL m, jl_module_t *import, jl_sym
jl_sym_t *name = asname ? asname : import->name;
// TODO: this is a bit race-y with what error message we might print
jl_binding_t *b = jl_get_module_binding(m, name, 1);
if (jl_get_binding_value_if_const(b) == (jl_value_t*)import)
return;
jl_binding_partition_t *bpart = jl_get_binding_partition(b, jl_current_task->world_age);
jl_ptr_kind_union_t pku = jl_atomic_load_relaxed(&bpart->restriction);
if (decode_restriction_kind(pku) != BINDING_KIND_GUARD && decode_restriction_kind(pku) != BINDING_KIND_FAILED) {
// Unlike regular constant declaration, we allow this as long as we eventually end up at a constant.
pku = jl_walk_binding_inplace(&b, &bpart, jl_current_task->world_age);
if (decode_restriction_kind(pku) == BINDING_KIND_CONST || decode_restriction_kind(pku) == BINDING_KIND_CONST_IMPORT) {
// Already declared (e.g. on another thread) or imported.
if (decode_restriction_value(pku) == (jl_value_t*)import)
return;
}
jl_errorf("importing %s into %s conflicts with an existing global",
jl_symbol_name(name), jl_symbol_name(m->name));
}
Expand Down