@@ -908,13 +908,12 @@ static const auto jldeclareglobal_func = new JuliaFunction<>{
908908 {T_pjlvalue, T_pjlvalue, T_prjlvalue, getInt32Ty (C)}, false ); },
909909 nullptr ,
910910};
911- static const auto jlgetbindingorerror_func = new JuliaFunction<>{
912- XSTR (jl_get_binding_or_error ),
911+ static const auto jldepcheck_func = new JuliaFunction<>{
912+ XSTR (jl_binding_deprecation_check ),
913913 [](LLVMContext &C) {
914914 auto T_pjlvalue = JuliaType::get_pjlvalue_ty (C);
915- return FunctionType::get (T_pjlvalue,
916- {T_pjlvalue, T_pjlvalue}, false );
917- },
915+ return FunctionType::get (getVoidTy (C),
916+ {T_pjlvalue}, false ); },
918917 nullptr ,
919918};
920919static const auto jlcheckbpwritable_func = new JuliaFunction<>{
@@ -2894,20 +2893,6 @@ static void mallocVisitLine(jl_codectx_t &ctx, StringRef filename, int line, Val
28942893
28952894// --- constant determination ---
28962895
2897- static void show_source_loc (jl_codectx_t &ctx, JL_STREAM *out)
2898- {
2899- jl_printf (out, " in %s at %s" , ctx.name , ctx.file .str ().c_str ());
2900- }
2901-
2902- static void cg_bdw (jl_codectx_t &ctx, jl_sym_t *var, jl_binding_t *b)
2903- {
2904- jl_binding_deprecation_warning (ctx.module , var, b);
2905- if (b->deprecated == 1 && jl_options.depwarn ) {
2906- show_source_loc (ctx, JL_STDERR);
2907- jl_printf (JL_STDERR, " \n " );
2908- }
2909- }
2910-
29112896static jl_value_t *static_apply_type (jl_codectx_t &ctx, ArrayRef<jl_cgval_t > args, size_t nargs)
29122897{
29132898 assert (nargs > 1 );
@@ -2932,6 +2917,12 @@ static jl_value_t *static_apply_type(jl_codectx_t &ctx, ArrayRef<jl_cgval_t> arg
29322917 return result;
29332918}
29342919
2920+ static void emit_depwarn_check (jl_codectx_t &ctx, jl_binding_t *b)
2921+ {
2922+ Value *bp = julia_binding_gv (ctx, b);
2923+ ctx.builder .CreateCall (prepare_call (jldepcheck_func), { bp });
2924+ }
2925+
29352926// try to statically evaluate, NULL if not possible. note that this may allocate, and as
29362927// such the resulting value should not be embedded directly in the generated code.
29372928static jl_value_t *static_eval (jl_codectx_t &ctx, jl_value_t *ex)
@@ -2940,9 +2931,13 @@ static jl_value_t *static_eval(jl_codectx_t &ctx, jl_value_t *ex)
29402931 jl_sym_t *sym = (jl_sym_t *)ex;
29412932 jl_binding_t *bnd = jl_get_module_binding (ctx.module , sym, 0 );
29422933 jl_binding_partition_t *bpart = jl_get_binding_partition_all (bnd, ctx.min_world , ctx.max_world );
2943- jl_walk_binding_inplace_all (&bnd, &bpart, ctx.min_world , ctx.max_world );
2944- if (bpart && jl_bkind_is_some_constant (jl_binding_kind (bpart)))
2934+ int possibly_deprecated = 0 ;
2935+ jl_walk_binding_inplace_all (&bnd, &bpart, &possibly_deprecated, ctx.min_world , ctx.max_world );
2936+ if (bpart && jl_bkind_is_some_constant (jl_binding_kind (bpart))) {
2937+ if (possibly_deprecated)
2938+ emit_depwarn_check (ctx, bnd);
29452939 return bpart->restriction ;
2940+ }
29462941 return NULL ;
29472942 }
29482943 if (jl_is_slotnumber (ex) || jl_is_argument (ex))
@@ -2965,13 +2960,14 @@ static jl_value_t *static_eval(jl_codectx_t &ctx, jl_value_t *ex)
29652960 s = jl_globalref_name (ex);
29662961 jl_binding_t *bnd = jl_get_module_binding (jl_globalref_mod (ex), s, 0 );
29672962 jl_binding_partition_t *bpart = jl_get_binding_partition_all (bnd, ctx.min_world , ctx.max_world );
2968- jl_walk_binding_inplace_all (&bnd, &bpart, ctx.min_world , ctx.max_world );
2963+ int possibly_deprecated = 0 ;
2964+ jl_walk_binding_inplace_all (&bnd, &bpart, &possibly_deprecated, ctx.min_world , ctx.max_world );
29692965 jl_value_t *v = NULL ;
29702966 if (bpart && jl_bkind_is_some_constant (jl_binding_kind (bpart)))
29712967 v = bpart->restriction ;
29722968 if (v) {
2973- if (bnd-> deprecated )
2974- cg_bdw (ctx, s , bnd);
2969+ if (possibly_deprecated )
2970+ emit_depwarn_check (ctx, bnd);
29752971 return v;
29762972 }
29772973 return NULL ;
@@ -2992,13 +2988,14 @@ static jl_value_t *static_eval(jl_codectx_t &ctx, jl_value_t *ex)
29922988 if (s && jl_is_symbol (s)) {
29932989 jl_binding_t *bnd = jl_get_module_binding (m, s, 0 );
29942990 jl_binding_partition_t *bpart = jl_get_binding_partition_all (bnd, ctx.min_world , ctx.max_world );
2995- jl_walk_binding_inplace_all (&bnd, &bpart, ctx.min_world , ctx.max_world );
2991+ int possibly_deprecated = 0 ;
2992+ jl_walk_binding_inplace_all (&bnd, &bpart, &possibly_deprecated, ctx.min_world , ctx.max_world );
29962993 jl_value_t *v = NULL ;
29972994 if (bpart && jl_bkind_is_some_constant (jl_binding_kind (bpart)))
29982995 v = bpart->restriction ;
29992996 if (v) {
3000- if (bnd-> deprecated )
3001- cg_bdw (ctx, s , bnd);
2997+ if (possibly_deprecated )
2998+ emit_depwarn_check (ctx, bnd);
30022999 return v;
30033000 }
30043001 }
@@ -3244,48 +3241,47 @@ static jl_cgval_t emit_globalref(jl_codectx_t &ctx, jl_module_t *mod, jl_sym_t *
32443241 if (!bpart) {
32453242 return emit_globalref_runtime (ctx, bnd, mod, name);
32463243 }
3247- // bpart was updated in place - this will change with full partition
3248- if (jl_bkind_is_some_guard (jl_binding_kind (bpart))) {
3249- // Redo the lookup at runtime
3250- return emit_globalref_runtime (ctx, bnd, mod, name);
3251- } else {
3252- while (true ) {
3253- if (!bpart)
3254- break ;
3255- if (!jl_bkind_is_some_import (jl_binding_kind (bpart)))
3256- break ;
3257- if (bnd->deprecated ) {
3258- cg_bdw (ctx, name, bnd);
3259- }
3260- bnd = (jl_binding_t *)bpart->restriction ;
3261- bpart = jl_get_binding_partition_all (bnd, ctx.min_world , ctx.max_world );
3262- if (!bpart)
3263- break ;
3264- }
3265- if (bpart) {
3266- enum jl_partition_kind kind = jl_binding_kind (bpart);
3267- if (jl_bkind_is_some_constant (kind) && kind != BINDING_KIND_BACKDATED_CONST) {
3268- jl_value_t *constval = bpart->restriction ;
3269- if (!constval) {
3270- undef_var_error_ifnot (ctx, ConstantInt::get (getInt1Ty (ctx.builder .getContext ()), 0 ), name, (jl_value_t *)mod);
3271- return jl_cgval_t ();
3272- }
3273- return mark_julia_const (ctx, constval);
3244+ int possibly_deprecated = 0 ;
3245+ int saw_explicit = 0 ;
3246+ while (bpart) {
3247+ if (!saw_explicit && (bpart->kind & BINDING_FLAG_DEPWARN))
3248+ possibly_deprecated = 1 ;
3249+ enum jl_partition_kind kind = jl_binding_kind (bpart);
3250+ if (!jl_bkind_is_some_import (kind))
3251+ break ;
3252+ if (kind != BINDING_KIND_IMPLICIT)
3253+ saw_explicit = 1 ;
3254+ bnd = (jl_binding_t *)bpart->restriction ;
3255+ bpart = jl_get_binding_partition_all (bnd, ctx.min_world , ctx.max_world );
3256+ }
3257+ Value *bp = NULL ;
3258+ if (bpart) {
3259+ enum jl_partition_kind kind = jl_binding_kind (bpart);
3260+ if (jl_bkind_is_some_constant (kind) && kind != BINDING_KIND_BACKDATED_CONST) {
3261+ if (possibly_deprecated) {
3262+ bp = julia_binding_gv (ctx, bnd);
3263+ ctx.builder .CreateCall (prepare_call (jldepcheck_func), { bp });
3264+ }
3265+ jl_value_t *constval = bpart->restriction ;
3266+ if (!constval) {
3267+ undef_var_error_ifnot (ctx, ConstantInt::get (getInt1Ty (ctx.builder .getContext ()), 0 ), name, (jl_value_t *)mod);
3268+ return jl_cgval_t ();
32743269 }
3270+ return mark_julia_const (ctx, constval);
32753271 }
32763272 }
32773273 if (!bpart || jl_binding_kind (bpart) != BINDING_KIND_GLOBAL) {
32783274 return emit_globalref_runtime (ctx, bnd, mod, name);
32793275 }
3280- Value * bp = julia_binding_gv (ctx, bnd);
3281- if (bnd-> deprecated ) {
3282- cg_bdw ( ctx, name, bnd );
3276+ bp = julia_binding_gv (ctx, bnd);
3277+ if (possibly_deprecated ) {
3278+ ctx. builder . CreateCall ( prepare_call (jldepcheck_func), { bp } );
32833279 }
32843280 jl_value_t *ty = bpart->restriction ;
3285- bp = julia_binding_pvalue (ctx, bp);
3281+ Value *bpval = julia_binding_pvalue (ctx, bp);
32863282 if (ty == nullptr )
32873283 ty = (jl_value_t *)jl_any_type;
3288- return update_julia_type (ctx, emit_checked_var (ctx, bp , name, (jl_value_t *)mod, false , ctx.tbaa ().tbaa_binding ), ty);
3284+ return update_julia_type (ctx, emit_checked_var (ctx, bpval , name, (jl_value_t *)mod, false , ctx.tbaa ().tbaa_binding ), ty);
32893285}
32903286
32913287static jl_cgval_t emit_globalop (jl_codectx_t &ctx, jl_module_t *mod, jl_sym_t *sym, jl_cgval_t rval, const jl_cgval_t &cmp,
@@ -3298,6 +3294,7 @@ static jl_cgval_t emit_globalop(jl_codectx_t &ctx, jl_module_t *mod, jl_sym_t *s
32983294 Value *bp = julia_binding_gv (ctx, bnd);
32993295 if (bpart) {
33003296 if (jl_binding_kind (bpart) == BINDING_KIND_GLOBAL) {
3297+ int possibly_deprecated = bpart->kind & BINDING_FLAG_DEPWARN;
33013298 jl_value_t *ty = bpart->restriction ;
33023299 if (ty != nullptr ) {
33033300 const std::string fname = issetglobal ? " setglobal!" : isreplaceglobal ? " replaceglobal!" : isswapglobal ? " swapglobal!" : ismodifyglobal ? " modifyglobal!" : " setglobalonce!" ;
@@ -3310,6 +3307,9 @@ static jl_cgval_t emit_globalop(jl_codectx_t &ctx, jl_module_t *mod, jl_sym_t *s
33103307 }
33113308 bool isboxed = true ;
33123309 bool maybe_null = jl_atomic_load_relaxed (&bnd->value ) == NULL ;
3310+ if (possibly_deprecated) {
3311+ ctx.builder .CreateCall (prepare_call (jldepcheck_func), { bp });
3312+ }
33133313 return typed_store (ctx,
33143314 julia_binding_pvalue (ctx, bp),
33153315 rval, cmp, ty,
@@ -9913,7 +9913,6 @@ static void init_jit_functions(void)
99139913 add_named_global (memcmp_func, &memcmp);
99149914 add_named_global (jltypeerror_func, &jl_type_error);
99159915 add_named_global (jlcheckassign_func, &jl_checked_assignment);
9916- add_named_global (jlgetbindingorerror_func, &jl_get_binding_or_error);
99179916 add_named_global (jlcheckbpwritable_func, &jl_check_binding_currently_writable);
99189917 add_named_global (jlboundp_func, &jl_boundp);
99199918 for (auto it : builtin_func_map ())
0 commit comments