Week4 - Bug Fixes & Block Data

Bug fixes SciPy & Block Data

Date: June 11, 2023.

Hello! Welcome to the fourth blog of my GSoC '23 journey. This week was based on fixing bugs and getting the statements and declarations present inside Block_Data() to ASR.

Let's start with Block Data, it is a Fortran 77 feature which is used to initialize variables and arrays. It is similar to the main program but it is executed before the main program. It is used to initialize the variables and arrays which are used in the main program.

Block Data is used at only few places in SciPy codebase, and as we have implementation of COMMON block and Data statements ready, I thought it would be a good idea to get Block Data implemented. We started with the declarations and body of block data, took every combination of it and fixed the bugs which were not supported by LFortran. The two major bugs were, improper handling of COMMON blocks with no name and second was allowing struct instance member to be used inside data statements. This was fixed by PR: 1763

With this, we were able to get the declarations and statements of block data to ASR and as we have implementation of COMMON blocks and Data statements, we were able to get the declarations and statements of block data to LLVM aswell.

Still we have to find a way to declare `block data` in ASR, which we can do either by adding a new node or by using the existing nodes. We are still working on it and will be fixed soon.

Moving ahead, we decided to scan SciPy and see if we are missing any edge cases, doing so we caught various issues like handling of external functions, statement functions, etc.

Let us begin with `external` declarations, a small example is shown below: Previously, LFortran used to ignore external declaratios which resulted in Issue: 1753, Issue: 1776.

In this declaration we donot have any idea about what function `matvect` can be, how many arguments it will have, etc. So we decided to create a template function with everything nullptr and/or 0 and then fill it up when we get the definition of the function. This was done in PR: 1789

On moving ahead, we encountered Issue: 1441 which is shown below: In the above example, argument of `sub2` i.e. `c` is a double precision variable when compiler visits a subroutine call, but on moving ahead we encounter that `c` is an implicit function with type `double precision`. So we created a template function `update_call_args` that updates `sub2` to use the new symbol `c` that is now a function, not a variable. This was done in PR: 1792

On further scanning we encountered various bugs related to statement functions, those were fixed through PR: 1794 more information about it can be found in PR itself.

Lastly, there were some bugs related to implicit declarations along with external and statement functions which got fixed by PR: 1800, PR: 1802

All in all with 23 hours of work, we were able to compile `Quadpack`, `Odepack`, `statlib` completely to ASR. For the next week I am planning to focus more on this bug hunting and fixing along with implementation of block data, data implied do loop (if possible), save attribute and some more edge cases. I would like to thank Ondřej Čertík for taking out time and helping me when I was stuck. Looking forward to many more commits.