[Mlir-commits] [mlir] [NFC] Parser: Include the unrecognized dialect in errors. (PR #96676)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Jun 26 09:35:37 PDT 2024
https://github.com/pizzud updated https://github.com/llvm/llvm-project/pull/96676
>From 34ae45fe8e41a019f3a6b6d79f9d37148b222dd3 Mon Sep 17 00:00:00 2001
From: pizzud <123112817+pizzud at users.noreply.github.com>
Date: Tue, 25 Jun 2024 11:28:39 -0700
Subject: [PATCH 1/2] [NFC] Parser: Include the unrecognized dialect in errors.
Listing the dialect shortens the journey needed to add it and resolve the error.
---
mlir/lib/AsmParser/Parser.cpp | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/mlir/lib/AsmParser/Parser.cpp b/mlir/lib/AsmParser/Parser.cpp
index 1b8b4bac1821e..6322a77a1c231 100644
--- a/mlir/lib/AsmParser/Parser.cpp
+++ b/mlir/lib/AsmParser/Parser.cpp
@@ -1416,9 +1416,13 @@ Operation *OperationParser::parseGenericOperation() {
if (!getContext()->allowsUnregisteredDialects()) {
// Emit an error if the dialect couldn't be loaded (i.e., it was not
// registered) and unregistered dialects aren't allowed.
- emitError("operation being parsed with an unregistered dialect. If "
- "this is intended, please use -allow-unregistered-dialect "
- "with the MLIR tool used");
+ std::string message;
+ llvm::raw_string_ostream os(message);
+ os << "operation being parsed with an unregistered dialect "
+ << dialectName
+ << "If this is intended, please use -allow-unregistered-dialect "
+ "with the MLIR tool used";
+ emitError(message);
return nullptr;
}
} else {
>From 4214688e394bf937df997316e6087d1386a9cd7c Mon Sep 17 00:00:00 2001
From: pizzud <123112817+pizzud at users.noreply.github.com>
Date: Tue, 25 Jun 2024 11:28:39 -0700
Subject: [PATCH 2/2] [NFC][MLIR] Parser: Include the unrecognized dialect in
errors.
Listing the dialect shortens the journey needed to add it and resolve the error.
---
mlir/lib/AsmParser/Parser.cpp | 7 ++++---
mlir/unittests/Parser/ParserTest.cpp | 27 +++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/mlir/lib/AsmParser/Parser.cpp b/mlir/lib/AsmParser/Parser.cpp
index 1b8b4bac1821e..06f1019639684 100644
--- a/mlir/lib/AsmParser/Parser.cpp
+++ b/mlir/lib/AsmParser/Parser.cpp
@@ -1416,9 +1416,10 @@ Operation *OperationParser::parseGenericOperation() {
if (!getContext()->allowsUnregisteredDialects()) {
// Emit an error if the dialect couldn't be loaded (i.e., it was not
// registered) and unregistered dialects aren't allowed.
- emitError("operation being parsed with an unregistered dialect. If "
- "this is intended, please use -allow-unregistered-dialect "
- "with the MLIR tool used");
+ emitError("operation being parsed with an unregistered dialect '")
+ << dialectName
+ << "'. If this is intended, please use -allow-unregistered-dialect "
+ "with the MLIR tool used";
return nullptr;
}
} else {
diff --git a/mlir/unittests/Parser/ParserTest.cpp b/mlir/unittests/Parser/ParserTest.cpp
index 62f609ecf8049..5cd0af448bf55 100644
--- a/mlir/unittests/Parser/ParserTest.cpp
+++ b/mlir/unittests/Parser/ParserTest.cpp
@@ -101,4 +101,31 @@ TEST(MLIRParser, ParseAttr) {
EXPECT_EQ(attr, b.getI64IntegerAttr(9));
}
}
+
+TEST(MLIRParser, UnknownDialect) {
+ using namespace testing;
+ // We need a dialect that exists but is not registered to the
+ // context so that its ops are unrecognized but we can still get
+ // a name for it.
+ std::string moduleStr = R"mlir(
+ builtin.module {
+ "test.int_types"() () -> (i16, si32, ui64, i8)
+ }
+ )mlir";
+
+ MLIRContext context;
+ ASSERT_THAT(context.getAvailableDialects(), Not(Contains("test")));
+
+ ParserConfig config(&context, /*verifyAfterParse=*/false);
+ std::vector<std::string> diagnostics;
+ ScopedDiagnosticHandler handler(&context, [&](Diagnostic &d) {
+ llvm::raw_string_ostream(diagnostics.emplace_back())
+ << d.getLocation() << ": " << d;
+ });
+
+ OwningOpRef<ModuleOp> module = parseSourceString<ModuleOp>(moduleStr, config);
+ EXPECT_FALSE(module);
+
+ EXPECT_THAT(diagnostics, ElementsAre(HasSubstr("operation being parsed with an unregistered dialect 'test'. If this is intended, please use -allow-unregistered-dialect with the MLIR tool used")));
+}
} // namespace
More information about the Mlir-commits
mailing list