Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Compiler/src/Compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ using Core: ABIOverride, Builtin, CodeInstance, IntrinsicFunction, MethodInstanc

using Base
using Base: @_foldable_meta, @_gc_preserve_begin, @_gc_preserve_end, @nospecializeinfer,
BINDING_KIND_GLOBAL, BINDING_KIND_UNDEF_CONST, BINDING_KIND_BACKDATED_CONST, BINDING_KIND_DECLARED,
BINDING_FLAG_DEPWARN,
PARTITION_KIND_GLOBAL, PARTITION_KIND_UNDEF_CONST, PARTITION_KIND_BACKDATED_CONST, PARTITION_KIND_DECLARED,
PARTITION_FLAG_DEPWARN,
Base, BitVector, Bottom, Callable, DataTypeFieldDesc,
EffectsOverride, Filter, Generator, IteratorSize, JLOptions, NUM_EFFECTS_OVERRIDES,
OneTo, Ordering, RefValue, SizeUnknown, _NAMEDTUPLE_NAME,
Expand Down
16 changes: 8 additions & 8 deletions Compiler/src/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2441,7 +2441,7 @@ end
(valid_worlds, rt) = scan_leaf_partitions(interp, gr, sv.world) do interp, _, partition
local rt
kind = binding_kind(partition)
if is_some_guard(kind) || kind == BINDING_KIND_DECLARED
if is_some_guard(kind) || kind == PARTITION_KIND_DECLARED
# We do not currently assume an invalidation for guard -> defined transitions
# rt = Const(nothing)
rt = Type
Expand Down Expand Up @@ -2572,7 +2572,7 @@ function abstract_eval_replaceglobal!(interp::AbstractInterpreter, sv::AbsIntSta
(valid_worlds, (rte, T)) = scan_leaf_partitions(interp, gr, sv.world) do interp, _, partition
partition_T = nothing
partition_rte = abstract_eval_partition_load(interp, partition)
if binding_kind(partition) == BINDING_KIND_GLOBAL
if binding_kind(partition) == PARTITION_KIND_GLOBAL
partition_T = partition_restriction(partition)
end
partition_exct = Union{partition_rte.exct, global_assignment_binding_rt_exct(interp, partition, v)[2]}
Expand Down Expand Up @@ -3552,9 +3552,9 @@ abstract_eval_partition_load(interp::Union{AbstractInterpreter, Nothing}, ::Core
abstract_eval_partition_load(interp, partition)
function abstract_eval_partition_load(interp::Union{AbstractInterpreter, Nothing}, partition::Core.BindingPartition)
kind = binding_kind(partition)
isdepwarn = (partition.kind & BINDING_FLAG_DEPWARN) != 0
isdepwarn = (partition.kind & PARTITION_FLAG_DEPWARN) != 0
local_getglobal_effects = Effects(generic_getglobal_effects, effect_free=isdepwarn ? ALWAYS_FALSE : ALWAYS_TRUE)
if is_some_guard(kind) || kind == BINDING_KIND_UNDEF_CONST
if is_some_guard(kind) || kind == PARTITION_KIND_UNDEF_CONST
if interp !== nothing && InferenceParams(interp).assume_bindings_static
return RTEffects(Union{}, UndefVarError, EFFECTS_THROWS)
else
Expand All @@ -3565,7 +3565,7 @@ function abstract_eval_partition_load(interp::Union{AbstractInterpreter, Nothing
end

if is_defined_const_binding(kind)
if kind == BINDING_KIND_BACKDATED_CONST
if kind == PARTITION_KIND_BACKDATED_CONST
# Infer this as guard. We do not want a later const definition to retroactively improve
# inference results in an earlier world.
return RTEffects(Any, UndefVarError, local_getglobal_effects)
Expand All @@ -3576,7 +3576,7 @@ function abstract_eval_partition_load(interp::Union{AbstractInterpreter, Nothing
effect_free=isdepwarn ? ALWAYS_FALSE : ALWAYS_TRUE))
end

if kind == BINDING_KIND_DECLARED
if kind == PARTITION_KIND_DECLARED
# Could be replaced by a backdated const which has an effect, so we can't assume it won't.
# Besides, we would prefer not to merge the world range for this into the world range for
# _GLOBAL, because that would pessimize codegen.
Expand Down Expand Up @@ -3643,7 +3643,7 @@ function abstract_eval_globalref(interp, g::GlobalRef, saw_latestworld::Bool, sv
# binding we end up reaching such that codegen can emit a simpler pointer load.
Pair{RTEffects, Union{Nothing, Core.Binding}}(
abstract_eval_partition_load(interp, partition),
binding_kind(partition) in (BINDING_KIND_GLOBAL, BINDING_KIND_DECLARED) ? binding : nothing)
binding_kind(partition) in (PARTITION_KIND_GLOBAL, PARTITION_KIND_DECLARED) ? binding : nothing)
end
update_valid_age!(sv, valid_worlds)
if ret.rt !== Union{} && ret.exct === UndefVarError && binding_if_global !== nothing && InferenceParams(interp).assume_bindings_static
Expand Down Expand Up @@ -3672,7 +3672,7 @@ function global_assignment_binding_rt_exct(interp::AbstractInterpreter, partitio
elseif is_some_const_binding(kind) || is_some_imported(kind)
return Pair{Any,Any}(Bottom, ErrorException)
end
ty = kind == BINDING_KIND_DECLARED ? Any : partition_restriction(partition)
ty = kind == PARTITION_KIND_DECLARED ? Any : partition_restriction(partition)
wnewty = widenconst(newty)
if !hasintersect(wnewty, ty)
return Pair{Any,Any}(Bottom, TypeError)
Expand Down
4 changes: 2 additions & 2 deletions base/invalidation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function invalidate_code_for_globalref!(b::Core.Binding, invalidated_bpart::Core
end
end
end
if (invalidated_bpart.kind & BINDING_FLAG_EXPORTED != 0) || (new_bpart !== nothing && (new_bpart.kind & BINDING_FLAG_EXPORTED != 0))
if (invalidated_bpart.kind & PARTITION_FLAG_EXPORTED != 0) || (new_bpart !== nothing && (new_bpart.kind & PARTITION_FLAG_EXPORTED != 0))
# This binding was exported - we need to check all modules that `using` us to see if they
# have a binding that is affected by this change.
usings_backedges = ccall(:jl_get_module_usings_backedges, Any, (Any,), gr.mod)
Expand All @@ -151,7 +151,7 @@ function invalidate_code_for_globalref!(b::Core.Binding, invalidated_bpart::Core
isdefined(user_binding, :partitions) || continue
latest_bpart = user_binding.partitions
latest_bpart.max_world == typemax(UInt) || continue
binding_kind(latest_bpart) in (BINDING_KIND_IMPLICIT, BINDING_KIND_FAILED, BINDING_KIND_GUARD) || continue
binding_kind(latest_bpart) in (PARTITION_KIND_IMPLICIT, PARTITION_KIND_FAILED, PARTITION_KIND_GUARD) || continue
@atomic :release latest_bpart.max_world = new_max_world
invalidate_code_for_globalref!(convert(Core.Binding, user_binding), latest_bpart, nothing, new_max_world)
end
Expand Down
46 changes: 23 additions & 23 deletions base/runtime_internals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,29 +197,29 @@ function _fieldnames(@nospecialize t)
end

# N.B.: Needs to be synced with julia.h
const BINDING_KIND_CONST = 0x0
const BINDING_KIND_CONST_IMPORT = 0x1
const BINDING_KIND_GLOBAL = 0x2
const BINDING_KIND_IMPLICIT = 0x3
const BINDING_KIND_EXPLICIT = 0x4
const BINDING_KIND_IMPORTED = 0x5
const BINDING_KIND_FAILED = 0x6
const BINDING_KIND_DECLARED = 0x7
const BINDING_KIND_GUARD = 0x8
const BINDING_KIND_UNDEF_CONST = 0x9
const BINDING_KIND_BACKDATED_CONST = 0xa

const BINDING_FLAG_EXPORTED = 0x10
const BINDING_FLAG_DEPRECATED = 0x20
const BINDING_FLAG_DEPWARN = 0x40

const BINDING_KIND_MASK = 0x0f
const BINDING_FLAG_MASK = 0xf0

is_defined_const_binding(kind::UInt8) = (kind == BINDING_KIND_CONST || kind == BINDING_KIND_CONST_IMPORT || kind == BINDING_KIND_BACKDATED_CONST)
is_some_const_binding(kind::UInt8) = (is_defined_const_binding(kind) || kind == BINDING_KIND_UNDEF_CONST)
is_some_imported(kind::UInt8) = (kind == BINDING_KIND_IMPLICIT || kind == BINDING_KIND_EXPLICIT || kind == BINDING_KIND_IMPORTED)
is_some_guard(kind::UInt8) = (kind == BINDING_KIND_GUARD || kind == BINDING_KIND_FAILED || kind == BINDING_KIND_UNDEF_CONST)
const PARTITION_KIND_CONST = 0x0
const PARTITION_KIND_CONST_IMPORT = 0x1
const PARTITION_KIND_GLOBAL = 0x2
const PARTITION_KIND_IMPLICIT = 0x3
const PARTITION_KIND_EXPLICIT = 0x4
const PARTITION_KIND_IMPORTED = 0x5
const PARTITION_KIND_FAILED = 0x6
const PARTITION_KIND_DECLARED = 0x7
const PARTITION_KIND_GUARD = 0x8
const PARTITION_KIND_UNDEF_CONST = 0x9
const PARTITION_KIND_BACKDATED_CONST = 0xa

const PARTITION_FLAG_EXPORTED = 0x10
const PARTITION_FLAG_DEPRECATED = 0x20
const PARTITION_FLAG_DEPWARN = 0x40

const PARTITION_MASK_KIND = 0x0f
const PARTITION_MASK_FLAG = 0xf0

is_defined_const_binding(kind::UInt8) = (kind == PARTITION_KIND_CONST || kind == PARTITION_KIND_CONST_IMPORT || kind == PARTITION_KIND_BACKDATED_CONST)
is_some_const_binding(kind::UInt8) = (is_defined_const_binding(kind) || kind == PARTITION_KIND_UNDEF_CONST)
is_some_imported(kind::UInt8) = (kind == PARTITION_KIND_IMPLICIT || kind == PARTITION_KIND_EXPLICIT || kind == PARTITION_KIND_IMPORTED)
is_some_guard(kind::UInt8) = (kind == PARTITION_KIND_GUARD || kind == PARTITION_KIND_FAILED || kind == PARTITION_KIND_UNDEF_CONST)

function lookup_binding_partition(world::UInt, b::Core.Binding)
ccall(:jl_get_binding_partition, Ref{Core.BindingPartition}, (Any, UInt), b, world)
Expand Down
26 changes: 13 additions & 13 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3377,49 +3377,49 @@ function print_partition(io::IO, partition::Core.BindingPartition)
else
print(io, max_world)
end
if (partition.kind & BINDING_FLAG_MASK) != 0
if (partition.kind & PARTITION_MASK_FLAG) != 0
first = false
print(io, " [")
if (partition.kind & BINDING_FLAG_EXPORTED) != 0
if (partition.kind & PARTITION_FLAG_EXPORTED) != 0
print(io, "exported")
end
if (partition.kind & BINDING_FLAG_DEPRECATED) != 0
if (partition.kind & PARTITION_FLAG_DEPRECATED) != 0
first ? (first = false) : print(io, ",")
print(io, "deprecated")
end
if (partition.kind & BINDING_FLAG_DEPWARN) != 0
if (partition.kind & PARTITION_FLAG_DEPWARN) != 0
first ? (first = false) : print(io, ",")
print(io, "depwarn")
end
print(io, "]")
end
print(io, " - ")
kind = binding_kind(partition)
if kind == BINDING_KIND_BACKDATED_CONST
if kind == PARTITION_KIND_BACKDATED_CONST
print(io, "backdated constant binding to ")
print(io, partition_restriction(partition))
elseif is_defined_const_binding(kind)
print(io, "constant binding to ")
print(io, partition_restriction(partition))
elseif kind == BINDING_KIND_UNDEF_CONST
elseif kind == PARTITION_KIND_UNDEF_CONST
print(io, "undefined const binding")
elseif kind == BINDING_KIND_GUARD
elseif kind == PARTITION_KIND_GUARD
print(io, "undefined binding - guard entry")
elseif kind == BINDING_KIND_FAILED
elseif kind == PARTITION_KIND_FAILED
print(io, "ambiguous binding - guard entry")
elseif kind == BINDING_KIND_DECLARED
elseif kind == PARTITION_KIND_DECLARED
print(io, "weak global binding declared using `global` (implicit type Any)")
elseif kind == BINDING_KIND_IMPLICIT
elseif kind == PARTITION_KIND_IMPLICIT
print(io, "implicit `using` from ")
print(io, partition_restriction(partition).globalref)
elseif kind == BINDING_KIND_EXPLICIT
elseif kind == PARTITION_KIND_EXPLICIT
print(io, "explicit `using` from ")
print(io, partition_restriction(partition).globalref)
elseif kind == BINDING_KIND_IMPORTED
elseif kind == PARTITION_KIND_IMPORTED
print(io, "explicit `import` from ")
print(io, partition_restriction(partition).globalref)
else
@assert kind == BINDING_KIND_GLOBAL
@assert kind == PARTITION_KIND_GLOBAL
print(io, "global variable with type ")
print(io, partition_restriction(partition))
end
Expand Down
2 changes: 1 addition & 1 deletion src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ static value_t fl_defined_julia_global(fl_context_t *fl_ctx, value_t *args, uint
jl_sym_t *var = scmsym_to_julia(fl_ctx, args[0]);
jl_binding_t *b = jl_get_module_binding(ctx->module, var, 0);
jl_binding_partition_t *bpart = jl_get_binding_partition(b, jl_current_task->world_age);
return (bpart != NULL && jl_binding_kind(bpart) == BINDING_KIND_GLOBAL) ? fl_ctx->T : fl_ctx->F;
return (bpart != NULL && jl_binding_kind(bpart) == PARTITION_KIND_GLOBAL) ? fl_ctx->T : fl_ctx->F;
}

// Used to generate a unique suffix for a given symbol (e.g. variable or type name)
Expand Down
14 changes: 7 additions & 7 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3226,11 +3226,11 @@ static jl_cgval_t emit_globalref_runtime(jl_codectx_t &ctx, jl_binding_t *bnd, j
static jl_cgval_t emit_globalref(jl_codectx_t &ctx, jl_module_t *mod, jl_sym_t *name, AtomicOrdering order)
{
jl_binding_t *bnd = jl_get_module_binding(mod, name, 1);
struct restriction_kind_pair rkp = { NULL, NULL, BINDING_KIND_GUARD, 0 };
struct restriction_kind_pair rkp = { NULL, NULL, PARTITION_KIND_GUARD, 0 };
if (!jl_get_binding_leaf_partitions_restriction_kind(bnd, &rkp, ctx.min_world, ctx.max_world)) {
return emit_globalref_runtime(ctx, bnd, mod, name);
}
if (jl_bkind_is_some_constant(rkp.kind) && rkp.kind != BINDING_KIND_BACKDATED_CONST) {
if (jl_bkind_is_some_constant(rkp.kind) && rkp.kind != PARTITION_KIND_BACKDATED_CONST) {
if (rkp.maybe_depwarn) {
Value *bp = julia_binding_gv(ctx, bnd);
ctx.builder.CreateCall(prepare_call(jldepcheck_func), { bp });
Expand All @@ -3242,7 +3242,7 @@ static jl_cgval_t emit_globalref(jl_codectx_t &ctx, jl_module_t *mod, jl_sym_t *
}
return mark_julia_const(ctx, constval);
}
if (rkp.kind != BINDING_KIND_GLOBAL) {
if (rkp.kind != PARTITION_KIND_GLOBAL) {
return emit_globalref_runtime(ctx, bnd, mod, name);
}
Value *bp = julia_binding_gv(ctx, bnd);
Expand All @@ -3267,8 +3267,8 @@ static jl_cgval_t emit_globalop(jl_codectx_t &ctx, jl_module_t *mod, jl_sym_t *s
jl_binding_partition_t *bpart = jl_get_binding_partition_all(bnd, ctx.min_world, ctx.max_world);
Value *bp = julia_binding_gv(ctx, bnd);
if (bpart) {
if (jl_binding_kind(bpart) == BINDING_KIND_GLOBAL) {
int possibly_deprecated = bpart->kind & BINDING_FLAG_DEPWARN;
if (jl_binding_kind(bpart) == PARTITION_KIND_GLOBAL) {
int possibly_deprecated = bpart->kind & PARTITION_FLAG_DEPWARN;
jl_value_t *ty = bpart->restriction;
if (ty != nullptr) {
const std::string fname = issetglobal ? "setglobal!" : isreplaceglobal ? "replaceglobal!" : isswapglobal ? "swapglobal!" : ismodifyglobal ? "modifyglobal!" : "setglobalonce!";
Expand Down Expand Up @@ -3819,11 +3819,11 @@ static jl_cgval_t emit_isdefinedglobal(jl_codectx_t &ctx, jl_module_t *modu, jl_
{
Value *isnull = NULL;
jl_binding_t *bnd = allow_import ? jl_get_binding(modu, name) : jl_get_module_binding(modu, name, 0);
struct restriction_kind_pair rkp = { NULL, NULL, BINDING_KIND_GUARD, 0 };
struct restriction_kind_pair rkp = { NULL, NULL, PARTITION_KIND_GUARD, 0 };
if (allow_import && jl_get_binding_leaf_partitions_restriction_kind(bnd, &rkp, ctx.min_world, ctx.max_world)) {
if (jl_bkind_is_some_constant(rkp.kind))
return mark_julia_const(ctx, rkp.restriction);
if (rkp.kind == BINDING_KIND_GLOBAL) {
if (rkp.kind == PARTITION_KIND_GLOBAL) {
Value *bp = julia_binding_gv(ctx, rkp.binding_if_global);
bp = julia_binding_pvalue(ctx, bp);
LoadInst *v = ctx.builder.CreateAlignedLoad(ctx.types().T_prjlvalue, bp, Align(sizeof(void*)));
Expand Down
2 changes: 1 addition & 1 deletion src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3816,7 +3816,7 @@ jl_function_t *jl_new_generic_function_with_supertype(jl_sym_t *name, jl_module_
JL_GC_PUSH1(&ftype);
ftype->name->mt->name = name;
jl_gc_wb(ftype->name->mt, name);
jl_declare_constant_val3(NULL, module, tname, (jl_value_t*)ftype, BINDING_KIND_CONST, new_world);
jl_declare_constant_val3(NULL, module, tname, (jl_value_t*)ftype, PARTITION_KIND_CONST, new_world);
jl_value_t *f = jl_new_struct(ftype);
ftype->instance = f;
jl_gc_wb(ftype, f);
Expand Down
Loading