chapel-lang/chapel — pull request #310 by sungeunchoi (2014-09-05 01:52:58+00:00)
Title: Strings as records implementation

This commit includes a new module called `NewString` that implements a reference counted string type using a record. These new strings, currently called `string_rec`, are designed to be a drop-in replacement for the current Chapel strings, though much work in the compiler and runtime will be needed to make them so (mostly ripping stuff out). For the most part, the original string interface was maintained, but it was decided to stop supporting `toString` and `_string_contains`. `NewString` requires 2 new runtime functions and 2 new memory allocation descriptors.

The actual string data is backed by a `baseType` which is currently `c_string`. The `baseType` is required to provide the `c_string` interface as well as a couple of functions for copying. The base string is assumed to be a *local-only* type like `c_string` for memory management purposes, so user strings of `baseType` will never be copied to a remote locale, though internal `baseType` strings can be copied. For the most part, the user should never use `baseType` strings, a notable exception being the IO module.

I chose to support a few operations between `string_rec` and `baseType` like concatenation and assignment, since they are commonly used. In other cases, a `baseType` string must be cast to `string_rec`. When this becomes the default string implementation, the compiler will coerce `c_string` to `string` as it does now. If the `baseType` is replaced, this coercion will not happen automatically.

This commit also includes a suite of tests designed primarily to check for memory leaks of string implementations. It contains unit tests for all the string operations, checking for both single and multilocale memory leaks. Currently, there are no memory leaks. There is a config type called `string_impl` that is used to define the string implementation, currently `string_rec`. When this implementation becomes the default Chapel string implementation, `string_impl` can be changed to `string`. Obviously, if others choose to implement their own strings, they can set `string_impl` to test their new strings. It is my hope that this suite will grow to include stuff from the new Strings library as well as performance tests.