Proposal: Google Summer of Code on GCC Ada Front end -
Goal : Implement some of the light-weight parallelism features of Ada 2022 in the GNAT front end - Contributor: Ethan Luis McDonough, PSU '2025 ( ethanluismcdono...@gmail.com) - Mentors: S. Tucker Taft (Lexington, MA -- tucker.t...@gmail.com) and Richard Wai (Toronto, ON -- rich...@annexi-strayline.com) The GNAT front end does not currently recognize the "parallel" keyword added as part of Ada 2022. The goal of this project is to add support in the GNAT parser for the two most important places where the "parallel" keyword is used, namely the parallel "for" loop, and the parallel "do" statement. Here is the Ada 2022 syntax for the parallel parts of the "for" loop (from https://adaic.org/resources/add_content/standards/22rm/html/RM-5-5.html): loop_statement ::= [loop_statement_identifier <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-5-1.html#S0172> :] [iteration_scheme <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-5-5.html#S0179>] loop sequence_of_statements <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-5-1.html#S0166> end loop [loop_identifier <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-2-3.html#S0002> ]; iteration_scheme ::= ... | [parallel [aspect_specification <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-13-1-1.html#S0346> ]] for procedural_iterator <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-5-5-3.html#S0185> | parallel [(chunk_specification <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-5-5.html#S0180>)] [aspect_specification <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-13-1-1.html#S0346> ] for loop_parameter_specification <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-5-5.html#S0181> | parallel [(chunk_specification <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-5-5.html#S0180>)] [aspect_specification <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-13-1-1.html#S0346> ] for iterator_specification <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-5-5-2.html#S0183> chunk_specification ::= integer_simple_expression <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-4-4.html#S0138> | defining_identifier <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-3-1.html#S0022> in discrete_subtype_definition <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-3-6.html#S0055> loop_parameter_specification ::= defining_identifier <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-3-1.html#S0022> in [reverse] discrete_subtype_definition <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-3-6.html#S0055> [iterator_filter <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-5-5.html#S0182> ] iterator_filter ::= when condition <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-4-5-7.html#S0150> Here is the Ada 2022 syntax for the parallel "do" statement (from https://adaic.org/resources/add_content/standards/22rm/html/RM-5-6-1.html): parallel_block_statement ::= parallel [(chunk_specification <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-5-5.html#S0180>)] [aspect_specification <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-13-1-1.html#S0346>] do sequence_of_statements <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-5-1.html#S0166> and sequence_of_statements <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-5-1.html#S0166> {and sequence_of_statements <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-5-1.html#S0166> } end do; The chunk_specification <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-5-5.html#S0180>, if any, of a parallel_block_statement <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-5-6-1.html#S0192> shall be an integer_simple_expression <https://www.adaic.org/resources/add_content/standards/22rm/html/RM-4-4.html#S0138> . The GNAT front end is organized into three basic phases, a parser, a semantic analyzer, and an expander. In the sources, these are represented by source files par-ch*.adb, sem_ch*.{ads,adb}, and exp_ch*.{ads,adb}, where "ch*" is short-hand for the various chapters of the Ada reference manual. For this project the intent is to augment primarily the "chapter 5" components, given that loop and parallel-do statements are defined in chapter 5 of the Ada reference manual. For example, the function Par.Ch5.P_Loop_Statement is where most of the parsing of the loop statement takes place, while Par.Ch5.P_Parallel_Do_Statement would be a new local function of Par.Ch5. Similarly, Sem_Ch5.Analyze_Loop_Statement would be augmented, while Sem_Ch5.Analyze_Parallel_Do_Statement would be new. And finally, Exp_Ch5.Expand_Loop_Statement would be augmented, while Exp_Ch5.Expand_Parallel_Do_Statement would be new. The project would begin with the parser, simply recognizing the new syntax, and producing debug output to report on whether the parse was successful. The next phase would be to construct the appropriate tree representations, which would mean updating the gen_il* set of files to include new fields and node types to support the parallel for-loop and parallel do statement. As part of doing this, pseudo-code would be developed for the semantic and expansion phases, to ensure that the new tree components created meet the needs of these later phases. Finally the semantic and expansion phases would be implemented in Ada, using the new tree components available. For the expansion phase, the job is primarily to transform the syntax into the appropriate calls on out-of-line runtime components providing light-weight-thread management. These routines have already been developed and debugged, and are available on the GitHub site for the ParaSail parallel programming language ( https://github.com/parasail-lang/parasail/tree/main/lwt). As far as effort involved, the parsing functions in the GNAT Front End tend to be quite short, often less than a page of code, making heavy use of shared parsing components. The semantic phase tends to be significantly more complex, but for this effort relatively little additional code will be required, because the additional static semantics for these new features are pretty simple. The major effort will be in the expansion phase, primarily because the out-of-line light-weight-threading library expects the loop body to be represented as a procedure. In fact the GNAT-FE frequently creates simple out-of-line routines as part of implementing certain existing Ada features, so there should be plenty of models to work from to turn the loop body into an out-of-line routine. Similarly, generating calls to run-time routines is also quite common as part of various GNAT-FE expansion routines, so we can use those as models as well. One feature of the light-weight-threading library we will be interfacing with is that it sits on top of the existing Ada runtime, as well as the GCC implementation of OpenMP, without any need to alter these underlying components. Overall we would estimate a couple of weeks for the parsing and initial semantic analysis for these two features, with the bulk of the summer spent on the expansion phase, finalizing the semantic analysis, and if there is time, working on error recovery. As far as mentors, Tucker Taft had agreed to be a mentor. Tucker was the lead designer of Ada 2022, and has implemented the light-weight-threading library that we will be interfacing with. Richard Wai has also agreed to be a mentor. Richard is an active member of the ISO-WG9 committee on Ada and its Ada Rapporteur Group (ARG), and has also made contributions to GCC components, in particular the GNAT front end, in the past. The contributor will be Ethan Luis McDonough. Ethan is currently finishing his last semester in the Penn State University online Software Engineering program, and is also finishing up an internship at the Lawrence Livermore Laboratory focused on open source LLVM development. Ethan spent his time at the lab working on LLVM’s Fortran frontend as well as GPU instrumentation tools. Most recently Ethan has been implementing a code generator for a hardware description language built on top of the ParaSail Programming Language, using an API he implemented in Ada providing access to the tree representation used by the ParaSail front end (which is written in Ada). He looks forward to making a contribution to the open-source GNAT FE component of the GCC compiler collection.