Branch: refs/heads/main
Revision: a23a447
Author: mppf
Link: compiler/next: implement type construction by mppf · Pull Request #18700 · chapel-lang/chapel · GitHub
Log Message:
Merge pull request #18700 from mppf/next-type-construction
compiler/next: implement type construction
This PR adds support for resolving type construction calls in the
compiler/next prototype resolver.
This PR uses the approach of generating a TypedFnSignature for a type
constructor and having that participate in candidate selection and
disambiguation to allow other functions with the same name as a type.
While we could decide to disallow this in the future, it seems to be a
good idea to have the new resolver able to handle it.
For example, this program doesn't type resolve with the production
compiler but the new resolver does handle it:
record R {
type t;
}
{
proc R(arg: int) {
return arg;
}
var x = R(arg=1);
var y:R(t=real);
}
This PR takes these main steps:
- fills in the details for CompositeType to represent individual fields
and adjusts the related classes appropriately. - makes some adjustments to the resolver and UntypedFnSignature and
TypedFnSignature in particular in order to allow the compiler to add a
TypedFnSignature during resolution that is not directly a function
declared in the source code and parsed into the uAST. This strategy of
creating a TypedFnSignature apart from a uAST Function declaration is
also a strategy I am expecting to follow for compiler-generated
default functions. - adds code to resolution-queries to resolve field types and to work
with generated type constructors
This PR also includes some enabling changes:
- Fixes a some bugs in defaultUpdateOwned
- De-indents resolution-queries.h (to fit with practice of not indenting
within namespaces and instead commenting on end of curly braces) - Address public fields in UntypedFnSignature and TypedFnSignature and
improve their API. Now they behave similarly to a Type with aget
class method to create one in a unique-ified manner. Also, these types
can now work with an ID that is not a Function - the ID can refer to
say a Record declaration in uAST. - Added a helper,
Type::getCompositeType
to return the receiver as a
CompositeType if it is one, or, for a ClassType to return the referred
to BasicClassType. (Why does ClassType refer to BasicClassType instead
of just containing the fields? It is because we want to have just one
type/instantiation for the fields of a class even as we can have
various different management strategies used with it). - Adds a helper
PrimitiveType::getWithNameAndWidth
to make it easier
to construct these types from a name and width. - Fixes a problem where TypeClassesList.h indicated ClassType is a
CompositeType (it is not) - Adds some additional built-in types to
Type::gatherBuiltins
Reviewed by @dlongnecke-cray - thanks!
Modified Files:
A compiler/next/test/resolution/testTypeConstruction.cpp
M compiler/next/include/chpl/queries/Context.h
M compiler/next/include/chpl/queries/update-functions.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/BasicClassType.h
M compiler/next/include/chpl/types/ClassType.h
M compiler/next/include/chpl/types/ClassTypeDecorator.h
M compiler/next/include/chpl/types/CompositeType.h
M compiler/next/include/chpl/types/PrimitiveType.h
M compiler/next/include/chpl/types/RecordType.h
M compiler/next/include/chpl/types/TupleType.h
M compiler/next/include/chpl/types/Type.h
M compiler/next/include/chpl/types/TypeClassesList.h
M compiler/next/include/chpl/types/UnionType.h
M compiler/next/lib/parsing/parsing-queries.cpp
M compiler/next/lib/resolution/resolution-queries.cpp
M compiler/next/lib/resolution/resolution-types.cpp
M compiler/next/lib/types/BasicClassType.cpp
M compiler/next/lib/types/ClassType.cpp
M compiler/next/lib/types/CompositeType.cpp
M compiler/next/lib/types/Makefile.include
M compiler/next/lib/types/PrimitiveType.cpp
M compiler/next/lib/types/RecordType.cpp
M compiler/next/lib/types/TupleType.cpp
M compiler/next/lib/types/Type.cpp
M compiler/next/lib/types/UnionType.cpp
M compiler/next/test/resolution/CMakeLists.txt
M compiler/next/test/resolution/testInteractive.cpp
M compiler/next/test/resolution/testPoi.cpp
Compare: https://github.com/chapel-lang/chapel/compare/2e70011941c9...a23a4470ba18