Skip to content

Commit

Permalink
fix JuliaLang#9799, module init order
Browse files Browse the repository at this point in the history
- still wait until outermost module finishes loading before running
  initializers, but run them innermost-first
- allow a non-Main module to be the "outermost" module
  • Loading branch information
JeffBezanson authored and tkelman committed Jun 6, 2015
1 parent aacc8fe commit 506ecbe
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ jl_value_t *jl_eval_module_expr(jl_expr_t *ex)
{
static arraylist_t module_stack;
static int initialized=0;
static jl_module_t *outermost = NULL;
if (!initialized) {
arraylist_new(&module_stack, 0);
initialized = 1;
Expand Down Expand Up @@ -145,6 +146,10 @@ jl_value_t *jl_eval_module_expr(jl_expr_t *ex)
JL_GC_PUSH1(&last_module);
jl_module_t *task_last_m = jl_current_task->current_module;
jl_current_task->current_module = jl_current_module = newm;
jl_module_t *prev_outermost = outermost;
size_t stackidx = module_stack.len;
if (outermost == NULL)
outermost = newm;

jl_array_t *exprs = ((jl_expr_t*)jl_exprarg(ex, 2))->args;
JL_TRY {
Expand All @@ -157,11 +162,14 @@ jl_value_t *jl_eval_module_expr(jl_expr_t *ex)
JL_CATCH {
jl_current_module = last_module;
jl_current_task->current_module = task_last_m;
outermost = prev_outermost;
module_stack.len = stackidx;
jl_rethrow();
}
JL_GC_POP();
jl_current_module = last_module;
jl_current_task->current_module = task_last_m;
outermost = prev_outermost;

#if 0
// some optional post-processing steps
Expand All @@ -185,10 +193,13 @@ jl_value_t *jl_eval_module_expr(jl_expr_t *ex)

arraylist_push(&module_stack, newm);

if (jl_current_module == jl_main_module) {
while (module_stack.len > 0) {
jl_module_load_time_initialize((jl_module_t *) arraylist_pop(&module_stack));
if (outermost == NULL || jl_current_module == jl_main_module) {
size_t i, l=module_stack.len;
for(i = stackidx; i < l; i++) {
jl_module_load_time_initialize((jl_module_t*)module_stack.items[i]);
}
assert(module_stack.len == l);
module_stack.len = stackidx;
}

return jl_nothing;
Expand Down

0 comments on commit 506ecbe

Please sign in to comment.