Skip to content

[mlir] prop-dict printout sometimes starts with <{, but sometimes with < { #145695

Closed
@peledins-zimperium

Description

@peledins-zimperium

This happens, because:

void OpState::genericPrintProperties(OpAsmPrinter &p, Attribute properties,
                                     ArrayRef<StringRef> elidedProps) {
...
if (dictAttr && !elidedProps.empty()) {
...
    if (atLeastOneAttr) {
      p << "<";
      p.printOptionalAttrDict(dictAttr.getValue(), elidedProps); // "< {" - has space
      p << ">";
    }
  } else {
    p << "<" << properties << ">"; // "<{" - no space
  }
...

This depends on whether there are ellided properties being specified in printout or not:
In "< {" case the end result is:

AsmPrinter::Impl::printOptionalAttrDict
...
    // Otherwise, print them all out in braces.
    os << " {"; //// THE SPACE IS COMING FROM HERE
    interleaveComma(filteredAttrs,
                    [&](NamedAttribute attr) { printNamedAttribute(attr); });
    os << '}';

But in other case

void AsmPrinter::Impl::printAttributeImpl(Attribute attr,
                                          AttrTypeElision typeElision) {
  if (!isa<BuiltinDialect>(attr.getDialect())) {
...
  } else if (auto dictAttr = llvm::dyn_cast<DictionaryAttr>(attr)) {
    os << '{';
    interleaveComma(dictAttr.getValue(),
                    [&](NamedAttribute attr) { printNamedAttribute(attr); });
    os << '}';

It would be great to be consistent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions