chapel icon indicating copy to clipboard operation
chapel copied to clipboard

dyno: initial steps for producing typed AST from uAST + types

Open mppf opened this issue 4 months ago • 0 comments

This PR adds a new prototype for converting from uAST + types to production compiler AST. The dyno effort to improve the compiler has been recently focusing on creating an incremental resolver. We would like to use this incremental resolver in production chpl compiles, but we will need to convert its results into a form that the production compiler understands to do so.

This PR also improves the user-facing error message for mixing return; and return x; in one function.

Before this PR, convert-uast.cpp had some initial support for converting types and resolved calls. However, it was hard to see how to continue to extend this in-place because both the input and output of this compiler pass need to change:

  • the input for convert-uast.cpp is an untyped uAST traversal but it needs to be a typed uAST traversal using ResolvedVisitor
  • the output from convert-uast.cpp is predominantly untyped AST but it needs to be typed AST with other changes.

This PR changes direction by adding convert-typed-uast.cpp. This is formed in part by copying some of the code from convert-uast.cpp and modifying it. Besides having a tighter implementation, there are two key ideas here:

  1. We will need to be able to make incremental progress with resolving. To enable that, this PR computes a call graph of functions called from user code. Only the functions in this call graph will go through the new strategy.
  2. The AST produced by convert-typed-uast.cpp will match the compiler's AST after callDestructors. That means that convert-typed-uast.cpp will work with the dyno resolver to normalize and to handle copy-init and deinit calls.

Implementation Details:

  • Some code can be reasonably shared between convert-uast.cpp and convert-typed-uast.cpp. I moved that code to convert-help.cpp.
  • Since there are now two uAST -> AST converters that need to potentially interact or to replace each other, these are now subclasses of an abstract base class.
  • Since convert-uast.cpp no longer needs to handle types, I removed the type handling code from there (and much of it is added back in a slightly different form in convert-typed-uast.cpp).
  • To allow incremental development, this PR adds a call-graph analysis and uses the call graph of function called from user module code in order to decide which functions to convert in this new manner when compiling with --dyno.
  • [x] full comm=none testing

mppf avatar Oct 07 '24 21:10 mppf