Skip to content

Commit

Permalink
some type signatures are only partially more specific than TypeName
Browse files Browse the repository at this point in the history
this require creation of extra entries to split the method between
multiple tables

[ci skip] [av skip]
  • Loading branch information
vtjnash committed Jul 9, 2016
1 parent b6bfb2f commit 1618919
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 161 deletions.
2 changes: 1 addition & 1 deletion 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,7 +302,6 @@ function visit(f, mc::TypeMapLevel)
isdefined(e, i) && visit(f, e[i])
end
end
mc.linear_leaf !== nothing && visit(f, mc.linear_leaf)
if mc.tname !== nothing
e = mc.tname::Vector{Any}
for i in 1:length(e)
Expand Down
20 changes: 11 additions & 9 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -939,14 +939,16 @@ 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, targ) == 0 * sizeof(jl_value_t*) &&
offsetof(jl_typemap_level_t, arg1) == 2 * sizeof(jl_value_t*) &&
offsetof(jl_typemap_level_t, tname) == 4 * sizeof(jl_value_t*) &&
offsetof(jl_typemap_level_t, name1) == 6 * sizeof(jl_value_t*) &&
offsetof(jl_typemap_level_t, linear) == 8 * sizeof(jl_value_t*) &&
offsetof(jl_typemap_level_t, any) == 9 * sizeof(jl_value_t*) &&
offsetof(jl_typemap_level_t, key) == 10 * sizeof(jl_value_t*) &&
sizeof(jl_typemap_level_t) == 11 * 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);
Expand Down Expand Up @@ -993,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
16 changes: 10 additions & 6 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3678,7 +3678,8 @@ void jl_init_types(void)

jl_typemap_level_type =
jl_new_datatype(jl_symbol("TypeMapLevel"), jl_any_type, jl_emptysvec,
jl_svec(11,
jl_svec(12,
jl_symbol("bottom"),
jl_symbol("index_targ"),
jl_symbol("targ"),
jl_symbol("index_arg1"),
Expand All @@ -3690,7 +3691,8 @@ void jl_init_types(void)
jl_symbol("list"),
jl_symbol("any"),
jl_symbol("key")),
jl_svec(11,
jl_svec(12,
jl_any_type,
jl_any_type,
jl_any_type,
jl_any_type,
Expand All @@ -3702,27 +3704,29 @@ void jl_init_types(void)
jl_any_type,
jl_any_type,
jl_any_type),
0, 1, 10);
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
8 changes: 6 additions & 2 deletions src/julia.h
Original file line number Diff line number Diff line change
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,11 +427,12 @@ struct jl_ordereddict_t {
};
typedef struct _jl_typemap_level_t {
JL_DATA_TYPE
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)
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 @@ -999,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

0 comments on commit 1618919

Please sign in to comment.