-
Notifications
You must be signed in to change notification settings - Fork 6
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
IR traits #21
IR traits #21
Conversation
How would you parse types or attributes if their |
I see. I originally did print them as well, but I did find the output quite noise and somewhat repetitive. The parsing issue is where the The idea is that the IR will become fully typed. That is in case of Type/Attribute objects we want the parameters to be typed. For object types we require their attributes/outputs/inputs to be typed. For some Type/Attribute values this is implicitly the case thanks to us using Rust structures. For example
The parameters In the case of an attribute referencing a type we only have
In order to guarantee that we can only write "safe" code we would have to introduce properly typed setters and getters and choose the right parser manually when implementing Ideally we would be able to make
Now
Alternatively(or in addition) to introducing the With properly typed At least
Here we need elem to be To summarize For Op I'm not fully sure yet on how to express this in code. This is also a challenge for custom generated printer/parser from assembly format directives. But borrowing from MILR TableGen I'm thinking on extending the
The Printer/Parser code gen will get meta-data about that definition passed in from Not exactly sure how this will look in code though. maybe something like:
here |
IMO, this is getting needlessly complicated. But specifically,
shouldn't exist. Since
This is a valid concern too, but I think letting the verifier ensure it (as it is doing already) should be sufficient. Let's keep it as it is w.r.t printing and parsing types and attributes, i.e., they're always led by a qualifier (typeid, attrid).
This is a genuine concern, and we can solve it (in the future) the way MLIR does it.
But either way, neither of this is critical at the moment. So let's just go with compulsory qualifier for all qualified IR entities. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR is mostly ok. I just have a couple of minor comments.
src/parsable.rs
Outdated
@@ -429,7 +429,7 @@ impl NameTracker { | |||
// Check if there are any unresolved forward label references. | |||
for (id, op) in label_scope { | |||
if matches!(op, LabelRef::ForwardRef(_)) { | |||
input_err!(loc.clone(), UnresolvedReference(id.clone()))? | |||
return input_err!(loc.clone(), UnresolvedReference(id.clone()))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops, I wanted to clean that up. I had a conflict with the commit introducing locations when rebasing
src/type.rs
Outdated
} | ||
} | ||
|
||
/// Trait for objects that have a direct type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
object IR entity. Here and the next line.
src/common_traits.rs
Outdated
error::Result, | ||
}; | ||
|
||
// Objects that have a qualified name within a dialect. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Objects IR entities
I'm not sure I fully understand your concern. The Alternatively to In case
I did take inspiration from MLIR actually. At first I was not sure if omitting the type mnemonic is a good idea, but then I checked MLIR and the idea did grow on me. See assembly format directives for attributes and types (The In code generated by MLIR the fields of attributes/types are by default printed via The parsing of fields (for code generated from TableGen) is implemented via Having said this, we will continue to print attributes/types using mnemonics for the time being. This will be guaranteed by implementing Currently the builtin
And parse like this:
The implementations for
I think this makes it easier (more error proof) to create the proper printer for the attributes. |
Q: Do you want to keep the |
You're right. I had misunderstood this.
Okay good. I don't want to fully go the MLIR way for legibility, where the mnemonics are optional. In fact, I'm now thinking we shouldn't make special cases for builtin types either. The right way to improve legibility is via type aliases. So
If we don't need it at the moment, let's not add it. I think the explicit
Sounds good. So when you make this change, you'll do ☝️ also for all existing (already defined) types and attributes right? |
I like the idea about using aliases for builtins. This would reduce the need for custom printing/parsing functions. Like int and float types.
Removed.
yes. |
@@ -170,6 +170,12 @@ impl Value { | |||
} | |||
} | |||
|
|||
impl Typed for Value { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you see any problem if I just replace this function with the contents of Value::get_type(..)
and remove that impl
method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i.e., get_type(..)
won't be a method on Value
anymore, but will provide that functionality by implementing the Typed
trait.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem with that. I was thinking to propose this as a follow up :)
Backport from #20 This PR introduces the `irfmt/printers` module with common printer functions. In #20 we implement `asm_format` directives as macros. These macros will use the printer functions defined here (and more to come). As secondary goal we want to make it easier for downstream developers to implement their own printers, while trying to keep some kind of standardized format. For this reason we also implement Printable for some more IR objects in pliron. The change also removes the `PrintableIter` trait in favor of the `list_with_sep` and `iter_with_sep` printer functions in the irfmt package. This change ensures that we have a single trait for printing in the library. As discussed in #21 we do not require developers to add the type_id or attribute_id manually to the printer anymore. `pliron` now implements a printer for TypeObj/AttribObj that will always print the IDs. --------- Co-authored-by: urso <steffen.siering at gmail.com> Co-authored-by: Vaivaswatha N <[email protected]>
Backport from #20
This PR adds the
Typed
andQualified
traits for IR objects.The
Typed
traits is added to each internal IR object that must have a type.The
Typed
trait is used by thetyped
assembler format directive.I opted to make Attributes not
Typed
, as it is up to the implementation of the attribute of the attribute has a type or not.The
Operation
is not marked asTyped
as well, although that would make sense. We might consider to use the built-inFunctionType
for operations.The
Qualified
trait describes IR objects that have a mnemonic. In pliron we haveTypeID
andAttrID
asQualifier
s. TheQualified
trait is used by thequalified
andqualifier
printing directives in #20.The idea of the
qualified
printer is similar to MLIR, where for attributes/types the qualifier is normally not printed by default. In some cases (e.g. generic types) one might need the qualifier to decide on parsing.For example in #20 I have a vec type that accepts another type as parameter:
This produces the output: