@@ -3435,26 +3435,33 @@ static jl_value_t *jl_ensure_rooted(jl_codectx_t &ctx, jl_value_t *val)
34353435
34363436// --- generating function calls ---
34373437
3438+ static jl_cgval_t emit_globalref_runtime (jl_codectx_t &ctx, jl_binding_t *bnd, jl_module_t *mod, jl_sym_t *name)
3439+ {
3440+ Value *bp = julia_binding_gv (ctx, bnd);
3441+ Value *v = ctx.builder .CreateCall (prepare_call (jlgetbindingvalue_func), { bp });
3442+ undef_var_error_ifnot (ctx, ctx.builder .CreateIsNotNull (v), name, (jl_value_t *)mod);
3443+ return mark_julia_type (ctx, v, true , jl_any_type);
3444+ }
3445+
34383446static jl_cgval_t emit_globalref (jl_codectx_t &ctx, jl_module_t *mod, jl_sym_t *name, AtomicOrdering order)
34393447{
34403448 jl_binding_t *bnd = jl_get_module_binding (mod, name, 1 );
3441- jl_binding_partition_t *bpart = jl_get_binding_partition (bnd, ctx.max_world );
3449+ assert (bnd);
3450+ jl_binding_partition_t *bpart = jl_get_binding_partition_all (bnd, ctx.min_world , ctx.max_world );
3451+ if (!bpart) {
3452+ return emit_globalref_runtime (ctx, bnd, mod, name);
3453+ }
34423454 jl_ptr_kind_union_t pku = jl_atomic_load_relaxed (&bpart->restriction );
34433455 if (jl_bkind_is_some_guard (decode_restriction_kind (pku))) {
34443456 // try to look this up now.
34453457 // TODO: This is bad and we'd like to delete it.
34463458 jl_get_binding (mod, name);
34473459 }
3448- assert (bnd);
3449- Value *bp = NULL ;
34503460 // bpart was updated in place - this will change with full partition
34513461 pku = jl_atomic_load_acquire (&bpart->restriction );
34523462 if (jl_bkind_is_some_guard (decode_restriction_kind (pku))) {
34533463 // Redo the lookup at runtime
3454- bp = julia_binding_gv (ctx, bnd);
3455- Value *v = ctx.builder .CreateCall (prepare_call (jlgetbindingvalue_func), { bp });
3456- undef_var_error_ifnot (ctx, ctx.builder .CreateIsNotNull (v), name, (jl_value_t *)mod);
3457- return mark_julia_type (ctx, v, true , jl_any_type);
3464+ return emit_globalref_runtime (ctx, bnd, mod, name);
34583465 } else {
34593466 while (true ) {
34603467 if (!bpart)
@@ -3465,7 +3472,9 @@ static jl_cgval_t emit_globalref(jl_codectx_t &ctx, jl_module_t *mod, jl_sym_t *
34653472 cg_bdw (ctx, name, bnd);
34663473 }
34673474 bnd = (jl_binding_t *)decode_restriction_value (pku);
3468- bpart = jl_get_binding_partition (bnd, ctx.max_world );
3475+ bpart = jl_get_binding_partition_all (bnd, ctx.min_world , ctx.max_world );
3476+ if (!bpart)
3477+ break ;
34693478 pku = jl_atomic_load_acquire (&bpart->restriction );
34703479 }
34713480 if (bpart && jl_bkind_is_some_constant (decode_restriction_kind (pku))) {
@@ -3477,7 +3486,10 @@ static jl_cgval_t emit_globalref(jl_codectx_t &ctx, jl_module_t *mod, jl_sym_t *
34773486 return mark_julia_const (ctx, constval);
34783487 }
34793488 }
3480- bp = julia_binding_gv (ctx, bnd);
3489+ if (!bpart) {
3490+ return emit_globalref_runtime (ctx, bnd, mod, name);
3491+ }
3492+ Value *bp = julia_binding_gv (ctx, bnd);
34813493 if (bnd->deprecated ) {
34823494 cg_bdw (ctx, name, bnd);
34833495 }
@@ -3496,7 +3508,7 @@ static jl_cgval_t emit_globalop(jl_codectx_t &ctx, jl_module_t *mod, jl_sym_t *s
34963508{
34973509 jl_binding_t *bnd = NULL ;
34983510 Value *bp = global_binding_pointer (ctx, mod, sym, &bnd, true , alloc);
3499- jl_binding_partition_t *bpart = jl_get_binding_partition (bnd, ctx.max_world );
3511+ jl_binding_partition_t *bpart = jl_get_binding_partition_all (bnd, ctx. min_world , ctx.max_world );
35003512 if (bp == NULL )
35013513 return jl_cgval_t ();
35023514 if (bpart) {
@@ -5854,7 +5866,7 @@ static Value *global_binding_pointer(jl_codectx_t &ctx, jl_module_t *m, jl_sym_t
58545866 jl_binding_t **pbnd, bool assign, bool alloc)
58555867{
58565868 jl_binding_t *b = jl_get_module_binding (m, s, 1 );
5857- jl_binding_partition_t *bpart = jl_get_binding_partition (b , ctx.max_world );
5869+ jl_binding_partition_t *bpart = jl_get_binding_partition_all (b, ctx. min_world , ctx.max_world );
58585870 jl_ptr_kind_union_t pku = jl_atomic_load_relaxed (&bpart->restriction );
58595871 if (assign) {
58605872 if (jl_bkind_is_some_guard (decode_restriction_kind (pku)))
@@ -5865,11 +5877,11 @@ static Value *global_binding_pointer(jl_codectx_t &ctx, jl_module_t *m, jl_sym_t
58655877 if (jl_bkind_is_some_guard (decode_restriction_kind (pku))) {
58665878 // try to look this up now
58675879 b = jl_get_binding (m, s);
5868- bpart = jl_get_binding_partition (b , ctx.max_world );
5880+ bpart = jl_get_binding_partition_all (b, ctx. min_world , ctx.max_world );
58695881 }
5870- pku = jl_walk_binding_inplace (&b, &bpart, ctx.max_world );
5882+ pku = jl_walk_binding_inplace_all (&b, &bpart, ctx. min_world , ctx.max_world );
58715883 }
5872- if (b == NULL ) {
5884+ if (!b || !bpart ) {
58735885 // var not found. switch to delayed lookup.
58745886 Constant *initnul = Constant::getNullValue (ctx.types ().T_pjlvalue );
58755887 GlobalVariable *bindinggv = new GlobalVariable (*ctx.f ->getParent (), ctx.types ().T_pjlvalue ,
@@ -6021,7 +6033,7 @@ static jl_cgval_t emit_isdefined(jl_codectx_t &ctx, jl_value_t *sym, int allow_i
60216033 name = (jl_sym_t *)sym;
60226034 }
60236035 jl_binding_t *bnd = allow_import ? jl_get_binding (modu, name) : jl_get_module_binding (modu, name, 0 );
6024- jl_binding_partition_t *bpart = jl_get_binding_partition (bnd, ctx.min_world );
6036+ jl_binding_partition_t *bpart = jl_get_binding_partition_all (bnd, ctx.min_world , ctx. max_world );
60256037 jl_ptr_kind_union_t pku = bpart ? jl_atomic_load_relaxed (&bpart->restriction ) : encode_restriction (NULL , BINDING_KIND_GUARD);
60266038 if (decode_restriction_kind (pku) == BINDING_KIND_GLOBAL || jl_bkind_is_some_constant (decode_restriction_kind (pku))) {
60276039 if (jl_get_binding_value_if_const (bnd))
0 commit comments