[Mlir-commits] [mlir] [mlir][Toy] Include generated interface declarations outside of namespaces (PR #236430)

Markus Böck llvmlistbot at llvm.org
Wed Oct 28 07:49:51 PDT 2026


https://github.com/zero9178 created https://github.com/llvm/llvm-project/pull/236430

The `cppNamespace` field is the conventional name to place an interface inside of a namespace. The ShapeInference interface in Toy chapters 4-7 now specifies its cppNamespace, rather than an include into a namespace. The tutorial docs are updated accordingly.

>From 3d21206f08c6756596d077d7b1702c044dd73d82 Mon Sep 17 00:00:00 2001
From: Markus Boeck <mboeck at nvidia.com>
Date: Tue, 27 Oct 2026 10:07:07 +0000
Subject: [PATCH] [mlir][Toy] Include generated interface declarations outside
 of namespaces

The `cppNamespace` field is the conventional name to place an interface inside of a namespace. The ShapeInference interface in Toy chapters 4-7 now specifies its cppNamespace, rather than an include into a namespace. The tutorial docs are updated accordingly.
---
 mlir/docs/Tutorials/Toy/Ch-4.md                             | 5 ++++-
 mlir/examples/toy/Ch4/include/toy/ShapeInferenceInterface.h | 6 ------
 .../examples/toy/Ch4/include/toy/ShapeInferenceInterface.td | 2 ++
 mlir/examples/toy/Ch5/include/toy/ShapeInferenceInterface.h | 6 ------
 .../examples/toy/Ch5/include/toy/ShapeInferenceInterface.td | 2 ++
 mlir/examples/toy/Ch6/include/toy/ShapeInferenceInterface.h | 6 ------
 .../examples/toy/Ch6/include/toy/ShapeInferenceInterface.td | 2 ++
 mlir/examples/toy/Ch7/include/toy/ShapeInferenceInterface.h | 6 ------
 .../examples/toy/Ch7/include/toy/ShapeInferenceInterface.td | 2 ++
 9 files changed, 12 insertions(+), 25 deletions(-)

diff --git a/mlir/docs/Tutorials/Toy/Ch-4.md b/mlir/docs/Tutorials/Toy/Ch-4.md
index 083a661a968b2d..7eadbc17e070a9 100644
--- a/mlir/docs/Tutorials/Toy/Ch-4.md
+++ b/mlir/docs/Tutorials/Toy/Ch-4.md
@@ -351,7 +351,8 @@ the operation definition specification (ODS) framework.
 The interface is defined by inheriting from `OpInterface`, which takes the name
 to be given to the generated C++ interface class as a template argument. For our
 purposes, we will simply name the generated class `ShapeInference`. We also
-provide a description for the interface.
+provide a description for the interface and the C++ namespace that the
+interface class should be generated in.
 
 ```tablegen
 def ShapeInferenceOpInterface : OpInterface<"ShapeInference"> {
@@ -359,6 +360,8 @@ def ShapeInferenceOpInterface : OpInterface<"ShapeInference"> {
     Interface to access a registered method to infer the return types for an
     operation that can be used during type inference.
   }];
+
+  let cppNamespace = "::mlir::toy";
 }
 ```
 
diff --git a/mlir/examples/toy/Ch4/include/toy/ShapeInferenceInterface.h b/mlir/examples/toy/Ch4/include/toy/ShapeInferenceInterface.h
index cfe5a872e7d6e3..5194f7da96a355 100644
--- a/mlir/examples/toy/Ch4/include/toy/ShapeInferenceInterface.h
+++ b/mlir/examples/toy/Ch4/include/toy/ShapeInferenceInterface.h
@@ -16,13 +16,7 @@
 
 #include "mlir/IR/OpDefinition.h"
 
-namespace mlir {
-namespace toy {
-
 /// Include the auto-generated declarations.
 #include "toy/ShapeInferenceOpInterfaces.h.inc"
 
-} // namespace toy
-} // namespace mlir
-
 #endif // MLIR_TUTORIAL_TOY_SHAPEINFERENCEINTERFACE_H_
diff --git a/mlir/examples/toy/Ch4/include/toy/ShapeInferenceInterface.td b/mlir/examples/toy/Ch4/include/toy/ShapeInferenceInterface.td
index 22790159ed5c62..11261e2ebcf97c 100644
--- a/mlir/examples/toy/Ch4/include/toy/ShapeInferenceInterface.td
+++ b/mlir/examples/toy/Ch4/include/toy/ShapeInferenceInterface.td
@@ -21,6 +21,8 @@ def ShapeInferenceOpInterface : OpInterface<"ShapeInference"> {
     operation that can be used during type inference.
   }];
 
+  let cppNamespace = "::mlir::toy";
+
   let methods = [
     InterfaceMethod<"Infer and set the output shape for the current operation.",
                     "void", "inferShapes">
diff --git a/mlir/examples/toy/Ch5/include/toy/ShapeInferenceInterface.h b/mlir/examples/toy/Ch5/include/toy/ShapeInferenceInterface.h
index cfe5a872e7d6e3..5194f7da96a355 100644
--- a/mlir/examples/toy/Ch5/include/toy/ShapeInferenceInterface.h
+++ b/mlir/examples/toy/Ch5/include/toy/ShapeInferenceInterface.h
@@ -16,13 +16,7 @@
 
 #include "mlir/IR/OpDefinition.h"
 
-namespace mlir {
-namespace toy {
-
 /// Include the auto-generated declarations.
 #include "toy/ShapeInferenceOpInterfaces.h.inc"
 
-} // namespace toy
-} // namespace mlir
-
 #endif // MLIR_TUTORIAL_TOY_SHAPEINFERENCEINTERFACE_H_
diff --git a/mlir/examples/toy/Ch5/include/toy/ShapeInferenceInterface.td b/mlir/examples/toy/Ch5/include/toy/ShapeInferenceInterface.td
index 22790159ed5c62..11261e2ebcf97c 100644
--- a/mlir/examples/toy/Ch5/include/toy/ShapeInferenceInterface.td
+++ b/mlir/examples/toy/Ch5/include/toy/ShapeInferenceInterface.td
@@ -21,6 +21,8 @@ def ShapeInferenceOpInterface : OpInterface<"ShapeInference"> {
     operation that can be used during type inference.
   }];
 
+  let cppNamespace = "::mlir::toy";
+
   let methods = [
     InterfaceMethod<"Infer and set the output shape for the current operation.",
                     "void", "inferShapes">
diff --git a/mlir/examples/toy/Ch6/include/toy/ShapeInferenceInterface.h b/mlir/examples/toy/Ch6/include/toy/ShapeInferenceInterface.h
index cfe5a872e7d6e3..5194f7da96a355 100644
--- a/mlir/examples/toy/Ch6/include/toy/ShapeInferenceInterface.h
+++ b/mlir/examples/toy/Ch6/include/toy/ShapeInferenceInterface.h
@@ -16,13 +16,7 @@
 
 #include "mlir/IR/OpDefinition.h"
 
-namespace mlir {
-namespace toy {
-
 /// Include the auto-generated declarations.
 #include "toy/ShapeInferenceOpInterfaces.h.inc"
 
-} // namespace toy
-} // namespace mlir
-
 #endif // MLIR_TUTORIAL_TOY_SHAPEINFERENCEINTERFACE_H_
diff --git a/mlir/examples/toy/Ch6/include/toy/ShapeInferenceInterface.td b/mlir/examples/toy/Ch6/include/toy/ShapeInferenceInterface.td
index 22790159ed5c62..11261e2ebcf97c 100644
--- a/mlir/examples/toy/Ch6/include/toy/ShapeInferenceInterface.td
+++ b/mlir/examples/toy/Ch6/include/toy/ShapeInferenceInterface.td
@@ -21,6 +21,8 @@ def ShapeInferenceOpInterface : OpInterface<"ShapeInference"> {
     operation that can be used during type inference.
   }];
 
+  let cppNamespace = "::mlir::toy";
+
   let methods = [
     InterfaceMethod<"Infer and set the output shape for the current operation.",
                     "void", "inferShapes">
diff --git a/mlir/examples/toy/Ch7/include/toy/ShapeInferenceInterface.h b/mlir/examples/toy/Ch7/include/toy/ShapeInferenceInterface.h
index cfe5a872e7d6e3..5194f7da96a355 100644
--- a/mlir/examples/toy/Ch7/include/toy/ShapeInferenceInterface.h
+++ b/mlir/examples/toy/Ch7/include/toy/ShapeInferenceInterface.h
@@ -16,13 +16,7 @@
 
 #include "mlir/IR/OpDefinition.h"
 
-namespace mlir {
-namespace toy {
-
 /// Include the auto-generated declarations.
 #include "toy/ShapeInferenceOpInterfaces.h.inc"
 
-} // namespace toy
-} // namespace mlir
-
 #endif // MLIR_TUTORIAL_TOY_SHAPEINFERENCEINTERFACE_H_
diff --git a/mlir/examples/toy/Ch7/include/toy/ShapeInferenceInterface.td b/mlir/examples/toy/Ch7/include/toy/ShapeInferenceInterface.td
index 22790159ed5c62..11261e2ebcf97c 100644
--- a/mlir/examples/toy/Ch7/include/toy/ShapeInferenceInterface.td
+++ b/mlir/examples/toy/Ch7/include/toy/ShapeInferenceInterface.td
@@ -21,6 +21,8 @@ def ShapeInferenceOpInterface : OpInterface<"ShapeInference"> {
     operation that can be used during type inference.
   }];
 
+  let cppNamespace = "::mlir::toy";
+
   let methods = [
     InterfaceMethod<"Infer and set the output shape for the current operation.",
                     "void", "inferShapes">



More information about the Mlir-commits mailing list