New Issue: unnecessary instantiations for generic functions with later concrete arguments

16470, “mppf”, “unnecessary instantiations for generic functions with later concrete arguments”, “2020-09-25T16:38:32Z”

When helping @ronawho with an issue with Arkouda running into the max instantiation limit for _cast with 1.22, I noticed that the compiler does not rule out a function with a concrete formal after a generic one if the formal does not match.

For example:

use CPtr;

proc mockcast(type t, arg: int(32)) where t == string
{
}

proc mockcast(type t:c_ptr, arg: c_ptr)
{
}


var n32 = 1:int(32);
mockcast(string, n32);
var n32ptr = c_ptrTo(n32);
mockcast(c_ptr(int(8)), n32ptr);

when compiled with this patch to the compiler:

diff --git a/compiler/resolution/generics.cpp b/compiler/resolution/generics.cpp
index d219af80ab..fb16f1c0d6 100644
--- a/compiler/resolution/generics.cpp
+++ b/compiler/resolution/generics.cpp
@@ -800,6 +800,8 @@ FnSymbol* instantiateFunction(FnSymbol*  fn,
   return newFn;
 }
 
+#include "view.h"