Make an explicit distinction between string and c_string

[reviewed by David, Michael, and others (test changes)]

This patch makes a (more) clear distinction between Chapel strings and
the c_string type in preparation for changing the string
implementation to use records.  Specifically:

- All runtime interfaces use c_string, not Chapel string
- Eliminate Chapel string literals, replacing them with literals of
  type c_string
- Eliminate param strings (use c_string params if needed)

For the time being, we do not clean up c_strings after casts to string
used in IO as well as some of the string operations such as
concatenation, substring, etc.  These will show up as "string copy
data" in the memory leaks log.  I envision most of these cases being
taken care of when strings become records, but I have marked them with
comments for future reference.

To make sure using string literals is seamless for the end user, a
number of changes were made to the compiler in order to hide the fact
that literals are of type c_string.  Specifically,

- Variables/fields/formals/tuples declared without a type but with a
  string literal initializing expression will be of type string
- Domain and array literals that use string literals will have
  index/element types of string
- Generics instantiated with string literals will have string type for
  the corresponding arguments


Additional notes:

- This commit will increase the memory leaks due to "string copy data"
  for a couple of reasons.  First, we when we coerce c_string to
  string, we need to allocate space for that data.  Second, various
  operations on c_strings allocate space (e.g., + and toString()) and
  there is currently no way to reclaim that space.  These are for the
  most part in the IO code.  Looking forward to a better string
  implementation, most cases will be handled with record semantics and
  a string creation function that take an already allocated c_string,
  though there may be a need for a c_string free function (but it's
  also possible that we can get around this by converting to string).

- There will be a few more "cannot create a C string from a remote
  string" for the multilocale case.  I prefer to let these regress
  rather than making them futures, as they are valuable for other
  cases.  If it is really bothersome, we can implement a temporary
  solution (as suggested by a few people at different times) and make
  the runtime function insert comm and allocate a c_string.  I'd
  prefer to fix this the right way and insert a temporary and allow
  the compiler to do the work.


Detailed changes:

runtime
=======

- For all files, change interfaces to use chpl_string or const char* to
  c_string.

Specific changes in the runtime:

- Add defaultStringValue and add chpl-string.h to stdchpl.h
  - runtime/include/chpl-string.h
  - runtime/include/stdchpl.h

- Rename chpl_string_compare() to string_compare() to be consistent
  with other string functions:
  - runtime/include/chpltypes.h
  - runtime/src/chpltypes.c
  - runtime/src/chplcast.c

- Remove qio_quote_string_chpl(), move functionality into module Error.chpl
  - runtime/src/qio/qio_formatted.c

modules
=======

modules/standard/Types.chpl
- Change _isPrimitiveType to return true for c_string, false for string

modules/standard/GMP.chpl
modules/dists/DimensionalDist2D.chpl
modules/internal/ChapelTaskTable.chpl
modules/internal/MemTracking.chpl
- Change string to c_string for filenames, compiler warnings/errors
- Add calls to c_str() as needed

modules/standard/Error.chpl
- Add quote_string() to replace call to qio_quote_string_chpl()
- Change return type of extern function to c_string
- Pass c_strings to chpl_error() primitive

modules/internal/localeModels/flat/LocaleModel.chpl
modules/internal/localeModels/numa/LocaleModel.chpl
- explicit casting of "rootLocale" literal to type string

modules/internal/DefaultAssociative.chpl
- Add support for c_string associative domain types
- Reuse the existing chpl__defaultHash() for string for c_string and
  add a chpl__defaultHash() for string that calls the c_string version.

modules/internal/ChapelArray.chpl
- Make domain and array literals that use quoted strings (c_string)
  have string index/element types

modules/internal/ChapelIO.chpl
- Reuse string versions of functions for c_string and add string
  versions that calls the c_string versions
- Change string to c_string as necessary

modules/standard/SysBasic.chpl
- Complete ops on c_string/string combos
  ==, !=, <=, <, >=, >
  =, _cast
  + with other types (param only)
  writeThis()
- Change chpl_string_compare->string_compare
- TODO: c_string and string stuff in separate module.

modules/internal/ChapelUtil.chpl
modules/internal/PrintModuleInitOrder.chpl
modules/standard/HDFS.chpl
modules/standard/RegExp.chpl
modules/standard/Sys.chpl
- Change string to c_string for extern declarations I missed previously
- Use c_string string for extern calls

modules/standard/IO.chpl

- Finish string -> c_string migration for runtime calls
- Make trues and falses c_string since they are only used as such
- Change _cast functions to be for c_string (ioChar, ioNewLine,
  ioLiteral, ioBits)
- Change ioLiteral val to be c_string
- Change _isIoPrimitiveType() include c_string
- Handle both string and c_string in {read|write}_{text|binary}_internal()
- Reuse existing channel.{writef|readf} for c_string and add a string
  version that calls the c_string version

modules/internal/ChapelBase.chpl

- string->c_string
- CHPL_* config params are c_string
- Change _throwOpError, compilerError, compilerWarning to take c_string
- Change chpl_string_compare->string_compare
- Add string ops and casts in terms of c_string
- Add new string concat, favoring string+string
- Remove param string ops including string concatenation
- Add c_string casts with primitive types and string
- TODO: c_string and string stuff in separate module.

compiler
========

compiler/include/flags_list.h
- Add FLAG_DEFAULT_STRING_VALUE

compiler/AST/build.cpp
- Identify default string value
- Convert string literals to string for tuples

compiler/AST/symbol.cpp
- Change string immediates (literals) to c_string (CONST_KIND_STRING)
- Change new_StringSymbol() to return a c_string immediate

compiler/AST/primitive.cpp
- typeToString() and _get_user_file() now return c_string
- string_concat(), string_index(), PRIM_STRING_COPY operate on c_string
- Change chpl_string_compare() to string_compare()

compiler/AST/expr.cpp
- Rework PRIM_CAST for string/cstring going directly to runtime
  functions for c_string and using the conversion routines for string
  - TODO: Consider moving the string versions to the modules

compiler/AST/type.cpp
- Default value for c_string is new_StringSymbol("")
- Do not fill in default string value (picked up during parsing)

compiler/passes/normalize.cpp
- Fix type-o in comment ('sumbols')
- Handle non-param variable with no type and initialized with a
  string literal changed to be of type string
- String literal args for non-param generics changed to be of type
  string

compiler/passes/insertLineNumbers.cpp
- Change filename arg to be of type c_string

compiler/passes/scopeResolve.cpp
- In build_type_constructor(), non-param fields with no type and
  initialized with a string literal changed to be of type string

compiler/passes/parallel.cpp
- Rename insertElementAccessTemps() to insertStringLiteralTemps() and
  replace string (dtString) c_string (dtStringC)
- In insert temp for default string value so that it too will be widened
- Do not widen the default string value

compiler/passes/buildDefaultFunctions.cpp
- Change enum-string cast functions to use dtStringC

compiler/resolution/generics.cpp
- Change dtString to dtStringC for immediates

compiler/resolution/wrappers.cpp
- Add coercion wrapper for string literal to string

compiler/resolution/functionResolution.cpp
- canInstantiate() return true for dtStringC with dtString formal
- canCoerce() return true for dtStringC to dtString
- computeGenericSubs() makes string literal actuals aligned with
  non-param generic formals of type dtAny substitute dtString
- preFold() chang enum-string cast to dtStringC
- Change chpl_string_compare() string_compare()

compiler/optimizations/optimizeOnClauses.cpp
- Add PRIM_STRING_FROM_C_STRING and PRIM_C_STRING_FROM_STRING to
  isFastPrimitive()
  - PRIM_C_STRING_FROM_STRING is fast
  - PRIM_STRING_FROM_C_STRING allocates memory so put it will the
    alloc/free functions (not fast)

tests
=====

Change param string to c_string (or unspecify):
- test/param/bradc/foldStringParams.chpl
- test/param/nelson/stringParams.chpl
- test/param/nelson/defaultParamValue.chpl
- test/memory/shannon/freedMalloc.chpl
- test/studies/uts/uts_deq.chpl
- test/studies/uts/uts_rec.chpl
- test/types/string/jturner/stringLengthParamType.chpl
- test/compflags/diten/configparam_nonint.chpl
- test/compflags/diten/configparam.compopts
- test/compflags/diten/configparam.chpl
- test/compflags/diten/configparam_nonint.compopts
- test/compflags/sungeun/configs/basic/configParamWithConfigType.compopts
- test/users/bartosz/paramfn.chpl

Remove candidates in .good file due to removed string param functions:
- test/users/brodtkorb/coercionQuestion.good

Change prototype of extern functions to use c_string:
- test/compflags/bradc/minimalModules/minModFnRefArg.chpl
- test/ compflags/bradc/minimalModules/minModDeclPrint.chpl

Change filename arg to c_string:
- test/memory/figueroa/printFinalMemStat.chpl
- test/memory/diten/MemAlloc.chpl
- test/memory/shannon/reallocZeroSize.chpl
- test/memory/shannon/printFinalMemStat.chpl
- test/memory/shannon/memstatPrint.chpl

Change type of memLog and memLeaksLog to c_string:
- test/execflags/shannon/help.good
- test/execflags/shannon/configs/help/basehelp.txt
- test/execflags/ferguson/help2.good

Change calls to compilerWarning/Error to use c_string:
- test/types/scalar/vass/abs-1-param.chpl
- test/users/vass/type-tests.isSubtype.chpl
- test/users/vass/sgn-1.chpl
- test/users/vass/type-tests.chpl
- test/execflags/vass/print-callstack-on-warning-1.chpl

Add additional callstack entry for conversion to string:
- test/execflags/vass/print-callstack-on-error-1.good
- test/execflags/vass/print-callstack-on-warning-1.good

Add explicit string return type on string literal:
- test/classes/diten/nearestMutualParentClass.chpl

Add futures for param strings:
- test/functions/diten/param_bool_to_string.future
- test/functions/diten/param_int_to_string.future
- test/functions/diten/param_int_to_string.bad
- test/functions/diten/param_bool_to_string.bad

Change to use a different type and preserve intent of test:
- test/functions/bradc/paramThis/secMethodParamThis.chpl

Change to chpldoc output format:
- test/chpldoc/classes/fields.doc.out

Add future for string copy leaked memory:
- test/memory/figueroa/StringLeaks5.future

Change leaked memory counts:
- test/memory/sungeun/refCount/domainMaps.good
- test/memory/sungeun/refCount/domainMaps.comm-gasnet.good
- test/memory/sungeun/refCount/domainMaps.lm-numa.good
- test/memory/sungeun/refCount/domainMaps.no-local.good




git-svn-id: http://svn.code.sf.net/p/chapel/code/trunk@23558 3a8e244f-b0f2-452b-bcba-4c88e055c3ca
Add a new set of tests for c_strings/string correctness

These tests address c_string support in Chapel.  Specifically,

- c_string coercion to strings as defined in r23558
- operations such as +, substring, and cast

There are 3 futures among these:

- implicit conversion of c_string to string does not work for ref/out/inout
- return of string literals should imply string return type
- substring() for range argument



git-svn-id: http://svn.code.sf.net/p/chapel/code/trunk@23559 3a8e244f-b0f2-452b-bcba-4c88e055c3ca