Skip to content

Commit 7270004

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 31f1e22 commit 7270004

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,11 +1335,9 @@ 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
jl_binding_t *b = jl_get_module_binding(from, s, 1);
1341-
JL_LOCK(&world_counter_lock);
1342-
size_t new_world = jl_atomic_load_acquire(&jl_world_counter)+1;
13431341
jl_binding_partition_t *bpart = jl_get_binding_partition(b, new_world);
13441342
int was_exported = (bpart->kind & PARTITION_FLAG_EXPORTED) != 0;
13451343
if (jl_atomic_load_relaxed(&b->flags) & BINDING_FLAG_PUBLICP) {
@@ -1354,9 +1352,9 @@ JL_DLLEXPORT void jl_module_public(jl_module_t *from, jl_sym_t *s, int exported)
13541352
jl_atomic_fetch_or_relaxed(&b->flags, BINDING_FLAG_PUBLICP);
13551353
if (was_exported != exported) {
13561354
jl_replace_binding_locked2(b, bpart, bpart->restriction, bpart->kind | PARTITION_FLAG_EXPORTED, new_world);
1357-
jl_atomic_store_release(&jl_world_counter, new_world);
1355+
return 1;
13581356
}
1359-
JL_UNLOCK(&world_counter_lock);
1357+
return 0;
13601358
}
13611359

13621360
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
@@ -924,14 +924,29 @@ JL_DLLEXPORT jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_val
924924
}
925925
else if (head == jl_export_sym || head == jl_public_sym) {
926926
int exp = (head == jl_export_sym);
927-
for (size_t i = 0; i < jl_array_nrows(ex->args); i++) {
928-
jl_sym_t *name = (jl_sym_t*)jl_array_ptr_ref(ex->args, i);
929-
if (!jl_is_symbol(name))
930-
jl_eval_errorf(m, *toplevel_filename, *toplevel_lineno,
931-
exp ? "syntax: malformed \"export\" statement" :
932-
"syntax: malformed \"public\" statement");
933-
jl_module_public(m, name, exp);
927+
volatile int any_new = 0;
928+
JL_LOCK(&world_counter_lock);
929+
size_t new_world = jl_atomic_load_acquire(&jl_world_counter)+1;
930+
JL_TRY {
931+
for (size_t i = 0; i < jl_array_nrows(ex->args); i++) {
932+
jl_sym_t *name = (jl_sym_t*)jl_array_ptr_ref(ex->args, i);
933+
if (!jl_is_symbol(name))
934+
jl_eval_errorf(m, *toplevel_filename, *toplevel_lineno,
935+
exp ? "syntax: malformed \"export\" statement" :
936+
"syntax: malformed \"public\" statement");
937+
if (jl_module_public_(m, name, exp, new_world))
938+
any_new = 1;
939+
}
940+
}
941+
JL_CATCH {
942+
if (any_new)
943+
jl_atomic_store_release(&jl_world_counter, new_world);
944+
JL_UNLOCK(&world_counter_lock);
945+
jl_rethrow();
934946
}
947+
if (any_new)
948+
jl_atomic_store_release(&jl_world_counter, new_world);
949+
JL_UNLOCK(&world_counter_lock);
935950
JL_GC_POP();
936951
return jl_nothing;
937952
}

0 commit comments

Comments
 (0)