lfortran / lfortran/lfortran

ASR design improvements

Open
#487 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
1.2k
Forks
271
Avg merge
1d 2h
Merged PRs (30d)
173

Description

Original issue: https://gitlab.com/lfortran/lfortran/-/issues/636

Here are some design improvements/simplifications/generalizations that I think we should consider for ASR and either implement, or reject and document why not:

  • Unify Subroutine/Function into just Function, that has return_type optional (if null, it is a subroutine) (https://gitlab.com/lfortran/lfortran/-/issues/703)
  • Unify stmt and expr into just expr (might actually make things more complex, so might not be worth it..)
  • Unify Explicit/ImplicitCast into just Cast
  • https://gitlab.com/lfortran/lfortran/-/issues/637: Add builtin functions size, len, u/lbound, shape, allocated into ASR itself (one way or another) to make ASR self contained (similar to the string // operation already in ASR)
  • Implement lambda function node, with closures (environment), then make Subroutine/Function just use it (empty environment = no closure), and nested functions might have non empty environment. The LLVM backend then just needs to implement closures in a clean way as a first class feature (currently it is a bit complicated and maybe not fully general). For Fortran only a subset would be used, but for Python (or Scheme) frontends this would be used fully.
  • Function type (signature) should probably be a first class type (helpful for type(procedure)) (https://github.com/lfortran/lfortran/issues/1162)
  • Implement generics/templates
  • Brainstorm how dimension/arrays are implemented in the type system
  • Add a tuple type (where each element is typed), allow to return it from functions
  • Add a dictionary type (the key/value are both typed), allow to return it from functions
  • Add a set type, allow to return it from functions
  • See if we can add a DataFrame (R/Panda/Apache Arrow style)
  • Masked arrays to represent missing values (related to data frame also)
  • Efficient "push_back" for 1D arrays, just like std::vector::push_back() with efficient doubling of internal allocated memory as needed
  • Each type has associated intrinsic functions that operate on it: complex has %re and %im; array has size, shape, u/lbound. String has len, concat. Dictionary has element access and appending, etc. Set has element access and appending.
  • Besides parallel loops and coarrays, also implement task based parallelism
  • Consider adding unsigned integers (for C interoperability and interacting with binary data formats that may store data in unsigned types)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the ASR design and the linked issues, especially the completed Function unification and builtin-function work. Break the remaining proposals into focused issues; for each, record whether it is accepted or rejected with rationale and define completion separately, since this issue has no single implementation target or named files and tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.