Skip to content

Compiling Fortran Package Manager (FPM) with LFortran #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 5 tasks
certik opened this issue May 29, 2025 · 0 comments
Open
1 of 5 tasks

Compiling Fortran Package Manager (FPM) with LFortran #17

certik opened this issue May 29, 2025 · 0 comments

Comments

@certik
Copy link

certik commented May 29, 2025

Project

LFortran

Summary

We propose to improve LFortran to be able to compile and run the Fortran Package Manager (FPM) code, which utilizes a lot of OOP features of Fortran. Compiling it enhances LFortran's capability to compile Object Oriented code.

submitter

Ondřej Čertík

project lead

@certik

Community benefit

With the successful compilation of FPM, LFortran will gain robust support for object-oriented features. This advancement will enable LFortran to be evaluated against a broader range of Fortran projects that utilize OOP features. Achieving the goals outlined in the grant would significantly help to bring LFortran from alpha stage to beta (expected to work) for modern Fortran codes.

For the broader Fortran community, the ability to distribute an open-source, modern Fortran compiler alongside FPM represents a significant milestone, as it will streamline project management and help attract greater adoption. This is because LFortran is compatible with all the platforms while being very lightweight.

Amount requested

10000

Execution plan

Description of Proposal

The Fortran Package Manager (fpm) is a package manager and a build system for Fortran. Its key goal is to improve the user experience of Fortran programmers. It does so by making it easier to build your Fortran program or library, run the executables, tests, and examples, and distribute it as a dependency to other Fortran projects.

Most Fortran projects employ diverse build systems such as cmake, make or meson tailored to specific compiler toolchains such as GFortran, Intel, and Cray. The Fortran Package Manager (FPM) standardizes and simplifies this process by offering a unified and streamlined build system, inspired by Cargo from Rust.

LFortran is a modern Fortran compiler that in addition to compiling to binaries like other compilers can also execute Fortran code interactively. It implements a structured multi-step lowering strategy where the source code is parsed into an Abstract Syntax Tree; then to an intermediate Abstract Semantic Representation (ASR) before being handled by various backends. The ASR is by construction always valid Fortran code. ASR to ASR passes allow for further optimizations and downstream backends (LLVM, WebAssembly, etc.) are guaranteed to receive semantically valid Fortran.

Compilation of FPM demands compilation of the following third-party codes:

Current status of LFortran:

  • LFortran already compiles fortran-regex, refer lfortran-7495 for more details.
  • LFortran can generate ASR ( Abstract Semantic Representation ) for all Fortran files in FPM.
  • LFortran can currently compile 44% of FPM to binaries (reported at: lfortran-6840)
  • LFortran can compile 64% of toml-f to binaries. (Reported at: lfortran-6838)
  • Successful 72% compilation of jonquil. (Reported at: lfortran-7494)
  • 50% compilation of fortran-shlex. ( Reported at lfortran-7496)
  • Lastly, status of M_CLI2 can be found at lfortran-7497

Although compilation of FPM depends on the 5 packages, these do not serve as blocker in achieveing 100% compilation as based on our past experience LFortran can generate binaries for almost every Fortran code with a few workarounds.

Proposed Work:

  • Achieve 100% compilation of FPM to object files.
    • Every Fortran file generates valid LLVM.
  • Final binary is generated and runs successfully.

As of now LFortran can compile substantial subset of FPM, but it needs to be finished. We have identified the following semantic features that still have to be implemented / refactored:

  • Enhance runtime polymorphism, difficulty: medium
  • Refactor handling of structs, difficulty: medium
  • Bug fixes while compiling

The LFortran community includes several developers (Ondřej Čertík, Pranav Goswami) who have contributed substantially to FPM and LFortran in past, ensuring smooth collaboration of all projects. This project is also well placed within the existing LFortran road-map: the goal of LFortran is to compile all Fortran codes.

Timeline of Deliverables:

12 weeks

We will begin with the existing build base and proceed to compile all source files to LLVM. To fully utilize FPM for building the project, it is essential to first compile its dependencies and generate the necessary binaries. This effort will proceed along two parallel tracks: one focused on leveraging the current base to continue compiling to LLVM, and the other dedicated to addressing FPM dependencies and generating binaries. Given this parallel approach, defining a precise timeline for individual deliverables is challenging. However, the following tentative milestones are outlined:

  • 4 weeks: Enable FPM dependencies to work seamlessly with LFortran and setup at CI to avoid regression.
    • Compile to ASR
    • Generate a binary (ASR passes and ASR->LLVM lowering)
    • Fix runtime bugs
  • 8 weeks: Achieve complete FPM compilation (100%) using LFortran
    • Compile to ASR
    • Generate a binary (ASR passes and ASR->LLVM lowering)
    • Fix runtime bugs

The above are parallel, total of 8 weeks, the result will compile and run, with workarounds in the Fortran FPM code. Then the last 4 weeks:

  • Fix all workarounds by fixing a given bug in LFortran, and removing the workaround from Fortran code.

A list of high priority issues can be found at lfortran-label:toml-f.

People

We have identified Pranav Goswami (@Pranavchiku), Gauravsingh Sisodia (@xaerru), Harshita Kalani (@HarshitaKalani), Jinang Shah (@jinangshah21), Assem Medhat (@assem2002) as possible contractors, all of them have an extensive multi-year prior experience with contributing to LFortran and have implemented many of the existing features into LFortran already. If they are unavailable, we have several more contractors that we work with regularly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant