From 7d7b2dd076654cf785ffd829878b15c5c02619ae Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Fri, 22 Mar 2019 05:48:23 -0500 Subject: [PATCH] Allow replacement of jl_typeinf_func Fixes #31429 --- src/gf.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/gf.c b/src/gf.c index 9bb6dcbcf6655..d697131520e56 100644 --- a/src/gf.c +++ b/src/gf.c @@ -521,20 +521,22 @@ size_t jl_typeinf_world = 0; JL_DLLEXPORT void jl_set_typeinf_func(jl_value_t *f) { jl_typeinf_func = (jl_function_t*)f; - jl_typeinf_world = jl_get_tls_world_age(); - ++jl_world_counter; // make type-inference the only thing in this world - // give type inference a chance to see all of these - // TODO: also reinfer if max_world != ~(size_t)0 - jl_array_t *unspec = jl_alloc_vec_any(0); - JL_GC_PUSH1(&unspec); - jl_foreach_reachable_mtable(reset_mt_caches, (void*)unspec); - size_t i, l; - for (i = 0, l = jl_array_len(unspec); i < l; i++) { - jl_method_instance_t *li = (jl_method_instance_t*)jl_array_ptr_ref(unspec, i); - if (!jl_is_rettype_inferred(li)) - jl_type_infer(&li, jl_world_counter, 1); + if (jl_typeinf_world == 0) { + jl_typeinf_world = jl_get_tls_world_age(); + ++jl_world_counter; // make type-inference the only thing in this world + // give type inference a chance to see all of these + // TODO: also reinfer if max_world != ~(size_t)0 + jl_array_t *unspec = jl_alloc_vec_any(0); + JL_GC_PUSH1(&unspec); + jl_foreach_reachable_mtable(reset_mt_caches, (void*)unspec); + size_t i, l; + for (i = 0, l = jl_array_len(unspec); i < l; i++) { + jl_method_instance_t *li = (jl_method_instance_t*)jl_array_ptr_ref(unspec, i); + if (!jl_is_rettype_inferred(li)) + jl_type_infer(&li, jl_world_counter, 1); + } + JL_GC_POP(); } - JL_GC_POP(); } static int very_general_type(jl_value_t *t)