External Issue: Support query expressions for components of array element type

20179, "milthorpe", "Support query expressions for components of array element type", "2022-07-08T01:31:39Z"

I would like to define a procedure over an array of tuples, where one of the tuple components is of a generic type. I believe this would naturally be written as follows:

proc f(a: [] (?t, int)) { }
// example instantiation for tuple of (real, int)
var realArr = [ (3.0, 1) ];
f( realArr );

However, when I compile the above code with Chapel 1.27, I get the following error message:

genericTupleArray.chpl:1: In function 'f':
genericTupleArray.chpl:1: error: Query expressions are not currently supported in this context
  genericTupleArray.chpl:1: called as f(a: [domain(1,int(64),false)] (real(64),int(64)))
note: generic instantiations are underlined in the above callstack

More confusingly, if I actually try to refer to type t anywhere in the procedure -- e.g. var big: max(t); -- I get a different compiler message:

genericTupleArray.chpl:1: In function 'f':
genericTupleArray.chpl:2: error: 't' used before defined
genericTupleArray.chpl:1: note: defined here

@bradcray suggested that it should be possible to access the individual component types of a tuple type, but that doesn't currently seem to be supported, e.g.

proc f(a: [] ?et) where isTupleType(et) && et.size == 2 && et(1) == int {
  type t = et(0);

(Fails to compile with unresolved call '(real(64),int(64))(1)' ... note: because no functions named (real(64),int(64)) found in scope.)

Brad also suggested a workaround to explicitly instantiate the array element type and then query the component types from that:

proc f(a: [] ?et) where isTupleType(et) && et.size == 2 {
  var dummy: et;
  if dummy(1).type != int then
    compilerError("the second element of the tuples must be int");
  type t = dummy(0).type;

This works fine, but is obviously a little clunky. It would be nice if Chapel allowed me to use a query expression on the component of the array element type.