Skip to content
Open
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 @@ -44,7 +44,7 @@ using Core: ABIOverride, Builtin, CodeInstance, IntrinsicFunction, MethodInstanc
typename, unsafe_write, write, stdout, stderr

using Base: @_foldable_meta, @_gc_preserve_begin, @_gc_preserve_end, @nospecializeinfer,
PARTITION_KIND_GLOBAL, PARTITION_KIND_UNDEF_CONST, PARTITION_KIND_BACKDATED_CONST, PARTITION_KIND_DECLARED,
PARTITION_KIND_GLOBAL, PARTITION_KIND_UNDEF_CONST, PARTITION_KIND_BACKDATED_CONST, PARTITION_KIND_BACKDATED_IMPORT, PARTITION_KIND_BACKDATED_GLOBAL, PARTITION_KIND_DECLARED,
PARTITION_FLAG_DEPWARN,
Base, BitVector, Bottom, Callable, DataTypeFieldDesc,
EffectsOverride, Filter, Generator, NUM_EFFECTS_OVERRIDES,
Expand All @@ -55,7 +55,7 @@ using Base: @_foldable_meta, @_gc_preserve_begin, @_gc_preserve_end, @nospeciali
datatype_pointerfree, decode_effects_override, diff_names, fieldindex, visit,
generating_output, get_nospecializeinfer_sig, get_world_counter, has_free_typevars,
hasgenerator, hasintersect, indexed_iterate, isType, is_file_tracked, is_function_def,
is_meta_expr, is_meta_expr_head, is_nospecialized, is_nospecializeinfer, is_defined_const_binding,
is_meta_expr, is_meta_expr_head, is_nospecialized, is_nospecializeinfer, is_backdated, is_defined_const_binding,
is_some_const_binding, is_some_guard, is_some_imported, is_some_explicit_imported, is_some_binding_imported, is_valid_intrinsic_elptr,
isbitsunion, isconcretedispatch, isdispatchelem, isexpr, isfieldatomic, isidentityfree,
iskindtype, ismutabletypename, ismutationfree, issingletontype, isvarargtype, isvatuple,
Expand Down
11 changes: 6 additions & 5 deletions Compiler/src/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3650,12 +3650,13 @@ function abstract_eval_partition_load(interp::Union{AbstractInterpreter,Nothing}
end
end

if is_backdated(kind)
# Infer this as guard. We do not want a later definition to retroactively improve
# inference results in an earlier world.
return RTEffects(Any, UndefVarError, local_getglobal_effects)
end

if is_defined_const_binding(kind)
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)
end
rt = Const(partition_restriction(partition))
return RTEffects(rt, Union{}, Effects(EFFECTS_TOTAL,
inaccessiblememonly=is_mutation_free_argtype(rt) ? ALWAYS_TRUE : ALWAYS_FALSE,
Expand Down
7 changes: 5 additions & 2 deletions base/runtime_internals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ const PARTITION_KIND_DECLARED = 0x8
const PARTITION_KIND_GUARD = 0x9
const PARTITION_KIND_UNDEF_CONST = 0xa
const PARTITION_KIND_BACKDATED_CONST = 0xb
const PARTITION_KIND_BACKDATED_IMPORT = 0xc
const PARTITION_KIND_BACKDATED_GLOBAL = 0xd

const PARTITION_FLAG_EXPORTED = 0x10
const PARTITION_FLAG_DEPRECATED = 0x20
Expand All @@ -256,11 +258,12 @@ const PARTITION_MASK_FLAG = 0xf0

const BINDING_FLAG_ANY_IMPLICIT_EDGES = 0x8

is_backdated(kind::UInt8) = (kind == PARTITION_KIND_BACKDATED_CONST || kind == PARTITION_KIND_BACKDATED_IMPORT || kind == PARTITION_KIND_BACKDATED_GLOBAL)
is_defined_const_binding(kind::UInt8) = (kind == PARTITION_KIND_CONST || kind == PARTITION_KIND_CONST_IMPORT || kind == PARTITION_KIND_IMPLICIT_CONST || 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_GLOBAL || kind == PARTITION_KIND_IMPLICIT_CONST || kind == PARTITION_KIND_EXPLICIT || kind == PARTITION_KIND_IMPORTED)
is_some_imported(kind::UInt8) = (kind == PARTITION_KIND_IMPLICIT_GLOBAL || kind == PARTITION_KIND_IMPLICIT_CONST || kind == PARTITION_KIND_EXPLICIT || kind == PARTITION_KIND_IMPORTED || kind == PARTITION_KIND_BACKDATED_IMPORT)
is_some_implicit(kind::UInt8) = (kind == PARTITION_KIND_IMPLICIT_GLOBAL || kind == PARTITION_KIND_IMPLICIT_CONST || kind == PARTITION_KIND_GUARD || kind == PARTITION_KIND_FAILED)
is_some_explicit_imported(kind::UInt8) = (kind == PARTITION_KIND_EXPLICIT || kind == PARTITION_KIND_IMPORTED)
is_some_explicit_imported(kind::UInt8) = (kind == PARTITION_KIND_EXPLICIT || kind == PARTITION_KIND_IMPORTED || kind == PARTITION_KIND_BACKDATED_IMPORT)
is_some_binding_imported(kind::UInt8) = is_some_explicit_imported(kind) || kind == PARTITION_KIND_IMPLICIT_GLOBAL
is_some_guard(kind::UInt8) = (kind == PARTITION_KIND_GUARD || kind == PARTITION_KIND_FAILED || kind == PARTITION_KIND_UNDEF_CONST)

Expand Down
6 changes: 6 additions & 0 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3309,6 +3309,12 @@ function print_partition(io::IO, partition::Core.BindingPartition)
if kind == PARTITION_KIND_BACKDATED_CONST
print(io, "backdated constant binding to ")
print(io, partition_restriction(partition))
elseif kind == PARTITION_KIND_BACKDATED_IMPORT
print(io, "backdated explicit `import` from ")
print(io, partition_restriction(partition).globalref)
elseif kind == PARTITION_KIND_BACKDATED_GLOBAL
print(io, "backdated global variable with type ")
print(io, partition_restriction(partition))
elseif kind == PARTITION_KIND_CONST
print(io, "constant binding to ")
print(io, partition_restriction(partition))
Expand Down
7 changes: 4 additions & 3 deletions src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1224,9 +1224,10 @@ JL_DLLEXPORT jl_value_t *jl_fl_lower(jl_value_t *expr, jl_module_t *inmodule,
JL_DLLEXPORT jl_value_t *jl_lower(jl_value_t *expr, jl_module_t *inmodule,
const char *filename, int line, size_t world, bool_t warn)
{
jl_value_t *core_lower = NULL;
if (jl_core_module)
core_lower = jl_get_global_value(jl_core_module, jl_symbol("_lower"), jl_current_task->world_age);
if (!jl_core_module || !jl_boundp(jl_core_module, jl_symbol("_lower"), jl_current_task->world_age)) {
return jl_fl_lower(expr, inmodule, filename, line, world, warn);
}
jl_value_t *core_lower = jl_get_global_value(jl_core_module, jl_symbol("_lower"), jl_current_task->world_age);
if (!core_lower || core_lower == jl_nothing) {
return jl_fl_lower(expr, inmodule, filename, line, world, warn);
}
Expand Down
20 changes: 13 additions & 7 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -694,11 +694,11 @@ typedef struct _jl_weakref_t {
//
// We may make this list more permissive in the future.
//
// Finally, PARTITION_KIND_BACKDATED_CONST is a special case, and the only case where we may replace an
// existing partition by a different partition kind in the same world age. As such, it needs special
// support in inference. Any partition kind that may be replaced by a PARTITION_KIND_BACKDATED_CONST
// must be inferred accordingly. PARTITION_KIND_BACKDATED_CONST is intended as a temporary compatibility
// measure. The following kinds may be replaced by PARTITION_KIND_BACKDATED_CONST:
// Finally, PARTITION_KIND_BACKDATED_* are special cases, and the only cases where we may replace an
// existing partition by a different partition kind in the same world age. As such, they need special
// support in inference. Any partition kind that may be replaced by a PARTITION_KIND_BACKDATED_*
// must be inferred accordingly. PARTITION_KIND_BACKDATED_* are intended as a temporary compatibility
// measure. The following kinds may be replaced by any backdated partition kind:
// - PARTITION_KIND_GUARD
// - PARTITION_KIND_FAILED
// - PARTITION_KIND_DECLARED
Expand Down Expand Up @@ -743,11 +743,17 @@ enum jl_partition_kind {
// Backated constant. A constant that was backdated for compatibility. In all other
// ways equivalent to PARTITION_KIND_CONST, but prints a warning on access
PARTITION_KIND_BACKDATED_CONST = 0xb,
// Backdated import. An explicit import that was backdated for compatibility. In all other
// ways equivalent to PARTITION_KIND_IMPORTED, but prints a warning on access
PARTITION_KIND_BACKDATED_IMPORT = 0xc,
// Backdated global. A global that was backdated for compatibility. In all other
// ways equivalent to PARTITION_KIND_GLOBAL, but prints a warning on access
PARTITION_KIND_BACKDATED_GLOBAL = 0xd,

// This is not a real binding kind, but can be used to ask for a re-resolution
// of the implicit binding kind
PARTITION_FAKE_KIND_IMPLICIT_RECOMPUTE = 0xc,
PARTITION_FAKE_KIND_CYCLE = 0xd
PARTITION_FAKE_KIND_IMPLICIT_RECOMPUTE = 0xe,
PARTITION_FAKE_KIND_CYCLE = 0xf
};

static const uint8_t PARTITION_MASK_KIND = 0x0f;
Expand Down
26 changes: 24 additions & 2 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,9 @@ JL_DLLEXPORT jl_binding_partition_t *jl_replace_binding_locked(jl_binding_t *b J
jl_binding_partition_t *old_bpart, jl_value_t *restriction_val, enum jl_partition_kind kind, size_t new_world) JL_GLOBALLY_ROOTED;
JL_DLLEXPORT jl_binding_partition_t *jl_replace_binding_locked2(jl_binding_t *b JL_PROPAGATES_ROOT,
jl_binding_partition_t *old_bpart, jl_value_t *restriction_val, size_t kind, size_t new_world) JL_GLOBALLY_ROOTED;
jl_binding_partition_t *jl_backdate_binding_partition(jl_binding_t *b JL_PROPAGATES_ROOT,
jl_binding_partition_t *bpart, jl_binding_partition_t *new_bpart,
jl_value_t *restriction, enum jl_partition_kind backdated_kind, size_t new_world) JL_GLOBALLY_ROOTED;
JL_DLLEXPORT void jl_update_loaded_bpart(jl_binding_t *b, jl_binding_partition_t *bpart);
extern jl_array_t *jl_module_init_order JL_GLOBALLY_ROOTED;
extern htable_t jl_current_modules JL_GLOBALLY_ROOTED;
Expand All @@ -998,11 +1001,11 @@ jl_method_t *jl_make_opaque_closure_method(jl_module_t *module, jl_value_t *name
JL_DLLEXPORT int jl_is_valid_oc_argtype(jl_tupletype_t *argt, jl_method_t *source);

STATIC_INLINE int jl_bkind_is_some_import(enum jl_partition_kind kind) JL_NOTSAFEPOINT {
return kind == PARTITION_KIND_IMPLICIT_CONST || kind == PARTITION_KIND_IMPLICIT_GLOBAL || kind == PARTITION_KIND_EXPLICIT || kind == PARTITION_KIND_IMPORTED;
return kind == PARTITION_KIND_IMPLICIT_CONST || kind == PARTITION_KIND_IMPLICIT_GLOBAL || kind == PARTITION_KIND_EXPLICIT || kind == PARTITION_KIND_IMPORTED || kind == PARTITION_KIND_BACKDATED_IMPORT;
}

STATIC_INLINE int jl_bkind_is_some_explicit_import(enum jl_partition_kind kind) JL_NOTSAFEPOINT {
return kind == PARTITION_KIND_EXPLICIT || kind == PARTITION_KIND_IMPORTED;
return kind == PARTITION_KIND_EXPLICIT || kind == PARTITION_KIND_IMPORTED || kind == PARTITION_KIND_BACKDATED_IMPORT;
}

STATIC_INLINE int jl_bkind_is_some_guard(enum jl_partition_kind kind) JL_NOTSAFEPOINT {
Expand All @@ -1025,6 +1028,10 @@ STATIC_INLINE int jl_bkind_is_real_constant(enum jl_partition_kind kind) JL_NOTS
return kind == PARTITION_KIND_IMPLICIT_CONST || kind == PARTITION_KIND_CONST || kind == PARTITION_KIND_CONST_IMPORT;
}

STATIC_INLINE int jl_bkind_is_backdated(enum jl_partition_kind kind) JL_NOTSAFEPOINT {
return kind == PARTITION_KIND_BACKDATED_CONST || kind == PARTITION_KIND_BACKDATED_IMPORT || kind == PARTITION_KIND_BACKDATED_GLOBAL;
}

JL_DLLEXPORT jl_binding_partition_t *jl_get_binding_partition(jl_binding_t *b JL_PROPAGATES_ROOT, size_t world) JL_GLOBALLY_ROOTED;
JL_DLLEXPORT jl_binding_partition_t *jl_get_binding_partition_with_hint(jl_binding_t *b JL_PROPAGATES_ROOT, jl_binding_partition_t *previous_part, size_t world) JL_GLOBALLY_ROOTED;
JL_DLLEXPORT jl_binding_partition_t *jl_get_binding_partition_all(jl_binding_t *b JL_PROPAGATES_ROOT, size_t min_world, size_t max_world) JL_GLOBALLY_ROOTED;
Expand Down Expand Up @@ -1059,6 +1066,21 @@ STATIC_INLINE void jl_walk_binding_inplace(jl_binding_t **bnd, jl_binding_partit
}
}

extern void check_backdated_binding(jl_binding_t *b, enum jl_partition_kind kind) JL_NOTSAFEPOINT;

STATIC_INLINE void jl_walk_binding_inplace_stop_at_backdated(jl_binding_t **bnd, jl_binding_partition_t **bpart, size_t world, int stop_at_backdated) JL_NOTSAFEPOINT
{
while (1) {
enum jl_partition_kind kind = jl_binding_kind(*bpart);
if (stop_at_backdated && jl_bkind_is_backdated(kind))
return;
if (!jl_bkind_is_some_explicit_import(kind) && kind != PARTITION_KIND_IMPLICIT_GLOBAL)
return;
*bnd = (jl_binding_t*)(*bpart)->restriction;
*bpart = jl_get_binding_partition(*bnd, world);
}
}

STATIC_INLINE void jl_walk_binding_inplace_depwarn(jl_binding_t **bnd, jl_binding_partition_t **bpart, size_t world, int *depwarn) JL_NOTSAFEPOINT
{
int passed_explicit = 0;
Expand Down
Loading
Loading