Adding comments to declarative assembly format

I’m considering adding a ‘comment’ tag to the declarative assembly format. The idea would be to allow having a more legible printed format for operations that have a natural, but non-intuitive assembly format. This might be used like:

($mask,$value,$amsel) attr-dict comment

Where this would assume an Corresponding OpInterface

class CommentAsmInterface : ... {
  std::string generateComment(Operation *op);

The advantage of doing something specific for comments, rather than something more general, would be that we can ensure the appropriate comment syntax and this would be known to have no effect on the parser.

Has anyone considered anything similar?

First there is already an OpAsmOpInterface, I’m not sure why a new interface is needed?
But beyond this, it’s not clear to me why an interface is needed at all? The C++ printers can already print trailing comments today right? So if all you want is the ability to do so in the declarative assembly then that should just be limited there I think.

But if we go with a method on the OpAsmOpInterface, then I’m not even sure why you need to do anything with the declarative assembly in the first place? This would just instruct the MLIR printer framework to always print the comment after the op, independently of the op printer itself.

True… probably having the tag is extranneous… I agree that a custom printer can do this: the point would be to do it with the declarative assembly format.

I wouldn’t want to add anything to the declarative format for this, just feels extraneous. Kind of along Mehdi’s point, you could have a custom directive called from the declarative format that just prints a comment.

If we added something to the existing interface for adding comments, I would expect it to out of the operation’s control (i.e. triggered by the framework, and without anything explicit in the format, either custom or declarative) and be a mechanism for injecting comments.

Sure: but what would you express in there? I assume your “comment” would have to be programmatically generated and it won’t be just a piece of static text right?
If so, you’ll need some C++ code, at which point having an interface makes sense but what needs to be done in the declarative assembly?

I missed this feature! Slick!

An interface would look like this: ⚙ D117942 Add a `printTrailingComment` method on OpAsmOpInterface (see the example uses with the test op).
(this is just a demo revision!)