[Chapel Merge] Migrate ifa code for param folding into compiler/n

Branch: refs/heads/main
Revision: 7033e77
Author: mppf
Log Message:

Merge pull request #18172 from mppf/next-ifa

Migrate ifa code for param folding into compiler/next

This PR moves logic to support param folding from compiler/ifa to
compiler/next/lib/immediates. It makes adjustments to this code to make
it possible to build it in the compiler library and adjusts the
production compiler accordingly.

In particular, this PR makes the following change to the production
compiler:

  • migrates the astr capability to work with the unique string table in
    Context / UniqueString
  • modifies the Immediate structure to use a UniqueString instead of a
    const char* for the uniqued string
  • modifies code working with Immediate strings to convert UniqueString
    to const char* etc as needed

Then, this PR implements param folding for primitive calls (e.g.
__primitive("+", 1, 2)) in the new resolver. To do so, it:

  • adds PrimCall
  • adds Param and subclasses
  • changes uast::Literal subclasses to store a const Param*
  • adds NothingType (to serve as an easy default for a Param, if one is
    needed).

Additionally, since string literals can contain zero bytes, and we're
trying to have the new compiler code store string literals unescaped (to
avoid a category of bugs with param string handling), this PR adjusts the
UniqueString and Context::uniqueCString to handle strings containing
interior zero bytes. The length of the string can be passed, and when the
memory for storing the unique string (and the GC mark) is allocated, it
now includes a 4-byte length. As a result, it is now possible to get a
length out of a UniqueString (even though the UniqueString is still only
8 bytes itself!).

A somewhat related change there is adding astr methods to UniqueString
to return the same string that Context::uniqueCString would. This is
just what the UniqueString already points to in the case the string is
not inlined. Additionally, since the Immediate union needs to work with a
PODUniqueString, added a method to get a PODUniqueString from a
UniqueString which is needed in one place.

The code in compiler/next/lib/immediates is considered an internal part
of the compiler library. Therefore, there are no headers for it in
compiler/next/include/chpl/immediates. Instead, the Param type will
serve as the public API for param folding logic.

Lastly, this PR removes some unused stuff from the ifa code. First, it
removes several unused elements from prim_data.h. Second, it removes
convert_string_to_immediate because it is unused. However I didn't
notice that at first and so migrated a few functions to be more globally
visible to help in more places. These include stringContainsZeroBytes
and decStr2uint64 / str2double etc. The conversion functions do not
strictly need to be moved for this PR but making them static methods on
Param seems like a good improvement in case we need to use them
elsewhere in the future.

Future Work:

  • Add a macro-driven table of primitive ops and give each an integer
    number at parse time rather than using UniqueString.

Reviewed by @daviditen and @dlongnecke-cray - thanks!

  • [x] full local testing

    Modified Files:
    A compiler/next/include/chpl/types/BytesType.h
    A compiler/next/include/chpl/types/CStringType.h
    A compiler/next/include/chpl/types/NothingType.h
    A compiler/next/include/chpl/types/Param.h
    A compiler/next/include/chpl/types/ParamClasses.h
    A compiler/next/include/chpl/types/ParamClassesList.h
    A compiler/next/include/chpl/types/ParamTag.h
    A compiler/next/include/chpl/types/StringType.h
    A compiler/next/lib/immediates/CMakeLists.txt
    A compiler/next/lib/immediates/Makefile
    A compiler/next/lib/immediates/Makefile.include
    A compiler/next/lib/immediates/cast_code.cpp
    A compiler/next/lib/immediates/hash_multipliers.cpp
    A compiler/next/lib/immediates/ifa_vars.cpp
    A compiler/next/lib/immediates/make_prims/Makefile
    A compiler/next/lib/immediates/make_prims/make_prims.cpp
    A compiler/next/lib/immediates/num.cpp
    A compiler/next/lib/immediates/num.h
    A compiler/next/lib/immediates/prim_data.h
    A compiler/next/lib/types/BytesType.cpp
    A compiler/next/lib/types/CStringType.cpp
    A compiler/next/lib/types/NothingType.cpp
    A compiler/next/lib/types/Param.cpp
    A compiler/next/lib/types/StringType.cpp
    A compiler/next/lib/uast/PrimCall.cpp
    A compiler/next/test/queries/testUniqueString.cpp
    A compiler/next/test/resolution/testParams.cpp
    R compiler/adt/map.cpp
    R compiler/ifa/Makefile
    R compiler/ifa/Makefile.include
    R compiler/ifa/Makefile.share
    R compiler/ifa/cast_code.cpp
    R compiler/ifa/ifa_vars.cpp
    R compiler/ifa/make_prims/Makefile
    R compiler/ifa/make_prims/make_prims.cpp
    R compiler/ifa/num.cpp
    R compiler/ifa/num.h
    R compiler/ifa/prim_data.h
    R compiler/include/chpltypes.h
    R compiler/next/test/uast/testUniqueString.cpp
    R test/trivial/diten/testIntExp4.prediff
    M compiler/AST/AggregateType.cpp
    M compiler/AST/AstToText.cpp
    M compiler/AST/astutil.cpp
    M compiler/AST/build.cpp
    M compiler/AST/expr.cpp
    M compiler/AST/primitive.cpp
    M compiler/AST/symbol.cpp
    M compiler/AST/type.cpp
    M compiler/AST/view.cpp
    M compiler/Makefile
    M compiler/adt/Makefile.share
    M compiler/codegen/cg-expr.cpp
    M compiler/codegen/cg-symbol.cpp
    M compiler/include/map.h
    M compiler/include/stringutil.h
    M compiler/include/symbol.h
    M compiler/include/type.h
    M compiler/llvm/clangUtil.cpp
    M compiler/main/driver.cpp
    M compiler/next/include/chpl/queries/Context-detail.h
    M compiler/next/include/chpl/queries/Context.h
    M compiler/next/include/chpl/queries/UniqueString-detail.h
    M compiler/next/include/chpl/queries/UniqueString.h
    M compiler/next/include/chpl/resolution/resolution-queries.h
    M compiler/next/include/chpl/resolution/resolution-types.h
    M compiler/next/include/chpl/types/QualifiedType.h
    M compiler/next/include/chpl/types/Type.h
    M compiler/next/include/chpl/types/TypeClasses.h
    M compiler/next/include/chpl/types/TypeClassesList.h
    M compiler/next/include/chpl/types/all-types.h
    M compiler/next/include/chpl/uast/ASTClassesList.h
    M compiler/next/include/chpl/uast/BoolLiteral.h
    M compiler/next/include/chpl/uast/BytesLiteral.h
    M compiler/next/include/chpl/uast/CStringLiteral.h
    M compiler/next/include/chpl/uast/ImagLiteral.h
    M compiler/next/include/chpl/uast/IntLiteral.h
    M compiler/next/include/chpl/uast/Literal.h
    M compiler/next/include/chpl/uast/NumericLiteral.h
    M compiler/next/include/chpl/uast/PrimCall.h
    M compiler/next/include/chpl/uast/RealLiteral.h
    M compiler/next/include/chpl/uast/StringLikeLiteral.h
    M compiler/next/include/chpl/uast/StringLiteral.h
    M compiler/next/include/chpl/uast/UintLiteral.h
    M compiler/next/include/chpl/uast/all-uast.h
    M compiler/next/include/chpl/util/hash.h
    M compiler/next/include/chpl/util/string-escapes.h
    M compiler/next/lib/CMakeLists.txt
    M compiler/next/lib/parsing/ParserContext.h
    M compiler/next/lib/parsing/ParserContextImpl.h
    M compiler/next/lib/parsing/chpl.ypp
    M compiler/next/lib/queries/Context.cpp
    M compiler/next/lib/queries/UniqueString.cpp
    M compiler/next/lib/resolution/resolution-queries.cpp
    M compiler/next/lib/types/CMakeLists.txt
    M compiler/next/lib/types/Makefile.include
    M compiler/next/lib/types/QualifiedType.cpp
    M compiler/next/lib/types/Type.cpp
    M compiler/next/lib/uast/BoolLiteral.cpp
    M compiler/next/lib/uast/BytesLiteral.cpp
    M compiler/next/lib/uast/CMakeLists.txt
    M compiler/next/lib/uast/CStringLiteral.cpp
    M compiler/next/lib/uast/ImagLiteral.cpp
    M compiler/next/lib/uast/IntLiteral.cpp
    M compiler/next/lib/uast/Makefile.include
    M compiler/next/lib/uast/NumericLiteral.cpp
    M compiler/next/lib/uast/RealLiteral.cpp
    M compiler/next/lib/uast/StringLiteral.cpp
    M compiler/next/lib/uast/UintLiteral.cpp
    M compiler/next/lib/util/string-escapes.cpp
    M compiler/next/test/parsing/testParse.cpp
    M compiler/next/test/parsing/testParseStringBytesLiterals.cpp
    M compiler/next/test/queries/CMakeLists.txt
    M compiler/next/test/resolution/CMakeLists.txt
    M compiler/next/test/resolution/testInteractive.cpp
    M compiler/next/test/uast/CMakeLists.txt
    M compiler/optimizations/forallOptimizations.cpp
    M compiler/optimizations/localizeGlobals.cpp
    M compiler/passes/convert-uast.cpp
    M compiler/passes/initializerRules.cpp
    M compiler/passes/insertLineNumbers.cpp
    M compiler/passes/normalize.cpp
    M compiler/resolution/callInfo.cpp
    M compiler/resolution/functionResolution.cpp
    M compiler/resolution/generics.cpp
    M compiler/resolution/postFold.cpp
    M compiler/resolution/preFold.cpp
    M compiler/resolution/resolveFunction.cpp
    M compiler/resolution/wrappers.cpp
    M compiler/util/misc.cpp
    M compiler/util/stringutil.cpp
    M modules/internal/ChapelBase.chpl
    M test/trivial/diten/testIntExp4.good

    Compare: https://github.com/chapel-lang/chapel/compare/335ad37874c1...7033e7731518