-
Notifications
You must be signed in to change notification settings - Fork 164
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
Investigate using opaque MLIR as our AST #101
Comments
I’m quite skeptical of this, as function bodies is only a fraction of the AST. Stuff like signatures, types, classes and interfaces, modules and imports... also need to be represented. |
I'm sceptical too, but it's worth investigating, even if to quickly conclude it's not a good idea. The assumption is that complex types and signatures can be represented as text or attributes, and classes and interfaces to be an annotation on a lexical block. Modules could be done via name mangling (like namespace) and imports would probably be done before lowering to MLIR. The reason behind this is that keeping a formal AST with rich semantics is yet-another internal representation. Also, there was the idea of doing the type inference directly in MLIR, which this path would make it much simpler. That is, of course, if it's at all possible. This task is just to investigate, discuss and come back with a consensus. Whatever the direction later, we'll create the appropriate issues. |
I am also sceptical and suggested we try it. I just think MLIR regions might make this possible as they allow nesting regions of code. But symbol resolution probably will be the problem as they can only refer to sibling and parent regions. If we use regions to represent classes, then the methods won't be exposed. But perhaps there is another encoding trick. The main reason I like this, is that having a "single" format for all the stages would make some tooling nicer. Probably not worth the pain, but worth investigating. |
Very rough draft, types are going to be hard without at least a shell dialect. |
I prefer the I think the example does not reflect one of the challenges @plietar raised. Fields: etc, Where we will need something to declare the shape of the classes. This is also going to have to take account of generics. Something like https://github.com/microsoft/verona/blob/master/testsuite/demo/run-pass/bank1.verona is about the simplist thing with fields. We need something in the MLIR dialect to declare them. |
Right, me too. I'm working on moving the standalone example from MLIR as a skeleton for the Verona dialect, so we can have opaque !verona<> types for now at least. But I need to plug the CMake files in the right or risk breaking the rest of the build. I'm hoping we can get any additional requirements as attributes, like |
Stub Verona dialect: https://github.com/rengolin/verona/tree/mlir-ast/mlir |
Turns out there's an option to enable opaque operands and types without the need of a stub dialect: The new |
Now we need to show that we can represent all concepts from the language we want only using opaque operations, types and attribute lists. |
Keep in mind a few things that are not present in the current interpreter (I don't think any these will be impossible in MLIR, but I could be wrong):
I think the last ones are the ones most likely to cause problems, because the callee won't be known at early lowering time and will need to be transmuted and possibly synthesised after type checking. I think MLIR supports this, it's a bit painful to do with LLVM IR. |
A few ways we could do those:
The others, I really don't know how to do. We talked about this yesterday and the consensus is that it may be too early to go straight to MLIR. First, it's clear we don't know how to lower most of the advanced concepts of Verona, and that's the whole point of creating a new language. :) Second, even if we did lower everything (ex. as attribute lists and opaque ops/types), the manipulation of this "AST" would be tedious and under-performing. AST nodes are small structures with clear semantics, translating that to an opaque representation of lists of lists with string comparisons isn't going to make it fast. Finally, Sylvan already has an AST prototype (#111) that can parse some variation of the Verona grammar, and will allow us to work on different levels of the compiler at the same time, so it's a better early development strategy. I'll close this ticket now but, once we have a better view of the AST/MLIR dialects, and we want to revisit this idea, we can either reopen it or create a new one. |
For reference, this is the last version of the "opaque" MLIR file:
|
Weigh the pros and cons of using opaque MLIR as our AST instead of having a hand-coded AST structure.
Acceptance criteria:
Not included:
The text was updated successfully, but these errors were encountered: