Improve fatal error message when handling promised interfaces
authorMehdi Amini <joker.eph@gmail.com>
Sat, 24 Jun 2023 01:15:47 +0000 (03:15 +0200)
committerMehdi Amini <joker.eph@gmail.com>
Sat, 24 Jun 2023 01:48:10 +0000 (03:48 +0200)
When initializing DialectInterfaceCollection, we wouldn't have the missing
interface name in the error.

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

mlir/include/mlir/IR/DialectInterface.h
mlir/lib/IR/Dialect.cpp

index d5d36ed..3a7ad87 100644 (file)
@@ -97,7 +97,8 @@ class DialectInterfaceCollectionBase {
   using InterfaceVectorT = std::vector<const DialectInterface *>;
 
 public:
-  DialectInterfaceCollectionBase(MLIRContext *ctx, TypeID interfaceKind);
+  DialectInterfaceCollectionBase(MLIRContext *ctx, TypeID interfaceKind,
+                                 StringRef interfaceName);
   virtual ~DialectInterfaceCollectionBase();
 
 protected:
@@ -159,7 +160,8 @@ public:
   /// Collect the registered dialect interfaces within the provided context.
   DialectInterfaceCollection(MLIRContext *ctx)
       : detail::DialectInterfaceCollectionBase(
-            ctx, InterfaceType::getInterfaceID()) {}
+            ctx, InterfaceType::getInterfaceID(),
+            llvm::getTypeName<InterfaceType>()) {}
 
   /// Get the interface for a given object, or null if one is not registered.
   /// The object may be a dialect or an operation instance.
index ebf40a7..501f52b 100644 (file)
@@ -122,8 +122,11 @@ MLIRContext *DialectInterface::getContext() const {
 }
 
 DialectInterfaceCollectionBase::DialectInterfaceCollectionBase(
-    MLIRContext *ctx, TypeID interfaceKind) {
+    MLIRContext *ctx, TypeID interfaceKind, StringRef interfaceName) {
   for (auto *dialect : ctx->getLoadedDialects()) {
+#ifndef NDEBUG
+  dialect->handleUseOfUndefinedPromisedInterface(interfaceKind, interfaceName);
+#endif
     if (auto *interface = dialect->getRegisteredInterface(interfaceKind)) {
       interfaces.insert(interface);
       orderedInterfaces.push_back(interface);