Skip to content

Commit 4376671

Browse files
committed
bindings: batch export/public changes from one statement
No real major effect, basically just making printing look tidier and avoiding spamming the lock.
1 parent e8b52e6 commit 4376671

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

src/jl_exported_funcs.inc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@
313313
XX(jl_module_names) \
314314
XX(jl_module_parent) \
315315
XX(jl_module_getloc) \
316-
XX(jl_module_public) \
317316
XX(jl_module_public_p) \
318317
XX(jl_module_use) \
319318
XX(jl_module_using) \

src/julia.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2112,7 +2112,7 @@ JL_DLLEXPORT void jl_module_use(jl_task_t *ct, jl_module_t *to, jl_module_t *fro
21122112
JL_DLLEXPORT void jl_module_use_as(jl_task_t *ct, jl_module_t *to, jl_module_t *from, jl_sym_t *s, jl_sym_t *asname);
21132113
JL_DLLEXPORT void jl_module_import(jl_task_t *ct, jl_module_t *to, jl_module_t *from, jl_sym_t *s);
21142114
JL_DLLEXPORT void jl_module_import_as(jl_task_t *ct, jl_module_t *to, jl_module_t *from, jl_sym_t *s, jl_sym_t *asname);
2115-
JL_DLLEXPORT void jl_module_public(jl_module_t *from, jl_sym_t *s, int exported);
2115+
int jl_module_public_(jl_module_t *from, jl_sym_t *s, int exported, size_t new_world);
21162116
JL_DLLEXPORT int jl_is_imported(jl_module_t *m, jl_sym_t *s);
21172117
JL_DLLEXPORT int jl_module_exports_p(jl_module_t *m, jl_sym_t *var);
21182118

src/module.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,12 +1335,10 @@ JL_DLLEXPORT jl_value_t *jl_get_module_binding_or_nothing(jl_module_t *m, jl_sym
13351335
return (jl_value_t*)b;
13361336
}
13371337

1338-
JL_DLLEXPORT void jl_module_public(jl_module_t *from, jl_sym_t *s, int exported)
1338+
int jl_module_public_(jl_module_t *from, jl_sym_t *s, int exported, size_t new_world)
13391339
{
13401340
// caller must hold world_counter_lock
13411341
jl_binding_t *b = jl_get_module_binding(from, s, 1);
1342-
JL_LOCK(&world_counter_lock);
1343-
size_t new_world = jl_atomic_load_acquire(&jl_world_counter)+1;
13441342
jl_binding_partition_t *bpart = jl_get_binding_partition(b, new_world);
13451343
int was_exported = (bpart->kind & PARTITION_FLAG_EXPORTED) != 0;
13461344
if (jl_atomic_load_relaxed(&b->flags) & BINDING_FLAG_PUBLICP) {
@@ -1355,9 +1353,9 @@ JL_DLLEXPORT void jl_module_public(jl_module_t *from, jl_sym_t *s, int exported)
13551353
jl_atomic_fetch_or_relaxed(&b->flags, BINDING_FLAG_PUBLICP);
13561354
if (was_exported != exported) {
13571355
jl_replace_binding_locked2(b, bpart, bpart->restriction, bpart->kind | PARTITION_FLAG_EXPORTED, new_world);
1358-
jl_atomic_store_release(&jl_world_counter, new_world);
1356+
return 1;
13591357
}
1360-
JL_UNLOCK(&world_counter_lock);
1358+
return 0;
13611359
}
13621360

13631361
JL_DLLEXPORT int jl_boundp(jl_module_t *m, jl_sym_t *var, int allow_import) // unlike most queries here, this is currently seq_cst

src/toplevel.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -925,14 +925,29 @@ JL_DLLEXPORT jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_val
925925
}
926926
else if (head == jl_export_sym || head == jl_public_sym) {
927927
int exp = (head == jl_export_sym);
928-
for (size_t i = 0; i < jl_array_nrows(ex->args); i++) {
929-
jl_sym_t *name = (jl_sym_t*)jl_array_ptr_ref(ex->args, i);
930-
if (!jl_is_symbol(name))
931-
jl_eval_errorf(m, *toplevel_filename, *toplevel_lineno,
932-
exp ? "syntax: malformed \"export\" statement" :
933-
"syntax: malformed \"public\" statement");
934-
jl_module_public(m, name, exp);
928+
volatile int any_new = 0;
929+
JL_LOCK(&world_counter_lock);
930+
size_t new_world = jl_atomic_load_acquire(&jl_world_counter)+1;
931+
JL_TRY {
932+
for (size_t i = 0; i < jl_array_nrows(ex->args); i++) {
933+
jl_sym_t *name = (jl_sym_t*)jl_array_ptr_ref(ex->args, i);
934+
if (!jl_is_symbol(name))
935+
jl_eval_errorf(m, *toplevel_filename, *toplevel_lineno,
936+
exp ? "syntax: malformed \"export\" statement" :
937+
"syntax: malformed \"public\" statement");
938+
if (jl_module_public_(m, name, exp, new_world))
939+
any_new = 1;
940+
}
941+
}
942+
JL_CATCH {
943+
if (any_new)
944+
jl_atomic_store_release(&jl_world_counter, new_world);
945+
JL_UNLOCK(&world_counter_lock);
946+
jl_rethrow();
935947
}
948+
if (any_new)
949+
jl_atomic_store_release(&jl_world_counter, new_world);
950+
JL_UNLOCK(&world_counter_lock);
936951
JL_GC_POP();
937952
return jl_nothing;
938953
}

0 commit comments

Comments
 (0)