Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: typemap split on non-leaf TypeNames #16418

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 13 additions & 0 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ function visit(f, mt::MethodTable)
nothing
end
function visit(f, mc::TypeMapLevel)
mc.bottom !== nothing && visit(f, mc.bottom)
if mc.targ !== nothing
e = mc.targ::Vector{Any}
for i in 1:length(e)
Expand All @@ -301,6 +302,18 @@ function visit(f, mc::TypeMapLevel)
isdefined(e, i) && visit(f, e[i])
end
end
if mc.tname !== nothing
e = mc.tname::Vector{Any}
for i in 1:length(e)
isdefined(e, i) && visit(f, e[i])
end
end
if mc.name1 !== nothing
e = mc.name1::Vector{Any}
for i in 1:length(e)
isdefined(e, i) && visit(f, e[i])
end
end
mc.list !== nothing && visit(f, mc.list)
mc.any !== nothing && visit(f, mc.any)
nothing
Expand Down
24 changes: 16 additions & 8 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -939,16 +939,24 @@ static void jl_serialize_value_(ios_t *s, jl_value_t *v)
// (which will need to be rehashed during deserialization anyhow)
jl_typemap_level_t *node = (jl_typemap_level_t*)v;
assert( // make sure this type has the expected ordering
offsetof(jl_typemap_level_t, arg1) == 0 * sizeof(jl_value_t*) &&
offsetof(jl_typemap_level_t, targ) == 2 * sizeof(jl_value_t*) &&
offsetof(jl_typemap_level_t, linear) == 4 * sizeof(jl_value_t*) &&
offsetof(jl_typemap_level_t, any) == 5 * sizeof(jl_value_t*) &&
offsetof(jl_typemap_level_t, key) == 6 * sizeof(jl_value_t*) &&
sizeof(jl_typemap_level_t) == 7 * sizeof(jl_value_t*));
offsetof(jl_typemap_level_t, bottom) == 0 * sizeof(jl_value_t*) &&
offsetof(jl_typemap_level_t, targ) == 1 * sizeof(jl_value_t*) &&
offsetof(jl_typemap_level_t, arg1) == 3 * sizeof(jl_value_t*) &&
offsetof(jl_typemap_level_t, tname) == 5 * sizeof(jl_value_t*) &&
offsetof(jl_typemap_level_t, name1) == 7 * sizeof(jl_value_t*) &&
offsetof(jl_typemap_level_t, linear) == 9 * sizeof(jl_value_t*) &&
offsetof(jl_typemap_level_t, any) == 10 * sizeof(jl_value_t*) &&
offsetof(jl_typemap_level_t, key) == 11 * sizeof(jl_value_t*) &&
sizeof(jl_typemap_level_t) == 12 * sizeof(jl_value_t*));
jl_serialize_value(s, node->bottom);
jl_serialize_value(s, jl_nothing);
jl_serialize_value(s, node->targ.values);
jl_serialize_value(s, jl_nothing);
jl_serialize_value(s, node->arg1.values);
jl_serialize_value(s, jl_nothing);
jl_serialize_value(s, node->targ.values);
jl_serialize_value(s, node->tname.values);
jl_serialize_value(s, jl_nothing);
jl_serialize_value(s, node->name1.values);
jl_serialize_value(s, node->linear);
jl_serialize_value(s, node->any.unknown);
jl_serialize_value(s, node->key);
Expand Down Expand Up @@ -987,7 +995,7 @@ struct jl_serialize_methcache_from_mod_env {
static int jl_serialize_methcache_from_mod(jl_typemap_entry_t *ml, void *closure)
{
struct jl_serialize_methcache_from_mod_env *env = (struct jl_serialize_methcache_from_mod_env*)closure;
if (module_in_worklist(ml->func.method->module)) {
if (module_in_worklist(ml->func.method->module) && !ml->weak) {
jl_serialize_value(env->s, ml->func.method);
jl_serialize_value(env->s, ml->simplesig);
}
Expand Down
28 changes: 20 additions & 8 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3678,43 +3678,55 @@ void jl_init_types(void)

jl_typemap_level_type =
jl_new_datatype(jl_symbol("TypeMapLevel"), jl_any_type, jl_emptysvec,
jl_svec(7,
jl_symbol("index_arg1"),
jl_symbol("arg1"),
jl_svec(12,
jl_symbol("bottom"),
jl_symbol("index_targ"),
jl_symbol("targ"),
jl_symbol("index_arg1"),
jl_symbol("arg1"),
jl_symbol("index_tname"),
jl_symbol("tname"),
jl_symbol("index_name1"),
jl_symbol("name1"),
jl_symbol("list"),
jl_symbol("any"),
jl_symbol("key")),
jl_svec(7,
jl_svec(12,
jl_any_type,
jl_any_type,
jl_any_type,
jl_any_type,
jl_any_type,
jl_any_type,
jl_any_type,
jl_any_type,
jl_any_type,
jl_any_type,
jl_any_type,
jl_any_type),
0, 1, 6);
0, 1, 11);

jl_typemap_entry_type =
jl_new_datatype(jl_symbol("TypeMapEntry"), jl_any_type, jl_emptysvec,
jl_svec(9, jl_symbol("next"),
jl_svec(10, jl_symbol("next"),
jl_symbol("sig"),
jl_symbol("tvars"),
jl_symbol("simplesig"),
jl_symbol("guardsigs"),
jl_symbol("func"),
jl_symbol("isleafsig"),
jl_symbol("issimplesig"),
jl_symbol("va")),
jl_svec(9, jl_any_type, // Union{TypeMapEntry, Void}
jl_symbol("va"),
jl_symbol("weak")),
jl_svec(10, jl_any_type, // Union{TypeMapEntry, Void}
jl_type_type, // TupleType
jl_any_type, // Union{SimpleVector{TypeVar}, TypeVar}
jl_any_type, // TupleType
jl_any_type, // SimpleVector{TupleType}
jl_any_type, // Any
jl_bool_type,
jl_bool_type,
jl_bool_type,
jl_bool_type),
0, 1, 5);

Expand Down
16 changes: 11 additions & 5 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ typedef struct {
jl_value_t *primary;
jl_svec_t *cache; // sorted array
jl_svec_t *linearcache; // unsorted array
intptr_t uid;
uint32_t uid;
struct _jl_methtable_t *mt;
} jl_typename_t;

Expand Down Expand Up @@ -416,6 +416,7 @@ typedef struct _jl_typemap_entry_t {
int8_t isleafsig; // isleaftype(sig) & !any(isType, sig) : unsorted and very fast
int8_t issimplesig; // all(isleaftype | isAny | isType | isVararg, sig) : sorted and fast
int8_t va; // isVararg(sig)
int8_t weak; // will never overwrite a signature
} jl_typemap_entry_t;

// one level in a TypeMap tree
Expand All @@ -426,9 +427,12 @@ struct jl_ordereddict_t {
};
typedef struct _jl_typemap_level_t {
JL_DATA_TYPE
struct jl_ordereddict_t arg1;
struct jl_ordereddict_t targ;
jl_typemap_entry_t *linear; // union jl_typemap_t (but no more levels)
jl_typemap_entry_t *bottom; // union jl_typemap_t (but no more levels) for entries which have no type at offs
struct jl_ordereddict_t targ; // contains Type{LeafType}
struct jl_ordereddict_t arg1; // contains LeafType
struct jl_ordereddict_t tname; // contains non-abstract Type{TypeName}
struct jl_ordereddict_t name1; // contains non-abstract TypeName
jl_typemap_entry_t *linear; // union jl_typemap_t (but no more levels) - most entries usually end up here
union jl_typemap_t any; // type at offs is Any
jl_value_t *key; // [nullable]
} jl_typemap_level_t;
Expand Down Expand Up @@ -997,7 +1001,9 @@ STATIC_INLINE int jl_is_leaf_type_(jl_value_t *v)

// type constructors
JL_DLLEXPORT jl_typename_t *jl_new_typename(jl_sym_t *name);
JL_DLLEXPORT jl_tvar_t *jl_new_typevar(jl_sym_t *name,jl_value_t *lb,jl_value_t *ub);
JL_DLLEXPORT jl_tvar_t *jl_new_typevar(jl_sym_t *name, jl_value_t *lb, jl_value_t *ub);
JL_DLLEXPORT jl_tvar_t *jl_new_typevar_(jl_sym_t *name, jl_value_t *lb,
jl_value_t *ub, jl_value_t *b);
JL_DLLEXPORT jl_value_t *jl_apply_type(jl_value_t *tc, jl_svec_t *params);
JL_DLLEXPORT jl_tupletype_t *jl_apply_tuple_type(jl_svec_t *params);
JL_DLLEXPORT jl_tupletype_t *jl_apply_tuple_type_v(jl_value_t **p, size_t np);
Expand Down
Loading