[mlir] Printing types in dialect attributes

I can write a custom dialect attribute printer for the following:

#foo.bar<0> : i32

The operation parser will look ahead and optionally parse the colon-type. But if my dialect attribute printer is just

printer << '<' << getValue() << '>';

The output is


I have to manually print the type, but there’s no way to print it the same way it’s parsed, because

printer << '<' << getValue() << "> : " << getType();

Results in

#foo<"bar<0> : i32">

Is this an oversight or an intentional design decision? The dialect attribute parser supports parsing ahead to get an optional type, but the printer does not.

The attribute isn’t in charge of printing the type, the framework is. The AsmPrinter code looks buggy:

We shouldn’t be returning early there, because it skips type handling.

1 Like

OK, that’s what I thought. Thanks for clarifying. I’ll fix that up in my patch for https://github.com/llvm/llvm-project/issues/55324