20575, "jeremiah-corrado", "Strange instantiation limit behavior with where-clauses", "2022-08-31T21:56:28Z"
The following is a sort of strange corner-case bug that likely doesn't need any attention in the near term, but I thought it would be good to document while I have it on my mind.
Consider the following program which uses both where-clauses and the fn exempt instantiation limit
pragma:
// param to select between two implementations of foo at compile time
config param ZeroIndexed = false;
// an implementation of foo that is not exempt from instantiation limits
proc foo(param n) where ZeroIndexed == true {
var a : [0..<n] int;
// ...
}
// a different implementation of foo that is exempt
pragma "fn exempt instantiation limit"
proc foo(param n) where ZeroIndexed == false {
var a : [1..n] int;
// ...
}
// instantiate 'foo' one too many times (the limit is 512)
for param n in 1..513 do foo(n);
When compiling the above program with -s ZeroIndexed=false
, the following error message is emitted:
inst_limit_bug.chpl:5: error: Function 'foo' has been instantiated too many times
note: If this is intentional, try increasing the instantiation limit from 512
And when compiling with -s ZeroIndexed=true
, the program compiles and runs without any errors.
In other words, its as if the pragma "fn exempt instantiation limit"
were applied to the zero-indexed version of foo rather than the non-zero-indexed version. Note that the line number on the error message is also incorrect.