chapel-lang / chapel

a Productive Parallel Programming Language
https://chapel-lang.org
Other
1.8k stars 423 forks source link

typed array argument with in or out intent does not accept a Block distributed array #15014

Open mppf opened 4 years ago

mppf commented 4 years ago

In the following example, a Block-distributed array is passed to an in intent arg. The result is compilation error. If the in intent is removed, the program compiles.

use BlockDist;

proc g(in arg:[1..10] int) {
  writeln(arg.domain.dist);
  writeln(arg.domain);
}

proc bar() {
  var A = newBlockArr(1..10, int);
  g(A);
}
bar();
t.chpl:8: In function 'bar':
t.chpl:10: error: unresolved call 'g([BlockDom(1,int(64),false,unmanaged DefaultDist)] int(64))'
t.chpl:3: note: this candidate did not match: g(in arg: [1..10] int)
t.chpl:10: note: because call actual argument #1 with type [BlockDom(1,int(64),false,unmanaged DefaultDist)] int(64)
t.chpl:3: note: is passed to formal 'in arg: [domain(1,int(64),false)] int(64)'

This issue is also present with out intent arguments after PR #14917.

I can't find any information in the language specification about the array-arguments-are-generic behavior so resolving this issue should also update the spec. There is some description here: https://chapel-lang.org/docs/language/spec/arrays.html#array-arguments-to-functions .

bradcray commented 4 years ago

For additional context, some time ago, we decided that default rectangular formal argument intents would be considered generic w.r.t. the actual's domain map in order to support a somewhat common case (a formal that wanted to say something about an array's size, but didn't want to prevent other domain maps / distributions from being passed in). I hadn't realized that the existing support was sensitive to the intents used.

mppf commented 3 years ago

@bradcray mentioned an expectation of a difference between a domain being declared or not:

I believe that if the domain is DR, it’s generic, such that X: [1..n] real could accept a block-distributed array over {1..n}, say. On the other hand, if the formal is X: [D] real where D is a block-distributed domain, it should not be generic, but should literally require an array over that domain (IIRC).