Skip to content

Commit 01c871c

Browse files
committed
specialize on all tuple types. fixes #11100
1 parent 32f5a51 commit 01c871c

File tree

1 file changed

+1
-95
lines changed

1 file changed

+1
-95
lines changed

src/gf.c

Lines changed: 1 addition & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,7 @@ static int cache_match_by_type(jl_value_t **types, size_t n, jl_tupletype_t *sig
7777
}
7878
}
7979
jl_value_t *a = types[i];
80-
if (jl_is_tuple_type(decl)) {
81-
// tuples don't have to match exactly, to avoid caching
82-
// signatures for tuples of every length
83-
if (!jl_subtype(a, decl, 0))
84-
return 0;
85-
}
86-
else if (jl_is_datatype(a) && jl_is_datatype(decl) &&
80+
if (jl_is_datatype(a) && jl_is_datatype(decl) &&
8781
((jl_datatype_t*)decl)->name == jl_type_type->name &&
8882
((jl_datatype_t*)a )->name == jl_type_type->name) {
8983
jl_value_t *tp0 = jl_tparam0(decl);
@@ -132,15 +126,6 @@ static inline int cache_match(jl_value_t **args, size_t n, jl_tupletype_t *sig,
132126
hash-consed, so pointer comparison should work.
133127
*/
134128
}
135-
else if (jl_is_tuple_type(decl)) {
136-
// tuples don't have to match exactly, to avoid caching
137-
// signatures for tuples of every length
138-
jl_datatype_t *ta = (jl_datatype_t*)jl_typeof(a);
139-
if (!jl_is_tuple_type(ta) || //!jl_subtype(a, decl, 1))
140-
!jl_tuple_subtype(jl_svec_data(ta->parameters), jl_datatype_nfields(ta),
141-
(jl_datatype_t*)decl, 0))
142-
return 0;
143-
}
144129
else if (jl_is_type_type(decl) && jl_is_type(a)) {
145130
jl_value_t *tp0 = jl_tparam0(decl);
146131
if (tp0 == (jl_value_t*)jl_typetype_tvar) {
@@ -473,19 +458,6 @@ static int is_kind(jl_value_t *v)
473458
v==(jl_value_t*)jl_typector_type);
474459
}
475460

476-
static int jl_is_specializable_tuple(jl_tupletype_t *t)
477-
{
478-
if (jl_nparams(t)==0) return 1;
479-
jl_value_t *e0 = jl_tparam(t,0);
480-
if (jl_is_tuple_type(e0) || e0 == (jl_value_t*)jl_datatype_type) return 0;
481-
size_t i, l=jl_nparams(t);
482-
// allow specialization on homogeneous tuples
483-
for(i=1; i < l; i++) {
484-
if (jl_tparam(t,i) != e0) return 0;
485-
}
486-
return 1;
487-
}
488-
489461
static jl_value_t *ml_matches(jl_methlist_t *ml, jl_value_t *type,
490462
jl_sym_t *name, int lim);
491463

@@ -559,72 +531,6 @@ static jl_function_t *cache_method(jl_methtable_t *mt, jl_tupletype_t *type,
559531
}
560532
if (set_to_any) {
561533
}
562-
else if (jl_is_tuple_type(elt) && !jl_is_specializable_tuple((jl_tupletype_t*)elt)) {
563-
/*
564-
don't cache tuple type exactly; just remember that it was
565-
a tuple, unless the declaration asks for something more
566-
specific. determined with a type intersection.
567-
*/
568-
int might_need_guard=0;
569-
if (i < jl_nparams(decl)) {
570-
jl_value_t *declt = jl_tparam(decl,i);
571-
if (jl_is_vararg_type(declt))
572-
declt = jl_tparam0(declt);
573-
// note: ignore va flag (for T..., intersect with T)
574-
if (!jl_has_typevars(declt)) {
575-
if (declt == (jl_value_t*)jl_anytuple_type ||
576-
jl_subtype((jl_value_t*)jl_anytuple_type, declt, 0)) {
577-
// don't specialize args that matched (Any...) or Any
578-
jl_svecset(newparams, i, (jl_value_t*)jl_anytuple_type);
579-
might_need_guard = 1;
580-
}
581-
else {
582-
declt = jl_type_intersection(declt, (jl_value_t*)jl_anytuple_type);
583-
if (jl_nparams(elt) > 3 ||
584-
(jl_is_tuple_type(declt) && tuple_all_Any((jl_tupletype_t*)declt))) {
585-
jl_svecset(newparams, i, declt);
586-
might_need_guard = 1;
587-
}
588-
}
589-
}
590-
}
591-
else {
592-
jl_svecset(newparams, i, (jl_value_t*)jl_anytuple_type);
593-
might_need_guard = 1;
594-
}
595-
assert(jl_svecref(newparams,i) != (jl_value_t*)jl_bottom_type);
596-
if (might_need_guard) {
597-
jl_methlist_t *curr = mt->defs;
598-
// can't generalize type if there's an overlapping definition
599-
// with typevars.
600-
// TODO: it seems premature to take these intersections
601-
// before the whole signature has been generalized.
602-
// example ((T...,),S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,...)
603-
temp2 = (jl_value_t*)jl_svec_copy(newparams);
604-
temp2 = (jl_value_t*)jl_apply_tuple_type((jl_svec_t*)temp2);
605-
while (curr != (void*)jl_nothing && curr->func!=method) {
606-
if (curr->tvars!=jl_emptysvec &&
607-
jl_type_intersection((jl_value_t*)curr->sig, (jl_value_t*)temp2) !=
608-
(jl_value_t*)jl_bottom_type) {
609-
jl_svecset(newparams, i, jl_tparam(type, i));
610-
might_need_guard = 0;
611-
break;
612-
}
613-
curr = curr->next;
614-
}
615-
}
616-
if (might_need_guard) {
617-
jl_methlist_t *curr = mt->defs;
618-
while (curr != (void*)jl_nothing && curr->func!=method) {
619-
jl_tupletype_t *sig = curr->sig;
620-
if (jl_nparams(sig) > i && jl_is_tuple_type(jl_tparam(sig,i))) {
621-
need_guard_entries = 1;
622-
break;
623-
}
624-
curr = curr->next;
625-
}
626-
}
627-
}
628534
else if (jl_is_type_type(elt) && jl_is_type_type(jl_tparam0(elt)) &&
629535
// give up on specializing static parameters for Type{Type{Type{...}}}
630536
(jl_is_type_type(jl_tparam0(jl_tparam0(elt))) ||

0 commit comments

Comments
 (0)