PSA: API contract change with Attribute/Type printer

Right now we have an asymmetry between the method on the Type/Attribute in how the mnemonic is handled.

Here is an example from the repo:


Type emitc::OpaqueType::parse(DialectAsmParser &parser) {
  if (parser.parseLess())
    return Type();
  ...
}

void emitc::OpaqueType::print(DialectAsmPrinter &printer) const {
  printer << "opaque<\"";
  llvm::printEscapedString(getValue(), printer.getStream());
  printer << "\">";
}

The parser starts after the mnemonic has been consumed, but the printer starts before.

I just resolved this in https://reviews.llvm.org/D113334 by changing the printer to:

void emitc::OpaqueAttr::print(DialectAsmPrinter &printer) const {
  printer << "<\"";
  llvm::printEscapedString(getValue(), printer.getStream());
  printer << "\">";
}

The change is trivial, but it isn’t a compile time failure: it’ll trigger in your failing tests!

4 Likes

Thank you for aligning these. it is also great to eliminate the boilerplate.