[Chapel Merge] Avoid top-level TPVs when no top-level yields

Branch: refs/heads/master
Revision: c7dbf2a
Author: vasslitvinov
Log Message:

Merge pull request #16467 from vasslitvinov/no-toplevel-tpvs

Avoid top-level TPVs when no top-level yields

Resolves #16366

We used to create a top-level TPV (task-private variable) for a forall loop
to accomodate “top-level yields” in the corresponding parallel iterator
in case it has such yields. Given that creating and deleting a TPV can be
expensive and it is a common case that the parallel iterator does not have
top-level yields, this change stops creating such TPVs.

A “top-level yield” is a yield outside any parallel constructs.
The corresponding TPV is created in the task that starts the forall loop.
Parallel constructs are coforall, cobegin, begin, forall loops, and also
for-loops over parallel iterators. Prominent examples of the latter are
the parallel iterators on arrays, i.e. standalone and leader _array.these().

In this example:

iter myIter() {...}
iter myIter(param tag) where tag == iterKind.standalone {
  coforall ..... {
yield 3; // not a "top-level yield"
  }

  yield 4;   // yes, a "top-level yield"
}

forall idx in myIter() with (var tpv: MyType) {
  writeln(idx, " : ", tpv);
}

the “top-level” task-private variable tpv is the one referenced
in the loop body for the iteration when idx==4.
If we remove yield 4 from the standalone myIter, such TPV
is no longer allocated.

This PR updates the tests to account for the absence of these TPVs.
Primarily this means shifting task IDs (implemented by the tests
themselves with an atomic counter) to start from 0 instead of 1 or 2.

We wondered whether this change would also revert the additional
init+deinit pairs introduced by #16401 in
test/statements/ferguson/var-init-records.good
Turns out it does not revert those. They occur within
proc chpl__coerceMove(type dstType:_array, in rhs:desyncEltType(dstType), definedConst: bool)
The forall loop there has an in-intent, not a TPV,
so is not affected by this PR.

Reviewed by @ronawho and @mppf - thank you!

Modified Files:
A test/parallel/forall/task-private-vars/count-tpvs.chpl
A test/parallel/forall/task-private-vars/count-tpvs.good
A test/parallel/forall/task-private-vars/count-tpvs.numlocales
A test/parallel/forall/task-private-vars/throwing-init-exprs/int-no-tlvy.0.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/int-no-tlvy.1-2.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/int-no-tlvy.1-20.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/int-no-tlvy.1-2000.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/int-no-tlvy.1.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/int-no-tlvy.10-2.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/int-no-tlvy.10-20.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/int-no-tlvy.10-2000.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/int-no-tlvy.10.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/int-no-tlvy.1000-2.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/int-no-tlvy.1000-20.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/int-no-tlvy.1000-2000.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/int-no-tlvy.1000.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/int-no-tlvy.2.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/int-no-tlvy.20.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/int-no-tlvy.2000.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/int-no-tlvy.chpl
A test/parallel/forall/task-private-vars/throwing-init-exprs/int-no-tlvy.execopts
A test/parallel/forall/task-private-vars/throwing-init-exprs/int-no-tlvy.prediff
A test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.1000.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/pod-no-tlvy.0.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/pod-no-tlvy.1-2.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/pod-no-tlvy.1-20.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/pod-no-tlvy.1-2000.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/pod-no-tlvy.1.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/pod-no-tlvy.10-2.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/pod-no-tlvy.10-20.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/pod-no-tlvy.10-2000.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/pod-no-tlvy.10.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/pod-no-tlvy.1000-2.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/pod-no-tlvy.1000-20.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/pod-no-tlvy.1000-2000.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/pod-no-tlvy.1000.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/pod-no-tlvy.2.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/pod-no-tlvy.20.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/pod-no-tlvy.2000.good
A test/parallel/forall/task-private-vars/throwing-init-exprs/pod-no-tlvy.chpl
A test/parallel/forall/task-private-vars/throwing-init-exprs/pod-no-tlvy.execopts
A test/parallel/forall/task-private-vars/throwing-init-exprs/pod-no-tlvy.prediff
A test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.1000.good
A test/parallel/forall/task-private-vars/tlvy-no-tlvy.chpl
A test/parallel/forall/task-private-vars/tlvy-no-tlvy.good
M compiler/AST/astutil.cpp
M compiler/include/astutil.h
M compiler/resolution/lowerForalls.cpp
M test/parallel/forall/task-private-vars/block.chpl
M test/parallel/forall/task-private-vars/block.comm-none.good
M test/parallel/forall/task-private-vars/block.good
M test/parallel/forall/task-private-vars/records.good
M test/parallel/forall/task-private-vars/refs.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/example-pr-14386.chpl
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.0.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.1.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.10.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.2-3.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.2-30.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.2-3000.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.2.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.20-3.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.20-30.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.20-3000.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.20.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.2000-3.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.2000-30.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.2000-3000.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.2000.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.3.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.30.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.3000.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.chpl
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.execopts
M test/parallel/forall/task-private-vars/throwing-init-exprs/int-tpvs.prediff
M test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.0.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.1.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.10.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.2-3.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.2-30.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.2-3000.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.2.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.20-3.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.20-30.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.20-3000.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.20.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.2000-3.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.2000-30.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.2000-3000.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.2000.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.3.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.30.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.3000.good
M test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.chpl
M test/parallel/forall/task-private-vars/throwing-init-exprs/pod-tpvs.execopts

Compare: https://github.com/chapel-lang/chapel/compare/045c7fd0b392...c7dbf2a78330