NFC: Elide the value of a UnitAttr within nested attribute dictionaries.
authorRiver Riddle <riverriddle@google.com>
Mon, 21 Oct 2019 18:01:38 +0000 (11:01 -0700)
committerA. Unique TensorFlower <gardener@tensorflow.org>
Mon, 21 Oct 2019 18:02:07 +0000 (11:02 -0700)
This matches the behavior of the top level attribute dictionary.

PiperOrigin-RevId: 275879828

mlir/lib/IR/AsmPrinter.cpp
mlir/test/IR/parser.mlir

index 4b29f0d..0200e98 100644 (file)
@@ -746,7 +746,13 @@ void ModulePrinter::printAttribute(Attribute attr, bool mayElideType) {
     os << '{';
     interleaveComma(attr.cast<DictionaryAttr>().getValue(),
                     [&](NamedAttribute attr) {
-                      os << attr.first << " = ";
+                      os << attr.first;
+
+                      // The value of a UnitAttr is elided within a dictionary.
+                      if (attr.second.isa<UnitAttr>())
+                        return;
+
+                      os << " = ";
                       printAttribute(attr.second);
                     });
     os << '}';
index d33186a..31452e0 100644 (file)
@@ -521,11 +521,14 @@ func @stringquote() -> () {
 
 // CHECK-LABEL: func @unitAttrs
 func @unitAttrs() -> () {
-  // CHECK-NEXT: "foo"() {unitAttr} : () -> ()
+  // CHECK-NEXT: "foo"() {unitAttr}
   "foo"() {unitAttr = unit} : () -> ()
 
-  // CHECK-NEXT: "foo"() {unitAttr} : () -> ()
+  // CHECK-NEXT: "foo"() {unitAttr}
   "foo"() {unitAttr} : () -> ()
+
+  // CHECK-NEXT: "foo"() {nested = {unitAttr}}
+  "foo"() {nested = {unitAttr}} : () -> ()
   return
 }