diff --git a/base/compiler/typeinfer.jl b/base/compiler/typeinfer.jl index f7dbcbea8481e..3ddc4c9faf2df 100644 --- a/base/compiler/typeinfer.jl +++ b/base/compiler/typeinfer.jl @@ -626,7 +626,12 @@ end function return_type(@nospecialize(f), @nospecialize(t)) - params = Params(ccall(:jl_get_tls_world_age, UInt, ())) + world = ccall(:jl_get_tls_world_age, UInt, ()) + return ccall(:jl_call_in_typeinf_world, Any, (Ptr{Ptr{Cvoid}}, Cint), Any[_return_type, f, t, world], 4) +end + +function _return_type(@nospecialize(f), @nospecialize(t), world) + params = Params(world) rt = Union{} if isa(f, Builtin) rt = builtin_tfunction(f, Any[t.parameters...], nothing, params) diff --git a/src/gf.c b/src/gf.c index 520db1ab45a98..3eea4b00108c9 100644 --- a/src/gf.c +++ b/src/gf.c @@ -289,6 +289,16 @@ jl_code_info_t *jl_type_infer(jl_method_instance_t **pli, size_t world, int forc return src; } +JL_DLLEXPORT jl_value_t *jl_call_in_typeinf_world(jl_value_t **args, int nargs) +{ + jl_ptls_t ptls = jl_get_ptls_states(); + size_t last_age = ptls->world_age; + ptls->world_age = jl_typeinf_world; + jl_value_t *ret = jl_apply(args, nargs); + ptls->world_age = last_age; + return ret; +} + int jl_is_rettype_inferred(jl_method_instance_t *li) { if (!li->inferred)