From 90a3f03133470c84c9475f7e0fdbeda028b7d30e Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Wed, 28 Sep 2022 09:54:34 -0400 Subject: [PATCH] codegen: fix compute_va_type issue with Type Issue noted in #42498. This should be the same as Core.Compiler.tuple_tfunc. Otherwise we might accidentally constant-fold something like: code_llvm((x...) -> x isa Tuple{Type{Tuple{Any}},Int}, (Type{Tuple{Any}}, Int)) to return true. This is rarely a compile-sig in practice, so it does not usually affect code, but is observable there in the IR. --- src/codegen.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index 1298e07525a62..9c09314c9aee1 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -2144,12 +2144,7 @@ static void jl_init_function(Function *F) static std::pair uses_specsig(jl_method_instance_t *lam, jl_value_t *rettype, bool prefer_specsig) { - size_t nreq = jl_is_method(lam->def.method) ? lam->def.method->nargs : 0; - int va = 0; - if (nreq > 0 && lam->def.method->isva) { - nreq--; - va = 1; - } + int va = lam->def.method->isva; jl_value_t *sig = lam->specTypes; bool needsparams = false; if (jl_is_method(lam->def.method)) { @@ -6594,6 +6589,7 @@ get_specsig_di(jl_codectx_t &ctx, jl_debugcache_t &debuginfo, jl_value_t *rt, jl return dbuilder.createSubroutineType(dbuilder.getOrCreateTypeArray(ditypes)); } +/* aka Core.Compiler.tuple_tfunc */ static jl_datatype_t *compute_va_type(jl_method_instance_t *lam, size_t nreq) { size_t nvargs = jl_nparams(lam->specTypes)-nreq; @@ -6601,6 +6597,12 @@ static jl_datatype_t *compute_va_type(jl_method_instance_t *lam, size_t nreq) JL_GC_PUSH1(&tupargs); for (size_t i = nreq; i < jl_nparams(lam->specTypes); ++i) { jl_value_t *argType = jl_nth_slot_type(lam->specTypes, i); + if (is_uniquerep_Type(argType)) + argType = jl_typeof(jl_tparam0(argType)); + else if (jl_has_intersect_type_not_kind(argType)) { + jl_value_t *ts[2] = {argType, (jl_value_t*)jl_type_type}; + argType = jl_type_union(ts, 2); + } jl_svecset(tupargs, i-nreq, argType); } jl_datatype_t *typ = jl_apply_tuple_type(tupargs);