diff --git a/mlir/lib/AsmParser/Parser.cpp b/mlir/lib/AsmParser/Parser.cpp --- a/mlir/lib/AsmParser/Parser.cpp +++ b/mlir/lib/AsmParser/Parser.cpp @@ -1871,8 +1871,24 @@ defaultDialect = iface->getDefaultDialect(); } else { Optional 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 ¬e = 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 --- a/mlir/test/IR/invalid.mlir +++ b/mlir/test/IR/invalid.mlir @@ -112,6 +112,14 @@ // ----- +func.func @unknown_dialect_operation() { + // expected-error@below {{Dialect `foo' not found for custom op 'foo.asd'}} + // expected-note-re@below {{Registered dialects:{{.*}} test{{.*}}}} + foo.asd +} + +// ----- + func.func @non_operation() { // expected-error@+1 {{custom op 'asd' is unknown (tried 'func.asd' as well)}} asd