chapel-lang/chapel — pull request #601 by hildeth (2014-10-02 20:42:17+00:00)
Title: Add c_string_copy type to support low-level string memory management.

This change removes the workaround (9cd7020) that was added to avoid the GCC error reporting an attempt to free statically-allocated memory. The workaround caused memory leakage across all tests to jump from 1.19Gb to 1.22Gb. This change returns memory leakage to the earlier level.

The main change involves splitting the low-level string representation type c_string into two types:
* `c_string` to represent "un-owned" character strings (such as string literals); and
* `c_string_copy` to represent "owned" character strings (i.e. heap-allocated copies).
The low-level and Chapel string implementation code can then use this distinction to manage memory with greater precision. Refer to the new technote c_string.txt (included in this PR) for details.

An additional change was to move some of the casts between strings (in their various forms) and fundamental types out of codegen and into module code. This change was motivated by the prospect of having to add *lots* of cases to codegen to handle the new c_string_copy type I was adding. It was way easier to do this in module code. Once I started down this path, I also discovered that Chapel's ability to resolve overloaded argument types made the job of writing the equivalent module code much easier.

Because Chapel does not yet support the definition of coercions at the source level, the compiler had to be modified to support two new coercions:
* c_string --> c_string_copy
* c_string_copy --> string
Adding them to the compiler was simple: we just needed two new clauses in canCoerce(). While there, I cleaned up special tests to prevent a symbol that is not a variable or an argument from c_string to string. Test results on this change are still pending.

TODOS:
* For this first cut, I left the baseType of both string and string_rec as c_string. Technically, these should both be c_string_copy.
* I should make another pass over the low-level runtime interface, to make sure that the coding rules for c_string vs. c_string_copy are obeyed.