Separate Semantic Routines From AST Nodes
Mentor: Razvan Nitu
Spec | Details |
---|---|
Difficulty Level | easy-medium |
Project Duration | 175 hours |
Number of Contributors | 1 |
Prerequisites | Familiarity with compiler organization, visitor pattern, object oriented programming |
Description
In the DMD compiler codebase, AST nodes are defined as classes within various files. The ideal structure for these nodes is to have minimal fields and methods focused solely on field queries. However, the current state of the DMD frontend deviates from this ideal. AST nodes are laden with numerous methods that either perform or are dependent on semantic analysis. Furthermore, many AST node files contain free functions related to semantic analysis. Our objective is to decouple AST nodes from these functions.
How to start working on this project
- Clone the compile repository - check this guideline.
- Choose an AST node file: start by selecting a file from this list of AST node definition files.
- Examine Imports: open your chosen file and scrutinize the top-level imports.
- Isolate semantic imports: temporarily comment out one of the imports that includes semantic routines, particularly those ending in sem (e.g., dsymbolsem, expressionsem, etc.).
- Build and identify dependencies: compile DMD and observe any unresolved symbols that emerge.
- Relocate functions: shift the functions reliant on the unresolved symbols to the semantic file where the import was commented out.
- Move and test a function: select a function for relocation and ensure it functions correctly in its new location.
- Submit a Pull Request: Once you’re satisfied with the changes, create a PR that follows the guidelines.
Check this PR for an illustration of the above steps.
Sometimes, more intricate solutions are required. For instance, if an overridden method in an AST node calls a semantic function, it can’t be simply relocated. In these cases, using a visitor to collate all overrides, along with the original method, into the appropriate semantic file is the way forward. A notable instance of this approach is detailed in this pull request.
Other complex scenarios may arise, especially when dealing with AST nodes that interact with the backend. Finding solutions to those will be the fun part of the project.
This project helps advance the development of the compiler library by creating a clear separation between compilation phases.
This project is ideal for someone that has no prior experience with real-life compilers but wants to start by doing valuable work.