Skip to content

Commit 935df0d

Browse files
committed
dispatch: tolerate un-sorted tables and support non-transitive specificity
1 parent fb8b5eb commit 935df0d

File tree

10 files changed

+466
-364
lines changed

10 files changed

+466
-364
lines changed

base/compiler/ssair/inlining.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ function compute_invoke_data(@nospecialize(atypes), params::Params)
11301130
invoke_entry = ccall(:jl_gf_invoke_lookup, Any, (Any, UInt),
11311131
invoke_types, params.world) # XXX: min_valid, max_valid
11321132
invoke_entry === nothing && return nothing
1133-
invoke_data = InvokeData(invoke_entry, invoke_types, min_valid[1], max_valid[1])
1133+
invoke_data = InvokeData(invoke_entry::Core.TypeMapEntry, invoke_types, min_valid[1], max_valid[1])
11341134
atype0 = atypes[2]
11351135
atypes = atypes[4:end]
11361136
pushfirst!(atypes, atype0)

src/codegen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5078,7 +5078,7 @@ static Function *jl_cfunction_object(jl_value_t *ff, jl_value_t *declrt, jl_tupl
50785078
if (!insert)
50795079
insert = jl_nothing;
50805080
cache_l3 = jl_typemap_insert(&insert, (jl_value_t*)insert, (jl_tupletype_t*)argt,
5081-
NULL, jl_emptysvec, (jl_value_t*)jl_emptysvec, /*offs*/0, &cfunction_cache, 1, ~(size_t)0, NULL);
5081+
NULL, jl_emptysvec, (jl_value_t*)jl_emptysvec, /*offs*/0, &cfunction_cache, 1, ~(size_t)0);
50825082
if (insert != cache_l2)
50835083
jl_cfunction_list = jl_eqtable_put(jl_cfunction_list, ft, insert, NULL);
50845084
}

src/dump.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,10 +810,14 @@ static void jl_serialize_value_(jl_serializer_state *s, jl_value_t *v, int as_li
810810
jl_serialize_value(s, (jl_value_t*)m->name);
811811
jl_serialize_value(s, (jl_value_t*)m->file);
812812
write_int32(s->s, m->line);
813-
if (external_mt)
813+
if (external_mt) {
814814
jl_serialize_value(s, jl_nothing);
815-
else
815+
jl_serialize_value(s, jl_nothing);
816+
}
817+
else {
816818
jl_serialize_value(s, (jl_value_t*)m->ambig);
819+
jl_serialize_value(s, (jl_value_t*)m->resorted);
820+
}
817821
write_int32(s->s, m->called);
818822
write_int32(s->s, m->nargs);
819823
write_int32(s->s, m->nospecialize);
@@ -1683,6 +1687,8 @@ static jl_value_t *jl_deserialize_value_method(jl_serializer_state *s, jl_value_
16831687
m->deleted_world = ~(size_t)0;
16841688
m->ambig = jl_deserialize_value(s, (jl_value_t**)&m->ambig);
16851689
jl_gc_wb(m, m->ambig);
1690+
m->resorted = jl_deserialize_value(s, (jl_value_t**)&m->resorted);
1691+
jl_gc_wb(m, m->resorted);
16861692
m->called = read_int32(s->s);
16871693
m->nargs = read_int32(s->s);
16881694
m->nospecialize = read_int32(s->s);

src/gf.c

Lines changed: 353 additions & 209 deletions
Large diffs are not rendered by default.

src/jltypes.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,7 +2113,7 @@ void jl_init_types(void) JL_GC_DISABLED
21132113
jl_method_type =
21142114
jl_new_datatype(jl_symbol("Method"), core,
21152115
jl_any_type, jl_emptysvec,
2116-
jl_perm_symsvec(20,
2116+
jl_perm_symsvec(21,
21172117
"name",
21182118
"module",
21192119
"file",
@@ -2122,6 +2122,7 @@ void jl_init_types(void) JL_GC_DISABLED
21222122
"deleted_world",
21232123
"sig",
21242124
"ambig",
2125+
"resorted",
21252126
"specializations",
21262127
"slot_syms",
21272128
"source",
@@ -2134,15 +2135,16 @@ void jl_init_types(void) JL_GC_DISABLED
21342135
"nospecialize",
21352136
"isva",
21362137
"pure"),
2137-
jl_svec(20,
2138+
jl_svec(21,
21382139
jl_symbol_type,
21392140
jl_module_type,
21402141
jl_symbol_type,
21412142
jl_int32_type,
21422143
jl_ulong_type,
21432144
jl_ulong_type,
21442145
jl_type_type,
2145-
jl_any_type, // Union{Array, Nothing}
2146+
jl_any_type, // Union{Vector, Nothing}
2147+
jl_any_type, // Union{Vector, Nothing}
21462148
jl_any_type, // TypeMap
21472149
jl_string_type,
21482150
jl_any_type,
@@ -2155,7 +2157,7 @@ void jl_init_types(void) JL_GC_DISABLED
21552157
jl_int32_type,
21562158
jl_bool_type,
21572159
jl_bool_type),
2158-
0, 1, 10);
2160+
0, 1, 11);
21592161

21602162
jl_method_instance_type =
21612163
jl_new_datatype(jl_symbol("MethodInstance"), core,
@@ -2314,7 +2316,7 @@ void jl_init_types(void) JL_GC_DISABLED
23142316
#endif
23152317
jl_svecset(jl_methtable_type->types, 9, jl_uint8_type);
23162318
jl_svecset(jl_methtable_type->types, 10, jl_uint8_type);
2317-
jl_svecset(jl_method_type->types, 11, jl_method_instance_type);
2319+
jl_svecset(jl_method_type->types, 12, jl_method_instance_type);
23182320
jl_svecset(jl_method_instance_type->types, 5, jl_code_instance_type);
23192321
jl_svecset(jl_code_instance_type->types, 7, jl_voidpointer_type);
23202322
jl_svecset(jl_code_instance_type->types, 8, jl_voidpointer_type);

src/julia.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ typedef struct _jl_method_t {
283283

284284
// list of potentially-ambiguous methods (nothing = none, Vector{Any} of TypeMapEntry otherwise)
285285
jl_value_t *ambig;
286+
// forward references to later items (typemap entries) which might sort before this one
287+
jl_value_t *resorted;
286288

287289
// table of all jl_method_instance_t specializations we have
288290
jl_typemap_t *specializations;

src/julia_internal.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,6 @@ JL_DLLEXPORT jl_array_t *jl_idtable_rehash(jl_array_t *a, size_t newsz);
565565

566566
JL_DLLEXPORT jl_methtable_t *jl_new_method_table(jl_sym_t *name, jl_module_t *module);
567567
jl_method_instance_t *jl_get_specialization1(jl_tupletype_t *types, size_t world, size_t *min_valid, size_t *max_valid, int mt_cache);
568-
JL_DLLEXPORT int jl_has_call_ambiguities(jl_value_t *types, jl_method_t *m);
569568
jl_method_instance_t *jl_get_specialized(jl_method_t *m, jl_value_t *types, jl_svec_t *sp);
570569
JL_DLLEXPORT jl_value_t *jl_rettype_inferred(jl_method_instance_t *li, size_t min_world, size_t max_world);
571570
JL_DLLEXPORT jl_value_t *jl_methtable_lookup(jl_methtable_t *mt, jl_value_t *type, size_t world);
@@ -919,8 +918,7 @@ jl_typemap_entry_t *jl_typemap_insert(jl_typemap_t **cache,
919918
jl_tupletype_t *simpletype, jl_svec_t *guardsigs,
920919
jl_value_t *newvalue, int8_t offs,
921920
const struct jl_typemap_info *tparams,
922-
size_t min_world, size_t max_world,
923-
jl_value_t **overwritten);
921+
size_t min_world, size_t max_world);
924922

925923
jl_typemap_entry_t *jl_typemap_assoc_by_type(
926924
jl_typemap_t *ml_or_cache JL_PROPAGATES_ROOT,
@@ -943,7 +941,6 @@ STATIC_INLINE jl_typemap_entry_t *jl_typemap_assoc_exact(
943941
}
944942
return NULL;
945943
}
946-
947944
typedef int (*jl_typemap_visitor_fptr)(jl_typemap_entry_t *l, void *closure);
948945
int jl_typemap_visitor(jl_typemap_t *a, jl_typemap_visitor_fptr fptr, void *closure);
949946

src/method.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ JL_DLLEXPORT jl_method_t *jl_new_method_uninit(jl_module_t *module)
573573
m->sig = NULL;
574574
m->slot_syms = NULL;
575575
m->ambig = jl_nothing;
576+
m->resorted = jl_nothing;
576577
m->roots = NULL;
577578
m->module = module;
578579
m->source = NULL;

0 commit comments

Comments
 (0)