Harshita Kalani

Kicking Off GSoC: Intrinsic Functions and Compile-Time Evaluations in Week One

This week marked the beginning of the coding period for GSoC, and I dived into implementing intrinsic functions from scratch. I focused on adding compile-time evaluation support for various array intrinsics. Specifically, I implemented compile-time support for the array intrinsic functions, namely, sum, product, minVal, maxVal, and count. Additionally, I implemented a number of elemental and array intrinsic functions from scratch, namely, spacing, nearest, iany, iall, and norm2.
I began by adding compile-time support for the sum, product, minval and maxval intrinsic function. The current implementation does not yet handle optional arguments such as dim and mask. This limitation also applies to the other array intrinsics I worked on. There is an issue with the reshape intrinsic function, making it difficult to debug the dim argument. Therefore, I am currently handling only the mandatory arguments and plan to address the optional ones soon.
Next week, I aim to resolve the reshape intrinsic issue and subsequently handle the optional arguments for the array intrinsics.
Regarding the intrinsics I implemented from scratch, I started with the spacing intrinsic, which calculates the spacing between two consecutive floating-point numbers. For runtime implementation, an ASR node needs to be created for the spacing function. The same applies to the nearest intrinsic. This has been documented as a separate issue, and a compiler exception is thrown for runtime values for these functions.
I then implemented the iany and iall array intrinsics, which compute the bitwise OR and AND of array elements, respectively. Following that, I implemented the norm2 intrinsic, which calculates the square root of the sum of the squares of array elements. A pull request for its implementation is ready for review.
Additionally, I worked on moving the merge intrinsic from the Intrinsic Array functions to the Intrinsic Elemental functions, where it belongs. I also refactored the code for ArrayConstant, replacing repetitive if-else conditions with switch cases to enhance readability, maintainability, and execution speed.
While we support the Fortran backend for several intrinsics, not all are covered. I have opened a pull request to add Fortran backend support for the array intrinsics, which is ready for review.
For the upcoming week, I have several plans. I will address the reshape intrinsic function issue, handle the optional arguments of array intrinsics, and work on the runtime implementation of the spacing and nearest intrinsic by designing the ASR node. I also plan to add Fortran backend support for the intrinsic elemental and inquiry functions, ensuring they run perfectly. I have outlined a better approach for the Fortran backend in the pull request, and if it is approved by my mentors, I will proceed with that. If I complete these tasks ahead of time, I will pick more intrinsics to implement from scratch.
I've created an issue to keep a track of issues and PRs I'm working on. Here's a link for the same: #4017.
Overall, I found this week's work interesting and am grateful to Ondřej Čertík and the rest of the mentors at LFortran for their constant reviews and suggestions. I look forward to the next week and am eager to complete the planned tasks.

Here's a link to related blogs: GSoC: Week 1
GSoC: Week 2
GSoC: Week 3
GSoC: Week 4
GSoC: Week 5
GSoC: Week 6