[Mlir-commits] [mlir] 7e9b000 - Improve diagnostic when parsing a custom op without registering the dialect

Mehdi Amini llvmlistbot at llvm.org
Wed Nov 16 13:42:45 PST 2022


Author: Mehdi Amini
Date: 2022-11-16T21:42:33Z
New Revision: 7e9b0005f205c9578938d09e171ee7dccaddf916

URL: https://github.com/llvm/llvm-project/commit/7e9b0005f205c9578938d09e171ee7dccaddf916
DIFF: https://github.com/llvm/llvm-project/commit/7e9b0005f205c9578938d09e171ee7dccaddf916.diff

LOG: Improve diagnostic when parsing a custom op without registering the dialect

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D138151

Added: 
    

Modified: 
    mlir/lib/AsmParser/Parser.cpp
    mlir/test/IR/invalid.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/AsmParser/Parser.cpp b/mlir/lib/AsmParser/Parser.cpp
index 4bb4fdf013b09..9b6d66582f837 100644
--- a/mlir/lib/AsmParser/Parser.cpp
+++ b/mlir/lib/AsmParser/Parser.cpp
@@ -1871,8 +1871,24 @@ OperationParser::parseCustomOperation(ArrayRef<ResultRecord> resultIDs) {
       defaultDialect = iface->getDefaultDialect();
   } else {
     Optional<Dialect::ParseOpHook> dialectHook;
-    if (Dialect *dialect = opNameInfo->getDialect())
-      dialectHook = dialect->getParseOperationHook(opName);
+    Dialect *dialect = opNameInfo->getDialect();
+    if (!dialect) {
+      InFlightDiagnostic diag =
+          emitError(opLoc) << "Dialect `" << opNameInfo->getDialectNamespace()
+                           << "' not found for custom op '" << originalOpName
+                           << "' ";
+      if (originalOpName != opName)
+        diag << " (tried '" << opName << "' as well)";
+      auto &note = diag.attachNote();
+      note << "Registered dialects: ";
+      llvm::interleaveComma(getContext()->getAvailableDialects(), note,
+                            [&](StringRef dialect) { note << dialect; });
+      note << " ; for more info on dialect registration see "
+              "https://mlir.llvm.org/getting_started/Faq/"
+              "#registered-loaded-dependent-whats-up-with-dialects-management";
+      return nullptr;
+    }
+    dialectHook = dialect->getParseOperationHook(opName);
     if (!dialectHook) {
       InFlightDiagnostic diag =
           emitError(opLoc) << "custom op '" << originalOpName << "' is unknown";

diff  --git a/mlir/test/IR/invalid.mlir b/mlir/test/IR/invalid.mlir
index 064b2ed6f749f..226dfdd9f02f6 100644
--- a/mlir/test/IR/invalid.mlir
+++ b/mlir/test/IR/invalid.mlir
@@ -112,6 +112,14 @@ func.func @non_operation() {
 
 // -----
 
+func.func @unknown_dialect_operation() {
+  // expected-error at below {{Dialect `foo' not found for custom op 'foo.asd'}}
+  // expected-note-re at below {{Registered dialects:{{.*}} test{{.*}}}}
+  foo.asd
+}
+
+// -----
+
 func.func @non_operation() {
   // expected-error at +1 {{custom op 'asd' is unknown (tried 'func.asd' as well)}}
   asd


        


More information about the Mlir-commits mailing list