Skip to content

Commit ffce357

Browse files
committed
make the TypeMap capable of splitting on any concrete type
previously, the TypeMap could only split on leaf types now it also has the ability to split on concrete types this allows it to ensure that each type gets its own linear list to scan to find its constructors, instead of needing to search through all constructors
1 parent becac63 commit ffce357

File tree

8 files changed

+413
-69
lines changed

8 files changed

+413
-69
lines changed

base/reflection.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,7 @@ function visit(f, mt::Core.MethodTable)
910910
nothing
911911
end
912912
function visit(f, mc::Core.TypeMapLevel)
913+
mc.bottom !== nothing && visit(f, mc.bottom)
913914
if mc.targ !== nothing
914915
e = mc.targ::Vector{Any}
915916
for i in 2:2:length(e)
@@ -922,6 +923,20 @@ function visit(f, mc::Core.TypeMapLevel)
922923
isassigned(e, i) && visit(f, e[i])
923924
end
924925
end
926+
if mc.tname !== nothing
927+
for e in mc.tname::SimpleVector
928+
e = e::Vector{Any}
929+
for i in 2:2:length(e)
930+
isassigned(e, i) && visit(f, e[i])
931+
end
932+
end
933+
end
934+
if mc.name1 !== nothing
935+
e = mc.name1::Vector{Any}
936+
for i in 2:2:length(e)
937+
isassigned(e, i) && visit(f, e[i])
938+
end
939+
end
925940
mc.list !== nothing && visit(f, mc.list)
926941
mc.any !== nothing && visit(f, mc.any)
927942
nothing

src/datatype.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ JL_DLLEXPORT jl_methtable_t *jl_new_method_table(jl_sym_t *name, jl_module_t *mo
5454
mt->kwsorter = NULL;
5555
mt->backedges = NULL;
5656
JL_MUTEX_INIT(&mt->writelock);
57-
mt->offs = 1;
57+
mt->offs = 0;
5858
mt->frozen = 0;
5959
return mt;
6060
}
@@ -568,8 +568,8 @@ JL_DLLEXPORT jl_datatype_t *jl_new_datatype(
568568
// as an optimization
569569
tn->mt = jl_new_method_table(name, module);
570570
jl_gc_wb(tn, tn->mt);
571-
if (jl_svec_len(parameters) > 0)
572-
tn->mt->offs = 0;
571+
if (jl_svec_len(parameters) == 0 && !abstract)
572+
tn->mt->offs = 1;
573573
}
574574
else {
575575
// Everything else, gets to use the unified table

src/dump.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,22 +1053,6 @@ static void jl_serialize_value_(jl_serializer_state *s, jl_value_t *v, int as_li
10531053
}
10541054
return;
10551055
}
1056-
if (t == jl_typemap_level_type) {
1057-
// perform some compression on the typemap levels
1058-
// (which will need to be rehashed during deserialization anyhow)
1059-
jl_typemap_level_t *node = (jl_typemap_level_t*)v;
1060-
assert( // make sure this type has the expected ordering and layout
1061-
offsetof(jl_typemap_level_t, arg1) == 0 * sizeof(jl_value_t*) &&
1062-
offsetof(jl_typemap_level_t, targ) == 1 * sizeof(jl_value_t*) &&
1063-
offsetof(jl_typemap_level_t, linear) == 2 * sizeof(jl_value_t*) &&
1064-
offsetof(jl_typemap_level_t, any) == 3 * sizeof(jl_value_t*) &&
1065-
sizeof(jl_typemap_level_t) == 4 * sizeof(jl_value_t*));
1066-
jl_serialize_value(s, node->arg1);
1067-
jl_serialize_value(s, node->targ);
1068-
jl_serialize_value(s, node->linear);
1069-
jl_serialize_value(s, node->any);
1070-
return;
1071-
}
10721056

10731057
char *data = (char*)jl_data_ptr(v);
10741058
size_t i, j, np = t->layout->npointers;

src/jltypes.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,6 @@ void jl_init_types(void) JL_GC_DISABLED
17321732
jl_any_type->super = jl_any_type;
17331733
jl_nonfunction_mt = jl_any_type->name->mt;
17341734
jl_any_type->name->mt = NULL;
1735-
jl_nonfunction_mt->offs = 0;
17361735

17371736
jl_type_type = (jl_unionall_t*)jl_new_abstracttype((jl_value_t*)jl_symbol("Type"), core, jl_any_type, jl_emptysvec);
17381737
jl_type_typename = ((jl_datatype_t*)jl_type_type)->name;
@@ -1945,17 +1944,23 @@ void jl_init_types(void) JL_GC_DISABLED
19451944

19461945
jl_typemap_level_type =
19471946
jl_new_datatype(jl_symbol("TypeMapLevel"), core, jl_any_type, jl_emptysvec,
1948-
jl_perm_symsvec(4,
1947+
jl_perm_symsvec(7,
1948+
"bottom",
19491949
"arg1",
19501950
"targ",
1951+
"name1",
1952+
"tname",
19511953
"list",
19521954
"any"),
1953-
jl_svec(4,
1955+
jl_svec(7,
1956+
jl_any_type,
1957+
jl_any_type,
1958+
jl_any_type,
19541959
jl_any_type,
19551960
jl_any_type,
19561961
jl_any_type,
19571962
jl_any_type),
1958-
0, 1, 4);
1963+
0, 1, 7);
19591964

19601965
jl_typemap_entry_type =
19611966
jl_new_datatype(jl_symbol("TypeMapEntry"), core, jl_any_type, jl_emptysvec,

src/julia.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,14 +520,24 @@ typedef struct _jl_typemap_entry_t {
520520
int8_t va; // isVararg(sig)
521521
} jl_typemap_entry_t;
522522

523-
// one level in a TypeMap tree
524-
// indexed by key if it is a sublevel in an array
523+
// one level in a TypeMap tree (each level splits on a type at a given offset)
525524
typedef struct _jl_typemap_level_t {
526525
JL_DATA_TYPE
527-
jl_array_t *arg1;
528-
jl_array_t *targ;
529-
jl_typemap_entry_t *linear; // jl_typemap_t * (but no more levels)
530-
jl_typemap_t *any; // type at offs is Any
526+
// these vectors contains vectors of more levels in their intended visit order
527+
// with an index that gives the functionality of a sorted dict.
528+
// The first entry may be bottom (for entries which have no type at offs)
529+
// next split may be on Type{T} as LeafTypes then TypeNames parents up to Any
530+
// next split may be on LeafType
531+
// next split may be on TypeName
532+
jl_typemap_entry_t *bottom; // jl_typemap_t * (but no more levels) for entries which have no type at offs
533+
jl_array_t *arg1; // contains LeafType
534+
jl_array_t *targ; // contains Type{LeafType}
535+
jl_array_t *name1; // contains non-abstract TypeName
536+
jl_svec_t *tname; // contains a list of Type{TypeName} dicts, for parents up to Any
537+
// next a linear list of unsortable things (no more levels)
538+
jl_typemap_entry_t *linear;
539+
// finally, start a new level if the type at offs is Any
540+
jl_typemap_t *any;
531541
} jl_typemap_level_t;
532542

533543
// contains the TypeMap for one Type

src/julia_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ void jl_mach_gc_end(void);
10251025

10261026
typedef uint_t (*smallintset_hash)(size_t val, jl_svec_t *data);
10271027
typedef int (*smallintset_eq)(size_t val, const void *key, jl_svec_t *data, uint_t hv);
1028-
ssize_t jl_smallintset_lookup(jl_array_t *cache JL_PROPAGATES_ROOT, smallintset_eq eq, const void *key, jl_svec_t *data, uint_t hv);
1028+
ssize_t jl_smallintset_lookup(jl_array_t *cache, smallintset_eq eq, const void *key, jl_svec_t *data, uint_t hv);
10291029
void jl_smallintset_insert(jl_array_t **pcache, jl_value_t *parent, smallintset_hash hash, size_t val, jl_svec_t *data);
10301030

10311031
// -- typemap.c -- //

src/rtutils.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,10 @@ static size_t jl_static_show_x_(JL_STREAM *out, jl_value_t *v, jl_datatype_t *vt
670670
n += jl_static_show_x(out, li->uninferred, depth);
671671
}
672672
}
673+
else if (vt == jl_typename_type) {
674+
n += jl_static_show_x(out, jl_unwrap_unionall(((jl_typename_t*)v)->wrapper), depth);
675+
n += jl_printf(out, ".name");
676+
}
673677
else if (vt == jl_simplevector_type) {
674678
n += jl_show_svec(out, (jl_svec_t*)v, "svec", "(", ")");
675679
}

0 commit comments

Comments
 (0)