Branch: refs/heads/main
Revision: 19616fd
Author: mppf
Link: dyno: add initial support for type queries by mppf · Pull Request #19248 · chapel-lang/chapel · GitHub
Log Message:
Merge pull request #19248 from mppf/dyno-type-queries
dyno: add initial support for type queries
Resolves https://github.com/Cray/chapel-private/issues/3054
This PR adds support in the dyno resolver for type queries. Here are some
examples that are now working and tested:
proc a(arg: ?) { }
proc b(arg: ?t) { ... use t ... }
proc c(arg: GenericRecord(?)) { }
proc d(arg: GenericRecord(?t)) { ... use t ... }
proc e(arg: GenericRecord(OtherGenericRecord(?t))) { ... use t ... }
Implementation Details:
- adjusts
CompositeType::isInstantiationOf
to consider if the
substitutions are instantiations of each other. This supports cases
where a substitution is a generic type (e.g. AnyType orintegral
).
This involved callingcanPass
so theContext
is now an argument
forisInstantiationOf
. - changes TypeQuery to be a NamedDecl because the TypeQuery
?t
is
introducing a name (t
) that can be referred to (e.g.var x: t
)
into the function's scope. - adjusts
struct Resolver
to- keep a stack of declarations currently being resolved
- include helper code to resolve the types of TypeQuery uAST nodes
based on the type of the formal; this includes going in to FnCalls
to pull out the matching parts of the type (casesd
ande
above) - handle
f(arg:?)
- note that?
is considered an Identifier rather
than a TypeQuery - process TypeQuery nodes by finding the parent Formal node and
running the helper code mentioned above to compute the TypeQuery
types from the Formal type - forget Param values if the QualifiedType is not param (for e.g.
f(1)
passed toproc f(arg)
) - process
Dot
uAST nodes to implementarg.type
- while debugging during development, I noted several redundant calls to
resolve the same thing. These were coming from typedSignatureInitial
so I changed it in to a query so that it only runs once for a given
function. That is important as it would otherwise run every time a
function is considered as a candidate. - I also noticed that instantiateSignature was visiting function bodies
and then discarding the result, so I changed it to focus only on
formals and where clause. - adjusted returnTypeForTypeCtorQuery to leave out substitutions for
AnyType unless they are for a field with an initializer - Added a CallInfo constructor that creates an untyped CallInfo from a
FnCall - Adjusted GatherQueryDecls for scope resolution to gather TypeQuery
decls into the same scope as the function formals
Future Work:
- add support for type queries with array or tuple syntax
Reviewed by @dlongnecke-cray - thanks!
Modified Files:
A compiler/dyno/test/resolution/testTypeQueries.cpp
M compiler/dyno/include/chpl/resolution/resolution-queries.h
M compiler/dyno/include/chpl/resolution/resolution-types.h
M compiler/dyno/include/chpl/resolution/scope-types.h
M compiler/dyno/include/chpl/types/CompositeType.h
M compiler/dyno/include/chpl/uast/TypeQuery.h
M compiler/dyno/lib/resolution/can-pass.cpp
M compiler/dyno/lib/resolution/resolution-queries.cpp
M compiler/dyno/lib/resolution/resolution-types.cpp
M compiler/dyno/lib/resolution/scope-queries.cpp
M compiler/dyno/lib/types/CompositeType.cpp
M compiler/dyno/test/resolution/CMakeLists.txt
M compiler/dyno/test/resolution/testInteractive.cpp
Compare: https://github.com/chapel-lang/chapel/compare/195c457849f9...19616fd119b5