19536, "stonea", "Tuple unpacking to initialize variables in forall loop (that were declared outside the loop) results in internal error", "2022-03-24T00:50:27Z"
Summary of Problem
I'm trying to write a program that searches a 2D domain (in parallel) and wants to communicate its result outside the loop. My first attempt was something like this but it errors out with an internal error:
// This errors with:
// foo.chpl:3: internal error: Unhandled type in blankIntentForType() [passes/resolveIntents.cpp:168]
var a,b;
forall (i,j) in {0..99, 0..99} {
if(i == 5 && j == 5) {
(a,b) = (i,j);
}
}
writeln(a, " ", b);
Note I don't think this would work anyway due to the issue described in this comment:
Error message improvement request: Change split initialization tuple unpacking error message · Issue #16086 · chapel-lang/chapel · GitHub but we certainly shouldn't be getting an internal error.
If I explode the tuple unpacking I'll get a different error but I think this is expected:
// foo.chpl:16: error: cannot assign to const variable
// foo.chpl:14: note: The shadow variable 'a' is constant due to forall intents in this loop
// ...
var a, b : int;
forall (i,j) in {0..99, 0..99} {
if(i == 5 && j == 5) {
a = i;
b = j;
}
}
writeln(a, " ", b);
I suppose the "right" thing to do in this case is something like this:
var a = 0, b = 0 : int;
forall (i,j) in {0..99, 0..99} with(ref a, ref b) {
if(i == 5 && j == 5) {
(a, b) = (i, j);
}
}
writeln(a, " ", b);
Steps to Reproduce
Source Code:
See first example at top of issue
Configuration Information
$ chpl --version
chpl version 1.26.0
built with LLVM version 11.1.0
Copyright 2020-2022 Hewlett Packard Enterprise Development LP
Copyright 2004-2019 Cray Inc.
(See LICENSE file for more details)
$ printchplenv --anonymize
CHPL_TARGET_PLATFORM: darwin
CHPL_TARGET_COMPILER: llvm
CHPL_TARGET_ARCH: x86_64
CHPL_TARGET_CPU: native
CHPL_LOCALE_MODEL: flat
CHPL_COMM: none
CHPL_TASKS: qthreads
CHPL_LAUNCHER: none
CHPL_TIMERS: generic
CHPL_UNWIND: none
CHPL_MEM: jemalloc
CHPL_ATOMICS: cstdlib
CHPL_GMP: bundled
CHPL_HWLOC: bundled
CHPL_RE2: bundled
CHPL_LLVM: system
CHPL_AUX_FILESYS: none