Ran ispell on Task_Parallelism_and_Synchronization.tex
Preliminary version of special functions proposal.
First update.
Merge branch 'master' into specAddSpecialFunctions
Distinguish C string utilities that return allocated strings from those that don't.

Some utilities that return a c_string return a string that has been freshly allocated off
the heap, while others to not.  To make the interface self-documenting, I created yet
another alias for "const char*" and called it c_string_copy.  To that one, I ascribed the
interpretation that it contains a freshly-allocated C string.  Thus:
```
  c_string foo();
    // Returns a pointer-copy of (i.e. a reference to) a C string owned by another program
    // entity.  The caller of foo() should not free the return value.
  c_string_copy bar();
    // Returns a freshly-allocated C string.  The caller should free the returned C string
    // (or arrange in some other way that it be cleaned up).
```
Since the C compiler treats the type aliases `c_string` and `c_string_copy` as equivalent,
a variable (or return value) of type `c_string_copy` can be supplied to a routine
expecting a `c_string` argument.

### DETAILS
####./runtime/include/chpl-mem.h
Piped the filename and linenumber arguments through, for better memory tracking.

####./runtime/include/chpl-string-support.h
Added the new typedef `c_string_copy` with comments explaining how it differs from c_string.
Updated return value types using `c_string_copy` where the returned string is
heap-allocated and should be managed by the caller.

####./runtime/include/chpl-string.h
Added comments to describe the interface to stringMove().
Updated the return type of remoteStringCopy, to say that it returns a heap-allocated c_string.

####./runtime/include/chplcast.{h,c}
Updated the interfaces to all integral_to_c_string() functions, to say that they return a
heap-allocated c_string result.
Added a comment to warn that this is not true for the boolean_to_c_string() functions.
Added comments to chpl_string_to_c_string and c_string_to_chpl_string, explaining why they
do not leak memory.

####./runtime/include/chplgmp.{h,c}
Changed the return type of chpl_gmp_mpz_get_str() to say that it returns a heap-allocated
c_string.

####./runtime/include/chplsys.{h,c}
Changed the return type of chpl_nodeName() to say that it returns a heap-allocated
c_string.

####./runtime/include/qio/qio_formatted.{h,c}
Changed the return type of qio_encode_to_string() to say that it returns a heap-allocated
c_string.

####./runtime/src/chpl-string-support.c
Changed the return type of chpl_format(), string_copy(), string_concat(), string_select()
and string_index() to say that they return a heap-allocated c_string.
Updated string_index to ensure that the returned c_string_copy can always be safely
deallocated.

####./runtime/src/chpl-string.c
Added comments about the semantics of stringMove().
Changed the return type of remoteStringCopy() to say that it returns a heap-allocated
c_string.

####./runtime/src/config.c
Added a comment about chpl_config_get_value() being inherently thread-safe.
Added tests of some compile-time computations.
Complete first draft of Special Functions chapter.
Add the new release/1.10 branch dates to perf data files.
Add new type c_string_copy to track owned c_strings.

Formerly, c_string was used to represent low-level C strings without regard to whether
they behave like fully-constructed (owned) objects or like references (unowned).  To
simplify the task of tracking allocations across the runtime/module interface, I added the
new type c_string_copy.

Now, c_string is used to represent unowned strings and c_string_copy is used to represent
owned strings.  To prevent memory leaks, an owned string should be freed before it goes
out of scope (or its ownership transferred to another program entity).  An unowned string
should not be feed.

When a c_string is used to initialize an object (such as a chpl_string)
that is expected to own its data, it must be copied into that object.  When a
c_string_copy is used to initialize such an object, a pointer copy will suffice.
Ownership of the c_string_copy is then transferred to the new object.

Note that a c_string_copy can be coerced to a c_string without breaking this ownership
invariant.  Ownership is retained by the original (c_string_copy) and not by the duplicate
(c_string).  This seems a good place to justify the naming: A c_string_copy is produced by
passing a c_string to the function string_copy().

[This version compiles and runs hello.chpl]

###DETAILS

####compiler/AST/expr.cpp
Moved all of the conversions between chpl_string, c_string and various fundamental types
from the PRIM_CAST clause of CallExpr::codegen() out to module code.
TODO: A PRIM_CAST returning an owned object should probably allocate that object.  This is
not a problem for fundamental types, but is probably a problem for c_string_copy,
chpl_string and records.  (Record casts are handled by compiler-generated cast functions
unless overridden.)

####compiler/AST/primitive.cpp
Added the new type info functions returnInfoStringCopy, and used this to inform the
compiler that the primitives
  string_concat
  string_index
  string_copy
  string_select
return c_string_copy objects.

####compiler/include/symbol.h
####compiler/AST/symbol.cpp
Added the new global initializer symbol gStringCopy.

####compiler/include/type.h
####compiler/AST/type.cpp
Added the new internal type dtStringCopy.
Added some comments suggesting future revisions.

####compiler/passes/resolveIntents.cpp
Added dtStringCopy to the list of types whose blank intent is equivalent to "const in".

####compiler/resolution/functionResolution.cpp
Added a coercion from c_string_copy to c_string.

####modules/internal/ChapelIO.chpl
Changed the return type of chpl_format() to c_string_copy.  These functions always
returned an owned c_string, and now we advertise that in the interface.

####modules/internal/String.chpl
Added an overload for toString() that takes a c_string_copy operand.  The new version
assumes ownership of the passed-in c_string_copy.  There were notations in the code that
we could use a non-allocating form of toString().  Now that task is accomplished.
Added the non-allocating versions of toString() -- taking a c_string_copy and returning a
chpl_string.
Added the c_string_copy to c_string cast used by the added coercion.

Removed the workaround for the string allocation bug in casts between c_strings and
chpl_string fixed before release, and replaced it with code that should not leak.
Some of the casts from fundamental types (e.g. enums and bools) to c_string yielded
an unowned c_string, while others yielded an owned c_string (i.e. a c_string_copy).  The
c_string cases had to be handled special w.r.t. the call to chpl_free_c_string().  Now,
copies are made of the c_string results, while the c_string_copy results are just usurped
buy the resulting chpl_string.

Added back the casts that used to be implemented by PRIM_CAST:
* bool to c_string
* integral to c_string_copy
* real to c_string_copy
* imag to c_string_copy

Revised c_string.substring() to always return a c_string_copy.  The ownership state of the
returned value used to be ambiguous, because if the range was empty it would return a
reference to a literal empty string (a c_string).

####modules/standard/GMP.chpl
chpl_gmp_mpz_get_str() now returns a c_string_copy.

####modules/standard/IO.chpl
qio_encode_to_string() now returns a c_string_copy.
The cast of an ioChar to a c_string now returns a c_string_copy.

####modules/standard/NewString.chpl
remoteStringCopy now returns a c_string_copy.

####runtime/include/chpl-string.h
Added string_from_c_string_copy() and wide_string_from_c_string_copy() to create a string
from a c_string_copy without allocating new memory.  Ownership of the c_string_copy
argument is transferred to the new string.

####runtime/include/chplcast.h
####runtime/src/chplcast.c
Replaced the individual int type to c_string functions with integral_to_c_string_copy().
Replaced the real and imag type to c_string functions with real_to_c_string_copy().

####runtime/include/chplsys.h
chpl_nodeName() actually returns a shared, statically-allocated string, so I changed its
return type to c_string from c_string_copy.

####runtime/src/chpl-string-support.c
Reworked string_select so it always returns a newly-allocated c_string_copy or NULL.

####runtime/src/chpl-string.c
Added string_from_c_string_copy().  This function steals the data owned by the passed-in
c_string_copy, so it creates a string from a c_string_copy without requiring a new
allocation and copy.  This is is used to implement the "non-allocating toString" mentioned
in several TODOs by Sung (which also allowed me to resolve those TODOs).

Added wide_string_from_c_string_copy(), which is the wide version of the above.

Reworked stringMove() so it always reuses the buffer provided.  The use of a zero-length
string to represent an empty c_string_copy is deprecated in favor of a null pointer.

####runtime/src/chplsys.c
Reworked chpl_nodeName() so it always returns an unowned c_string.
The thread safety of returning a shared object implies that it should be initialized only
once (pre node).  Although I don't guarantee that, it's pretty likely.
Using the assumption that the node name does not change in the course of execution of a
program, I moved the initialization inside the namespace==NULL test, so (in the absence of
races) it is, in fact, initialized only once.
If the node name is expected to change during a run, this routine would have to be
reworked using unshared data, and return a c_string_copy.
Add some missing casts to and from c_strings.

Removal from codegen of the conversion from c_strings to fundamental types means that they
had to be added as explicit casts in Strings.chpl.

This version passes all primers tests (local only).

###DETAILS

####/compiler/AST/primitive.cpp
The "string_copy" primitive actually returns a c_string_copy.

####/modules/internal/ChapelIO.chpl
Reworked StringWriter, so its state data is a c_string_copy, not a c_string.  This allows
us to make the calls to chpl_free_c_string() unconditional.

####/modules/internal/String.chpl
The cast to string type now also works if the source type is a c_string or a
c_string_copy, so I was able to remove the "x.type != c_string" exclusion.

I removed the "cast a string to types other than c_string, and enumerated the types to
which a string can be cast.

The casts from c_string to primitive types formerly performed in the codegen for PRIM_CAST
are now enumerated explicitly in module code.

The cast from complex to c_string_copy did not make it into the previous commit, so that
support is added here.

I needed to provide an implementation for _defaultOf(c_string_copy).  It returns a
_nullString, which is effectively "(const char*) NULL".

I needed to provide definitions of assignment from c_string to c_string_copy and
c_string_copy to c_string_copy.

I needed to supply a cast from a chpl_string to a c_string_copy.  This creates a
newly-allocated copy.

I needed to provide a cast from boolean types to c_string_copy.

I had to supply a return type for the real_to_c_string_copy() extern prototype.

####/modules/standard/IO.chpl
I needed to add a cast from ioNewline and ioLiteral to c_string_copy.

####/runtime/include/chplcast.h
####/runtime/src/chplcast.c
Removed the older implementation of the integral_to_c_string and real_to_c_string functions.
Adjusted indentation in real_to_c_string_copy().
Some tweaks after first paratest run.

Now the result of a cast of any type to a string-ish thing is c_string_copy.  Adjusted the
memory management in that routine and also in string.write and c_string.write routines.

Made the coercion cast from c_string_copy to c_string return the right type.
Added a writeThis() method for c_string_copy.

Down to 401 failures (std).
Default to /proc/cpuinfo for maxTaskPar.prediff core counting.

Instead of explicitly calling out the configurations for which we use
/proc/cpuinfo to determine the core count, default to /proc/cpuinfo and
arrange for failure (by putting a '0' in the .good) when it's not there.

Credit: Brad.
Further tweaks.

Added a string-to-enum cast.
Now use the "insert line file info" pragma to pass line number information to the c_string
to integer, c_string to real and c_string to complex conversions.
Removed the redundant (and incorrect) cast from imag to c_string.

Empty c_string_copies are now represented by a null pointer, so I fixed two places that
used the old "" value instead.

Failure count is now down to 90 (std),
Continued tweaks from standard testing.

Disable redundant cast from c_string to string in ChapelBase.
Add explicit cast from enumerated to c_string_copy.
Add explicit casts from real, imag and complex to c_string, to support tests in
types/string/sungeun/c_string.  These should be deprecated and removed ASAP.
Add an explicit cast to c_string in c_string_copy.write(), to avoid infinite recursion.
Add null tests in the runtime support routines, since an empty c_string_copy can be a null pointer.
Rewrite string_concat() so it handles null input strings efficiently.
Revised the comment on c_string_from_wide_string, to indicate that an empty string is
represented by null, not "" (now that it returns a c_string_copy).

Down to 90 failures.
Work in progress.

The changes in this commit at one point got the error count down to about 40, but then
further changes introduced double deletion errors so that nearly every test fails.  Branch
from the previous commit and cherry-pick from this branch to duplicate that.
Further debugging of test results.

In Error.chpl, use cast-to-c_string_copy, to force conversion of offset using integer
formatting.
Made qio_channel_read_string() and qio_channel_scan_string() write their results into a
c_string_copy, to show that these results are newly allocated.
Changed signature of stringMove, so that dest is typed as a c_string_copy.  It now
allocates memory if the input dest pointer is NULL.
As a workaround, changed all "beer" test programs to use a c_string_copy cast on bottleNum
(because the string cast does not work).
Changed test/types/string/sungeun/c_string/substr.chpl to report that substr on a c_string
returns a c_string_copy, while substr on a string returns a string.

Now down to 12 failures, all in NewString.chpl.
A few tweaks to get tests in StringImpl to work.

Added concatenation operators taking a c_string_copy as one argument, so that internal
casts produce a c_string_copy that is then stolen.

The concatenation helper routines now use a c_string_copy, but leak memory somewhere.

Casts from other types to string_rec now go through the c_string_copy version, and the
output of this is stolen.  Note that special handling of Enum and Bool and ioLiteral and
ioEndOfLine and other literal strings is avoided.

Added a workaround to stringMove, to also allocate a new string if the input string is the
empty string.  This might leak memory in general, but the way it is used in NewString
currently does not cause this problem.
Add feature request for construction based on the result of a type function.
Updating REGRESSIONS based on the weekend's runs
Start a test to exercise lustre code.

At present, the SKIPIF functionality does not work for something like: skip if
CHPL_AUX_FILESYS does not contain "lustre". It is possible to say: skip if
MY_VAR contains "some value".