Skip to content

Commit 00b7d95

Browse files
committed
Stop stripping the std. prefix when printing operations in a region with a defined default dialect
This fixes round-trip / ambiguity when an operation in the standard dialect would have the same name as an operation in the default dialect. Differential Revision: https://reviews.llvm.org/D111204
1 parent d60bfa6 commit 00b7d95

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

mlir/lib/IR/Operation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,9 @@ void OpState::printOpName(Operation *op, OpAsmPrinter &p,
646646
StringRef name = op->getName().getStringRef();
647647
if (name.startswith((defaultDialect + ".").str()))
648648
name = name.drop_front(defaultDialect.size() + 1);
649-
// TODO: remove this special case.
650-
else if (name.startswith("std."))
649+
// TODO: remove this special case (and update test/IR/parser.mlir)
650+
else if ((defaultDialect.empty() || defaultDialect == "builtin") &&
651+
name.startswith("std."))
651652
name = name.drop_front(4);
652653
p.getStream() << name;
653654
}

mlir/test/IR/parser.mlir

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,7 @@ func @pretty_names() {
13121312
// operations like `test.default_dialect` can define a default dialect
13131313
// used in nested region.
13141314
// CHECK-LABEL: func @default_dialect
1315-
func @default_dialect() {
1315+
func @default_dialect(%bool : i1) {
13161316
test.default_dialect {
13171317
// The test dialect is the default in this region, the following two
13181318
// operations are parsed identically.
@@ -1324,8 +1324,17 @@ func @default_dialect() {
13241324
// example.
13251325
// CHECK: "test.op_with_attr"() {test.attr = "test.value"} : () -> ()
13261326
"test.op_with_attr"() {test.attr = "test.value"} : () -> ()
1327+
1328+
// TODO: remove this after removing the special casing for std in the printer.
1329+
// Verify that operations in the standard dialect keep the `std.` prefix.
1330+
// CHECK: std.assert
1331+
assert %bool, "Assertion"
13271332
"test.terminator"() : ()->()
13281333
}
1334+
// The same operation outside of the region does not have an std. prefix.
1335+
// CHECK-NOT: std.assert
1336+
// CHECK: assert
1337+
assert %bool, "Assertion"
13291338
return
13301339
}
13311340

0 commit comments

Comments
 (0)