Skip to content

Commit

Permalink
codegen: fix compute_va_type issue with Type (#46953)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vtjnash authored Sep 29, 2022
1 parent 8e44510 commit 170d643
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2144,12 +2144,7 @@ static void jl_init_function(Function *F)

static std::pair<bool, bool> 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)) {
Expand Down Expand Up @@ -6594,13 +6589,20 @@ 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;
jl_svec_t *tupargs = jl_alloc_svec(nvargs);
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);
Expand Down

0 comments on commit 170d643

Please sign in to comment.