[Chapel Merge] Close leaks coming from unnamed array types

Branch: refs/heads/master
Revision: c15a3a6
Author: e-kayrakli
Log Message:

Merge pull request #16600 from e-kayrakli/arrtype-leak2

Close leaks coming from unnamed array types

This PR improves the memory management for runtime type values returned from
ForallExprs.

Resolves https://github.com/chapel-lang/chapel/issues/14309
Resolves https://github.com/chapel-lang/chapel/issues/15611
Resolves https://github.com/chapel-lang/chapel/issues/14318
Resolves https://github.com/Cray/chapel-private/issues/1171

The main issue was if you have a code like this:

proc foo(type t) { /* bla */ }

foo([1..3] int);

The argument to foo is parsed as a forall expression. Within the relevant
chpl__forallexpr function created for that expression, we call
chpl__ensureDomainExpr on the range which creates a domain. But we never free
the memory for that domain.

The following did not leak even before this PR:

proc foo(type t) { /* bla */ }

foo([{1..3}] int);
// doesn't leak because we create the domain in the calling scope and as such it
// is cleaned here

type t = [1..3] int;
foo(t);
//doesn't leak because parser is able to tell that this is actually an array
//type and creates the domain in this scope

This is done by two changes in `callDestructors:

  • A new function insertAutoDestroyPrimsForLoopExprTemps that is called before
    insertCallDestructors.

    This function looks at CallExprs that call a forall expression function, and
    depending on the temp that stores the return value and the argument to the
    function adds a PRIM_AUTO_DESTROY_RUNTIME_TYPE for that temp in the calling
    scope.

  • Improve lowerAutoDestroyRuntimeType by iterating over all the fields of the
    runtime type instead of hardcoding the dom field. This allows eltType
    field to be cleaned, too.

[Reviewed by @mppf]

Test:

  • [x] asan release/examples
  • [x] asan all leaky tests
  • [x] --memleaks all leaky tests
  • [x] standard
  • [x] gasnet

Modified Files:
A test/arrays/leaks/anonymousTypeLeaks.chpl
A test/arrays/leaks/anonymousTypeLeaks.execopts
A test/arrays/leaks/anonymousTypeLeaks.good
M compiler/resolution/callDestructors.cpp

Compare: https://github.com/chapel-lang/chapel/compare/1a4bf2fe5971...c15a3a68b2ba