New Issue: What should behavior be for nested use of unsafeAssign manager?

19591, "stonea", "What should behavior be for nested use of unsafeAssign manager?", "2022-04-01T22:32:31Z"

Summary of Problem

The more I think about this the more I'm convinced that this isn't really a bug and the current behavior is correct. Nevertheless, at first I found the behavior (in the following example) somewhat surprising.

I'll post it anyway on the off-chance that it spurs conversation but feel free to close if the sentiment is "yeah of course this won't work what were you thinking?".

class C {
  var prop : int;
  proc init(x) { prop = x; }
}

var D = {0..0};
var A: [D] shared C = [new shared C(0)];

manage D.unsafeAssign({0..2}, checks=true) as mgr {
  manage D.unsafeAssign({0..1}, checks=true) as mgr {
    mgr.initialize(A, 1, new shared C(1));
  }
  mgr.initialize(A, 2, new shared C(A[1].prop));
}
writeln(A);

Produced this error:

foo.chpl:13: error: halt reached - Array index out of bounds: 2

Note the error is happening on the second call to mgr.initialize in the outer loop (where I'm thinking that I'm in a context where D is reshaped to 0..2).

I think my confusion came from thinking about unsafeAssign as setting up a series of transactions to safely populate the new elements that occurs when you exit the block. But I guess that's not really the right way to view things. Rather the resize occurs as soon as you enter the block and the assertion that all elements have been assigned occurs at the end.

Steps to Reproduce

Compile and run example in summary.

Configuration Information

$ chpl --version
chpl version 1.27.0 pre-release (a4373b47a9)
  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)

$ $CHPL_HOME/util/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

$ clang --version
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin