New Issue: [Bug]: Promotion over array of arrays

25595, "benharsh", "[Bug]: Promotion over array of arrays", "2024-07-17T21:13:24Z"

The following program currently fails to compile in Chapel 2.2, but only when the --verify flag is thrown:


record R {
  var A : [1..4] real;

  proc init() {
    init this;
    for i in A.domain do A[i] = i:real;
  }
}

proc main() {
  var X, Y : [1..4] R;
  var dt = 3.14;

  for i in Y.domain do
    for j in Y[i].A.domain do Y[i].A[j] = (i*j):real;

  X.A += dt * Y.A; // here's the problem!

  for x in X do
    writeln(x.A);
}

The problem comes from the line X.A += dt * Y.A, which gets promoted to something like this:

forall (x, y) in zip(X, Y) do
  x.A += dt * y.A;

Here, we encounter a second level of promotion for both the multiplication operator and the += operator.

The compiler fails with an internal assertion like this:

$CHPL_HOME/modules/internal/ChapelIteratorSupport.chpl:116: In function 'iteratorToArrayElementType':
$CHPL_HOME/modules/internal/ChapelIteratorSupport.chpl:120: internal error: actual formal type mismatch for chpl_buildStandInRTT: _ref(_array(unmanaged DefaultRectangularArr(1,int(64),one,real(64),int(64)))) != _RuntimeTypeInfo [main/checks.cpp:944]
  $CHPL_HOME/modules/internal/ChapelArray.chpl:3553: called as iteratorToArrayElementType(type t = _ir_chpl_promo1_A__ref__array_DefaultRectangularArr_1_int64_t_one_R_int64_t) from function 'chpl__initCopy_shapeHelp'
  $CHPL_HOME/modules/internal/ChapelArray.chpl:3533: called as chpl__initCopy_shapeHelp(shape: domain(unmanaged DefaultRectangularDom(1,int(64),one)), ir: _ir_chpl_promo1_A__ref__array_DefaultRectangularArr_1_int64_t_one_R_int64_t) from function 'chpl__initCopy'

The issue appears to be that PRIM_SCALAR_PROMOTION_TYPE is returning the static array type for the iterator record, rather than the runtime type.

For some as-yet-unknown reason this program can still successfully compile and run without the --verify flag, seemingly because the offending AST is dead-code-eliminated somewhere along the way.

Issue #10921 may be relevant here.

Associated Future Test(s):
pending