I write Swift. What’s the best way to lower S-expressions representing a high-level, feature-rich language like Swift to MLIR?
What is Swift?
Swift is high-level and feature-rich. Some features:
letconstant variable bindings and
varmutable variable bindings.
- Structs (value types), classes (reference types), enums (algebraic data types).
- Statically typed: all values have a compile-time type and a runtime type.
- Protocols and conformances: traits/typeclasses and their implementations/instances for specific conforming types.
- First-class functions: need “lambdas” in the language representation.
- Higher-order functions:
- C-style structured control flow constructs:
- Separate compilation: function declarations may exist that have no body. “Optimizations required for correctness” like inlining are bad.
- More! Let’s start with a small core and grow our coverage (ambition) though.
What do I want from MLIR?
Plugging a frontend language into MLIR (e.g. implementing
Swift → MLIR) is easiest when there is a MLIR dialect (or multiple) that is similar in abstraction level to the frontend language.
I would like an MLIR dialect that’s the easiest target for Swift, which is described above.
Any ideas? Also, I’m going to need some MLIR builder C APIs so I can import them in Swift. (until Swift gets sufficiently powerful C++ interop)