Project scaffolding and compiler design


Serialized update for the 2021 Google Summer of Code under the fortran-lang organization, mentored by Ondrej Certik.


This post is part of a series based around my weekly GSoC21 project check-ins.

  1. GSoC21 W1: LFortran Kickoff

  2. GSoC21 W2: LFortran Unraveling

  3. GSoC21 W3: Kind, Characters, and Standards

  4. GSoC21 W4: LFortran, Backends and Bugs

  5. GSoC21 W5: LFortran Design Details and minidftatom <– You are here!

  6. GSoC21 W6: LFortran ASR and Values

  7. GSoC21 W7: LFortran Workflow Basics


  • Met with Ondrej on Tuesday, Wednesday and Thursday
    • Discussed the AST, ASR and backends in more detail
  • Zeroed in on several alternate designs implementations of intrinsic functions
    • We have prototype calls for the two kinds of compile evaluation
    • My sin implementation (pre-GSoC21) is pretty unwieldy and a cleaner method which we elected to pursue is the minval strategy
  • Discussed concrete methods of working
  • Talked about the runtime library
    • This is a late stage issue, after the ASR generation


This week focused around a subset of dftatom which Ondrej prepared. In fact the main highlight was working through possible code design directions and iterating on these with Ondrej (and Gagandeep asynchrously) to come up with the intrinsic function design methods and the compile time evaluation of expressions plan issue (discussed below in issue 420).

New Merge Requests

Restructuring of the ASR (1024)
A code cleanup task, to reduce code smell from using statements and to refactor into more logical file structures
Grammar modifications (1037)
Name changes to keep a consistent clear implementation structure

Freshly Assigned Issues

minidftatom Roadmap (401)
A clone of the SNAP and dftatom issues
size() not handled correctly for arrays (416)
This is an ASR bug, with a fix which should not be too difficult to track down
Compile time evaluation of expressions (420)
This is an internal implementation design specification document, which essentially introduces a value option for the ASR

Additional Tasks

Continue down the road for 401 and also consider perhaps, more runtime library logic.

Misc Logs

Since running on a new project is roughly similar, I will only briefly go over the steps.

1git clone
2cd minidftatom
3FC=gfortran cmake .
4make -j$(nproc)

Which generates:

 1 Z=          92 N=        5500
 2E_tot=     -25658.417889
 3 state    E            occupancy
 41s       -3689.355140    2.000
 52s        -639.778728    2.000
 62p        -619.108550    6.000
 73s        -161.118073    2.000
 83p        -150.978980    6.000
 93d        -131.977358   10.000
104s         -40.528084    2.000
114p         -35.853321    6.000
124d         -27.123212   10.000
134f         -15.027460   14.000
145s          -8.824089    2.000
155p          -7.018092    6.000
165d          -3.866175   10.000
175f          -0.366543    3.000
186s          -1.325976    2.000
196p          -0.822538    6.000
206d          -0.143190    1.000
217s          -0.130948    2.000
22 Print the first 10 values of the 1st and 2nd orbitals:
23   1753.2892641883584        1753.2812175211841        1753.2731512531607        1753.2650645481160        1753.2569495840532        1753.2488203554758        1753.2406710770906        1753.2325014795395        1753.2243110250588        1753.2160993495806
24   587.50702296395195        587.50432661503442        587.50162369317059        587.49891391928361        587.49619467268258        587.49347064291044        587.49073989144335        587.48800232804547        587.48525777252200        587.48250610287175

Parsing and AST Generation

The test for the parser is essentially to check if the output before and after formatting with lfortran still compiles to the same result. Note that because of the nature of this, we need to ensure -ffree-line-length-none is passed when working with the gfortran compiler.

1cd minidftatom
2# -i --> Inplace modification
3for file in *.f90; do lfortran fmt -i $file; done
4make clean
5FC=gfortran cmake .
6make -j$(nproc)

Dependency Tree

Before going on to the ASR, a dependency tree is required. As before, it is reproduced in excruciating detail in the issue, and represented by a pretty picture shown in Fig. mdftatomgit for this post.

1pip install fortdepend
2cd minidftatom/src
3fortdepend -g -c

Figure 1: minidftatom compilation dependency graph

Figure 1: minidftatom compilation dependency graph

ASR Generation

I found a new favorite command, which I should have remembered while it was being implemented (by Thirumalai Shaktivel in 765); namely the --indent option which makes for a much more readable ASR output. Apart from that git diff --color-words works well enough as well.


The main work plan outcomes for the week were the new design specifications for the compile time evaluation of expressions. It is always an enriching experience to work with Ondrej directly (even over the ether) and this week felt more productive than most. I hope to keep the same momentum going. This will allow faster progress on the main issue of getting ASR generated for minidftatom.