LFortran's main advantage is that it is interactive, so the parser and semantics has to be a little different. And also we designed it so that it will be quite approachable for people to write tools on top.
519 karma · joined March 22, 2019
LFortran's main advantage is that it is interactive, so the parser and semantics has to be a little different. And also we designed it so that it will be quite approachable for people to write tools on top.
Fortran needs a good compiler, that is why I started LFortran some time ago:
https://lfortran.org/blog/2019/04/why-we-created-lfortran/
and there is also Flang. Both Flang and LFortra are in development. GFortran is currently the most advanced open source compiler.
See our page for the list of all compilers:
The advantage of Fortran is that the code is simple and comprehensible to average scientist, and yet fast, because the effort goes into the compiler itself. I would also argue it is easier to implement an optimization pass in the compiler than implement optimizations on the template level in C++. The disadvantage is that you need a good Fortran compiler. If your compiler can't run your code on, say, GPU, then suddenly there is not a good path forward. While in C++, there is always a way forward via template metaprogramming: perhaps ugly, but at least it gets the job done.
For example, Python's AST is not round-trippable, and that forces people to write alternative parsers such as Parso (https://github.com/davidhalter/parso).
ANTLR should allow to parse all the white space. But the issue is how to represent it in the AST, see the issue for more details. One could have an AST and a parser just for this round-trippable application, but that defeats the purpose. The goal should be to have this part of the compiler so that one can trust that it parses things correctly.
Right now I am concentrating my efforts to finish gfortran compatibility (see the roadmap at https://lfortran.org) and to get first users. Once we get further along, we will tackle this problem. I am hopeful there might be a way to do this.
Regarding commercial implementations, I only have experience with Intel and NAG, both of which are very good.
There is a really promising new project by Chris Lattner (the original author of LLVM) called MLIR: https://github.com/tensorflow/mlir. That might be the best intermediate representation that all the compilers (Julia, Fortran, ...) could target.
In the meantime, others in this thread pretty much hit all the main points already why Fortran as a language is still a very good choice for numerical computing. It's the tooling that must improve.
Right now if you have any questions, you can open an issue at our GitLab repository:
Can you please point me to some documentation or examples where Intel Fortran is used to offload to, say, NVIDIA GPUs? I don't think it supports it yet.
PGI and IBM support CUDA Fortran, other compilers don't. PGI/Flang has an experimental support for offloading "do concurrent". Some compilers also support the openmp/openacc pragmas and GPU offloading. One can also call CUDA C from any Fortran compiler via iso_c_binding. None of this is ideal.
I think it's still a research problem how to best integrate GPU support in the language itself. CUDA Fortran is nice --- one thing we want to do down the road is to implement CUDA Fortran and to allow LFortran to transform code it understands into a Fortran dialect that all Fortran compilers can compile, so that one can use any Fortran compiler and still use CUDA Fortran.
The other path is to parallelize "do concurrent", but part of this is also means to extend Fortran to allow to specify the array layout, as Kokkos (https://github.com/kokkos/kokkos) allows.
That is one of the biggest problem with Fortran: people want to be assured that their code will run on modern hardware. When using, e.g., C++ and Kokkos, then there is some assurance that the code will run.
I see what you mean --- that's just a for loop. I created an issue for it: https://gitlab.com/lfortran/lfortran/issues/83.
Thanks for the feedback!
It doesn't yet. Are you interested in this for parsing or for code generation?
If for code generation (i.e., LFortran parses your Fortran code, and then generates a Fortran code back in this format), then I think that will not be that difficult to implement, I think this would be useful.
Regarding parsing, for now my parser is for free form. But I think it would be useful to also have a fixed form parser --- it might need to be a separate parser, but the rest of LFortran can be reused.
> Does it have a linter that can remove linenumbers in the easy cases?
Can you give an example of what you mean?
One issue with linting is that currently the parser is not round-trippable (https://gitlab.com/lfortran/lfortran/issues/42). That means that it can generate the original code back, but it will be formatted differently (mostly white space). Most compilers are not round-trippable. The only compiler that I know about that is round-trippable is C#. Essentially one has to keep track of white space and other formatting, and I didn't want this to complicate the internal representation. I wanted to design the internal representation that is as simple as possible. And then see if one can add optional nodes for white space, similarly how C# does it. If it's possible, then I'll do it.
However, even if it is not round-trippable, the linter can simply generate a nice Fortran code back, and if people use the linter like `clang-format`, enforced by the CI, then it might not be a problem.
Here is the current implementation of ASR (Abstract Semantic Representation) to AST (Abstract Semantic Tree):
https://gitlab.com/lfortran/lfortran/blob/f5856fadf8bd0cc479...
And AST to source code:
https://gitlab.com/lfortran/lfortran/blob/f5856fadf8bd0cc479...
We will be extending it this summer to support more Fortran features.
It's mostly about priority at this point --- I want all of the above to be implemented, it's just about what I do first and what second. Feel free to vote or open new issues here:
https://gitlab.com/lfortran/lfortran/issues
See also my current roadmap/priorities at the bottom of:
The motivation is precisely as you described. In fact, Julia was my initial motivation too: but I didn't want a new language, I wanted the modern interactive environment for Fortran.
In order to get first users and before full Fortran 2018 is supported, I figured out how to parse GFortran's mod files and can interface to GFortran's array descriptors, I am now integrating it in the interactive compiler / REPL. After that is done, for a subset of Fortran, I think this will already be usable (one could use GFortran to compile production code, and use LFortran to use parts of it interactively) and I will announce it more widely. I think this will happen in the next few months.