@@ -488,20 +488,18 @@ static void body_attributes(jl_array_t *body, int *has_ccall, int *has_defs, int
488
488
}
489
489
490
490
extern size_t jl_require_world ;
491
- static jl_module_t * call_require (jl_module_t * mod , jl_sym_t * var ) JL_GLOBALLY_ROOTED
491
+ static jl_module_t * call_require (jl_task_t * ct , jl_module_t * mod , jl_sym_t * var ) JL_GLOBALLY_ROOTED
492
492
{
493
493
JL_TIMING (LOAD_IMAGE , LOAD_Require );
494
494
jl_timing_printf (JL_TIMING_DEFAULT_BLOCK , "%s" , jl_symbol_name (var ));
495
495
496
496
int build_mode = jl_options .incremental && jl_generating_output ();
497
497
jl_module_t * m = NULL ;
498
- jl_task_t * ct = jl_current_task ;
499
498
static jl_value_t * require_func = NULL ;
500
499
if (require_func == NULL && jl_base_module != NULL ) {
501
500
require_func = jl_get_global (jl_base_module , jl_symbol ("require" ));
502
501
}
503
502
if (require_func != NULL ) {
504
- size_t last_age = ct -> world_age ;
505
503
ct -> world_age = jl_atomic_load_acquire (& jl_world_counter );
506
504
if (build_mode && jl_require_world < ct -> world_age )
507
505
ct -> world_age = jl_require_world ;
@@ -510,18 +508,19 @@ static jl_module_t *call_require(jl_module_t *mod, jl_sym_t *var) JL_GLOBALLY_RO
510
508
reqargs [1 ] = (jl_value_t * )mod ;
511
509
reqargs [2 ] = (jl_value_t * )var ;
512
510
m = (jl_module_t * )jl_apply (reqargs , 3 );
513
- ct -> world_age = last_age ;
514
511
}
515
512
if (m == NULL || !jl_is_module (m )) {
516
513
jl_errorf ("failed to load module %s" , jl_symbol_name (var ));
517
514
}
515
+ ct -> world_age = jl_atomic_load_acquire (& jl_world_counter );
518
516
return m ;
519
517
}
520
518
521
519
// either:
522
520
// - sets *name and returns the module to import *name from
523
521
// - sets *name to NULL and returns a module to import
524
- static jl_module_t * eval_import_path (jl_module_t * where , jl_module_t * from JL_PROPAGATES_ROOT ,
522
+ // also updates world_age
523
+ static jl_module_t * eval_import_path (jl_task_t * ct , jl_module_t * where , jl_module_t * from JL_PROPAGATES_ROOT ,
525
524
jl_array_t * args , jl_sym_t * * name , const char * keyword ) JL_GLOBALLY_ROOTED
526
525
{
527
526
if (jl_array_nrows (args ) == 0 )
@@ -546,7 +545,7 @@ static jl_module_t *eval_import_path(jl_module_t *where, jl_module_t *from JL_PR
546
545
m = jl_base_module ;
547
546
}
548
547
else {
549
- m = call_require (where , var );
548
+ m = call_require (ct , where , var );
550
549
}
551
550
if (i == jl_array_nrows (args ))
552
551
return m ;
@@ -566,6 +565,8 @@ static jl_module_t *eval_import_path(jl_module_t *where, jl_module_t *from JL_PR
566
565
}
567
566
}
568
567
568
+ ct -> world_age = jl_atomic_load_acquire (& jl_world_counter );
569
+
569
570
while (1 ) {
570
571
var = (jl_sym_t * )jl_array_ptr_ref (args , i );
571
572
if (!jl_is_symbol (var ))
@@ -650,17 +651,17 @@ JL_DLLEXPORT jl_method_instance_t *jl_method_instance_for_thunk(jl_code_info_t *
650
651
return mi ;
651
652
}
652
653
653
- static void import_module (jl_module_t * JL_NONNULL m , jl_module_t * import , jl_sym_t * asname )
654
+ static void import_module (jl_task_t * ct , jl_module_t * JL_NONNULL m , jl_module_t * import , jl_sym_t * asname )
654
655
{
655
656
assert (m );
656
657
jl_sym_t * name = asname ? asname : import -> name ;
657
658
// TODO: this is a bit race-y with what error message we might print
658
659
jl_binding_t * b = jl_get_module_binding (m , name , 1 );
659
- jl_binding_partition_t * bpart = jl_get_binding_partition (b , jl_current_task -> world_age );
660
+ jl_binding_partition_t * bpart = jl_get_binding_partition (b , ct -> world_age );
660
661
enum jl_partition_kind kind = jl_binding_kind (bpart );
661
662
if (kind != BINDING_KIND_GUARD && kind != BINDING_KIND_FAILED && kind != BINDING_KIND_DECLARED && kind != BINDING_KIND_IMPLICIT ) {
662
663
// Unlike regular constant declaration, we allow this as long as we eventually end up at a constant.
663
- jl_walk_binding_inplace (& b , & bpart , jl_current_task -> world_age );
664
+ jl_walk_binding_inplace (& b , & bpart , ct -> world_age );
664
665
if (jl_binding_kind (bpart ) == BINDING_KIND_CONST || jl_binding_kind (bpart ) == BINDING_KIND_BACKDATED_CONST || jl_binding_kind (bpart ) == BINDING_KIND_CONST_IMPORT ) {
665
666
// Already declared (e.g. on another thread) or imported.
666
667
if (bpart -> restriction == (jl_value_t * )import )
@@ -673,7 +674,7 @@ static void import_module(jl_module_t *JL_NONNULL m, jl_module_t *import, jl_sym
673
674
}
674
675
675
676
// in `import A.B: x, y, ...`, evaluate the `A.B` part if it exists
676
- static jl_module_t * eval_import_from (jl_module_t * m JL_PROPAGATES_ROOT , jl_expr_t * ex , const char * keyword )
677
+ static jl_module_t * eval_import_from (jl_task_t * ct , jl_module_t * m JL_PROPAGATES_ROOT , jl_expr_t * ex , const char * keyword )
677
678
{
678
679
if (jl_expr_nargs (ex ) == 1 && jl_is_expr (jl_exprarg (ex , 0 ))) {
679
680
jl_expr_t * fr = (jl_expr_t * )jl_exprarg (ex , 0 );
@@ -682,7 +683,7 @@ static jl_module_t *eval_import_from(jl_module_t *m JL_PROPAGATES_ROOT, jl_expr_
682
683
jl_expr_t * path = (jl_expr_t * )jl_exprarg (fr , 0 );
683
684
if (((jl_expr_t * )path )-> head == jl_dot_sym ) {
684
685
jl_sym_t * name = NULL ;
685
- jl_module_t * from = eval_import_path (m , NULL , path -> args , & name , keyword );
686
+ jl_module_t * from = eval_import_path (ct , m , NULL , path -> args , & name , keyword );
686
687
if (name != NULL ) {
687
688
from = (jl_module_t * )jl_eval_global_var (from , name );
688
689
if (!from || !jl_is_module (from ))
@@ -828,8 +829,7 @@ JL_DLLEXPORT jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_val
828
829
}
829
830
else if (head == jl_using_sym ) {
830
831
jl_sym_t * name = NULL ;
831
- jl_module_t * from = eval_import_from (m , ex , "using" );
832
- ct -> world_age = jl_atomic_load_acquire (& jl_world_counter );
832
+ jl_module_t * from = eval_import_from (ct , m , ex , "using" );
833
833
size_t i = 0 ;
834
834
if (from ) {
835
835
i = 1 ;
@@ -839,10 +839,10 @@ JL_DLLEXPORT jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_val
839
839
jl_value_t * a = jl_exprarg (ex , i );
840
840
if (jl_is_expr (a ) && ((jl_expr_t * )a )-> head == jl_dot_sym ) {
841
841
name = NULL ;
842
- jl_module_t * import = eval_import_path (m , from , ((jl_expr_t * )a )-> args , & name , "using" );
842
+ jl_module_t * import = eval_import_path (ct , m , from , ((jl_expr_t * )a )-> args , & name , "using" );
843
843
if (from ) {
844
844
// `using A: B` and `using A: B.c` syntax
845
- jl_module_use (m , import , name );
845
+ jl_module_use (ct , m , import , name );
846
846
}
847
847
else {
848
848
jl_module_t * u = import ;
@@ -857,7 +857,7 @@ JL_DLLEXPORT jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_val
857
857
if (m == jl_main_module && name == NULL ) {
858
858
// TODO: for now, `using A` in Main also creates an explicit binding for `A`
859
859
// This will possibly be extended to all modules.
860
- import_module (m , u , NULL );
860
+ import_module (ct , m , u , NULL );
861
861
}
862
862
}
863
863
continue ;
@@ -868,12 +868,11 @@ JL_DLLEXPORT jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_val
868
868
if (jl_is_symbol (asname )) {
869
869
jl_expr_t * path = (jl_expr_t * )jl_exprarg (a , 0 );
870
870
name = NULL ;
871
- jl_module_t * import = eval_import_path (m , from , ((jl_expr_t * )path )-> args , & name , "using" );
872
- ct -> world_age = jl_atomic_load_acquire (& jl_world_counter );
871
+ jl_module_t * import = eval_import_path (ct , m , from , ((jl_expr_t * )path )-> args , & name , "using" );
873
872
assert (name );
874
873
check_macro_rename (name , asname , "using" );
875
874
// `using A: B as C` syntax
876
- jl_module_use_as (m , import , name , asname );
875
+ jl_module_use_as (ct , m , import , name , asname );
877
876
continue ;
878
877
}
879
878
}
@@ -886,8 +885,7 @@ JL_DLLEXPORT jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_val
886
885
}
887
886
else if (head == jl_import_sym ) {
888
887
jl_sym_t * name = NULL ;
889
- jl_module_t * from = eval_import_from (m , ex , "import" );
890
- ct -> world_age = jl_atomic_load_acquire (& jl_world_counter );
888
+ jl_module_t * from = eval_import_from (ct , m , ex , "import" );
891
889
size_t i = 0 ;
892
890
if (from ) {
893
891
i = 1 ;
@@ -897,14 +895,14 @@ JL_DLLEXPORT jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_val
897
895
jl_value_t * a = jl_exprarg (ex , i );
898
896
if (jl_is_expr (a ) && ((jl_expr_t * )a )-> head == jl_dot_sym ) {
899
897
name = NULL ;
900
- jl_module_t * import = eval_import_path (m , from , ((jl_expr_t * )a )-> args , & name , "import" );
898
+ jl_module_t * import = eval_import_path (ct , m , from , ((jl_expr_t * )a )-> args , & name , "import" );
901
899
if (name == NULL ) {
902
900
// `import A` syntax
903
- import_module (m , import , NULL );
901
+ import_module (ct , m , import , NULL );
904
902
}
905
903
else {
906
904
// `import A.B` or `import A: B` syntax
907
- jl_module_import (m , import , name );
905
+ jl_module_import (ct , m , import , name );
908
906
}
909
907
continue ;
910
908
}
@@ -914,15 +912,15 @@ JL_DLLEXPORT jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_val
914
912
if (jl_is_symbol (asname )) {
915
913
jl_expr_t * path = (jl_expr_t * )jl_exprarg (a , 0 );
916
914
name = NULL ;
917
- jl_module_t * import = eval_import_path (m , from , ((jl_expr_t * )path )-> args , & name , "import" );
915
+ jl_module_t * import = eval_import_path (ct , m , from , ((jl_expr_t * )path )-> args , & name , "import" );
918
916
if (name == NULL ) {
919
917
// `import A as B` syntax
920
- import_module (m , import , asname );
918
+ import_module (ct , m , import , asname );
921
919
}
922
920
else {
923
921
check_macro_rename (name , asname , "import" );
924
922
// `import A.B as C` syntax
925
- jl_module_import_as (m , import , name , asname );
923
+ jl_module_import_as (ct , m , import , name , asname );
926
924
}
927
925
continue ;
928
926
}
0 commit comments