[Mlir-commits] [mlir] [mlir][python][NFC] Make pybind references consistent with current bindings (PR #175528)
Vitalii Shutov
llvmlistbot at llvm.org
Fri Jan 23 10:35:34 PST 2026
https://github.com/Lallapallooza updated https://github.com/llvm/llvm-project/pull/175528
>From 3da7c4046f270affe394290ddb1000a2a89f75ee Mon Sep 17 00:00:00 2001
From: Vitalii Shutov <vitalii.shutov at arm.com>
Date: Mon, 12 Jan 2026 10:45:11 +0000
Subject: [PATCH 1/4] [mlir][python][NFC] Make pybind references consistent
with current bindings
Clean up stale "pybind/pybind11" references in MLIR Python bindings docs,
build configuration text, and source comments to match the current binding
layer (nanobind) without changing behavior.
Change-Id: I27919d9eab7b8b1ba945f7788ed9207450538307
---
mlir/CMakeLists.txt | 6 +++---
mlir/cmake/modules/MLIRDetectPythonEnv.cmake | 2 +-
mlir/docs/Bindings/Python.md | 15 +++++++--------
.../python/StandaloneExtensionNanobind.cpp | 3 +--
mlir/include/mlir-c/Bindings/Python/Interop.h | 6 ++----
.../mlir/Bindings/Python/NanobindAdaptors.h | 7 +++----
mlir/include/mlir/Bindings/Python/NanobindUtils.h | 6 +++---
mlir/lib/Bindings/Python/AsyncPasses.cpp | 2 +-
mlir/lib/Bindings/Python/DialectAMDGPU.cpp | 2 +-
mlir/lib/Bindings/Python/DialectGPU.cpp | 2 +-
mlir/lib/Bindings/Python/DialectIRDL.cpp | 2 +-
mlir/lib/Bindings/Python/DialectLLVM.cpp | 2 +-
mlir/lib/Bindings/Python/DialectLinalg.cpp | 2 +-
mlir/lib/Bindings/Python/DialectNVGPU.cpp | 2 +-
mlir/lib/Bindings/Python/DialectSMT.cpp | 2 +-
mlir/lib/Bindings/Python/GPUPasses.cpp | 2 +-
mlir/lib/Bindings/Python/Globals.cpp | 2 +-
mlir/lib/Bindings/Python/IRAffine.cpp | 2 +-
mlir/lib/Bindings/Python/IRCore.cpp | 6 +++---
mlir/lib/Bindings/Python/IRInterfaces.cpp | 2 +-
mlir/lib/Bindings/Python/LinalgPasses.cpp | 2 +-
mlir/lib/Bindings/Python/MainModule.cpp | 5 +++--
mlir/lib/Bindings/Python/Pass.cpp | 2 +-
mlir/lib/Bindings/Python/Pass.h | 2 +-
mlir/lib/Bindings/Python/Rewrite.cpp | 2 +-
mlir/lib/Bindings/Python/Rewrite.h | 2 +-
mlir/lib/Bindings/Python/SparseTensorPasses.cpp | 2 +-
mlir/lib/Bindings/Python/TransformInterpreter.cpp | 2 +-
mlir/python/mlir/_mlir_libs/__init__.py | 2 +-
mlir/python/mlir/dialects/func.py | 2 +-
mlir/python/mlir/dialects/linalg/__init__.py | 2 +-
mlir/test/python/dialects/python_test.py | 9 ++++++---
mlir/test/python/multithreaded_tests.py | 2 +-
33 files changed, 55 insertions(+), 56 deletions(-)
diff --git a/mlir/CMakeLists.txt b/mlir/CMakeLists.txt
index 9e1e9314511e3..2d3dcc2178d76 100644
--- a/mlir/CMakeLists.txt
+++ b/mlir/CMakeLists.txt
@@ -185,9 +185,9 @@ configure_file(
#-------------------------------------------------------------------------------
# Python Bindings Configuration
# Requires:
-# The pybind11 library can be found (set with -DPYBIND_DIR=...)
+# The nanobind library can be found (set with -Dnanobind_DIR=...)
# The python executable is correct (set with -DPython3_EXECUTABLE=...)
-# By default, find_package and probing for installed pybind11 is performed.
+# By default, find_package and probing for installed nanobind is performed.
# Super projects can set MLIR_DISABLE_CONFIGURE_PYTHON_DEV_PACKAGES=ON to
# disable all package setup and control it themselves.
#-------------------------------------------------------------------------------
@@ -210,7 +210,7 @@ set(MLIR_DISABLE_CONFIGURE_PYTHON_DEV_PACKAGES 0 CACHE BOOL
"Performs python dev package configuration sufficient to use all MLIR \
python features. Super-projects that wish to control their own setup \
must perform an appropriate find_package of Python3 with \
- 'Development.Module' and ensure that find_package(pybind11) is \
+ 'Development.Module' and ensure that find_package(nanobind) is \
satisfied (and keep up to date as requirements evolve).")
set(_mlir_python_stubgen_enabled ON)
diff --git a/mlir/cmake/modules/MLIRDetectPythonEnv.cmake b/mlir/cmake/modules/MLIRDetectPythonEnv.cmake
index 01dd7437cc8fc..5b29303de40c1 100644
--- a/mlir/cmake/modules/MLIRDetectPythonEnv.cmake
+++ b/mlir/cmake/modules/MLIRDetectPythonEnv.cmake
@@ -17,7 +17,7 @@ macro(mlir_configure_python_dev_packages)
# Development.Module. Searching for Development will fail in situations where
# the Python libraries are not available. When possible, limit to just
# Development.Module.
- # See https://pybind11.readthedocs.io/en/stable/compiling.html#findpython-mode
+ # See CMake FindPython/FindPython3 documentation for details.
set(_python_development_component Development.Module)
find_package(Python3 ${MLIR_MINIMUM_PYTHON_VERSION}
diff --git a/mlir/docs/Bindings/Python.md b/mlir/docs/Bindings/Python.md
index f75febd1a06e0..e64ee60fc7ae3 100644
--- a/mlir/docs/Bindings/Python.md
+++ b/mlir/docs/Bindings/Python.md
@@ -139,7 +139,8 @@ There are a lot of co-related issues of shared library linkage, distribution
concerns, etc that affect such things. Organizing the code into composable
modules (versus a monolithic `cpp` file) allows the flexibility to address many
of these as needed over time. Also, compilation time for all of the template
-meta-programming in pybind scales with the number of things you define in a
+meta-programming in the binding layer scales with the number of things you
+define in a
translation unit. Breaking into multiple translation units can significantly aid
compile times for APIs with a large surface area.
@@ -190,8 +191,8 @@ The Python APIs should seek to layer on top of the C-API to the degree possible.
Especially for the core, dialect-independent parts, such a binding enables
packaging decisions that would be difficult or impossible if spanning a C++ ABI
boundary. In addition, factoring in this way side-steps some very difficult
-issues that arise when combining RTTI-based modules (which pybind derived things
-are) with non-RTTI polymorphic C++ code (the default compilation mode of LLVM).
+issues that arise when combining RTTI-based extension modules with non-RTTI
+polymorphic C++ code (the default compilation mode of LLVM).
### Ownership in the Core IR
@@ -1260,11 +1261,11 @@ are available when the dialect is loaded from Python.
Dialect-specific passes can be made available to the pass manager in Python by
registering them with the context and relying on the API for pass pipeline
parsing from string descriptions. This can be achieved by creating a new
-nanobind module, defined in `lib/Bindings/Python/<Dialect>Passes.cpp`, that
+Python extension module, defined in `lib/Bindings/Python/<Dialect>Passes.cpp`, that
calls the registration C API, which must be provided first. For passes defined
declaratively using Tablegen, `mlir-tblgen -gen-pass-capi-header` and
`-mlir-tblgen -gen-pass-capi-impl` automate the generation of C API. The
-nanobind module must be compiled into a separate “Python extension” library,
+extension module must be compiled into a separate “Python extension” library,
which can be `import`ed from the main dialect file, i.e.
`python/mlir/dialects/<dialect-namespace>.py` or
`python/mlir/dialects/<dialect-namespace>/__init__.py`, or from a separate
@@ -1276,9 +1277,7 @@ make the passes available along with the dialect.
Dialect functionality other than IR objects or passes, such as helper functions,
can be exposed to Python similarly to attributes and types. C API is expected to
-exist for this functionality, which can then be wrapped using pybind11 and
-[`include/mlir/Bindings/Python/PybindAdaptors.h`](https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Bindings/Python/PybindAdaptors.h),
-or nanobind and
+exist for this functionality, which can then be wrapped using nanobind and
[`include/mlir/Bindings/Python/NanobindAdaptors.h`](https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h)
utilities to connect to the rest of Python API. The bindings can be located in a
separate module or in the same module as attributes and types, and
diff --git a/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp b/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
index 78c96e8059a8a..f2cd247eda041 100644
--- a/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
+++ b/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
@@ -1,7 +1,6 @@
//===- StandaloneExtension.cpp - Extension module -------------------------===//
//
-// This is the nanobind version of the example module. There is also a pybind11
-// example in StandaloneExtensionPybind11.cpp.
+// This is the nanobind version of the example module.
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/include/mlir-c/Bindings/Python/Interop.h b/mlir/include/mlir-c/Bindings/Python/Interop.h
index a33190c380d37..09c4e26a0c546 100644
--- a/mlir/include/mlir-c/Bindings/Python/Interop.h
+++ b/mlir/include/mlir-c/Bindings/Python/Interop.h
@@ -25,10 +25,8 @@
// definitions for what we need below, however, importing Python.h directly on
// Windows results in the enforcement of either pythonX.lib or pythonX_d.lib
// depending on the build flavor. Instead, we rely on the fact that this file
-// (Interop.h) is always included AFTER pybind11 and will therefore have access
-// to the definitions from Python.h in addition to having a workaround applied
-// through the pybind11 headers that allows us to control which python library
-// is used.
+// (Interop.h) is always included AFTER the binding headers, which have already
+// imported Python.h and applied any needed platform workarounds.
#if !defined(_MSC_VER)
#include <Python.h>
#endif
diff --git a/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h b/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h
index 6594670abaaa7..b5e30b99ee8c2 100644
--- a/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h
+++ b/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h
@@ -13,7 +13,7 @@
//
// It is encouraged to be used both in-tree and out-of-tree. For in-tree use
// cases, it should be used for dialect implementations (versus relying on
-// Pybind-based internals of the core libraries).
+// internals of the core libraries).
//===----------------------------------------------------------------------===//
#ifndef MLIR_BINDINGS_PYTHON_NANOBINDADAPTORS_H
@@ -28,7 +28,7 @@
#include "mlir-c/IR.h"
// clang-format off
#include "mlir/Bindings/Python/Nanobind.h"
-#include "mlir-c/Bindings/Python/Interop.h" // This is expected after nanobind.
+#include "mlir-c/Bindings/Python/Interop.h" // Expected after binding headers.
// clang-format on
#include "llvm/ADT/Twine.h"
@@ -663,8 +663,7 @@ class mlir_type_subclass : public pure_subclass {
// 'get_static_typeid' method.
// This is modeled as a static method instead of a static property because
// `def_property_readonly_static` is not available in `pure_subclass` and
- // we do not want to introduce the complexity that pybind uses to
- // implement it.
+ // we do not want to introduce additional complexity to implement it.
def_staticmethod(
"get_static_typeid",
[getTypeIDFunction]() { return getTypeIDFunction(); },
diff --git a/mlir/include/mlir/Bindings/Python/NanobindUtils.h b/mlir/include/mlir/Bindings/Python/NanobindUtils.h
index aea195fecae82..5bb89b87af0e8 100644
--- a/mlir/include/mlir/Bindings/Python/NanobindUtils.h
+++ b/mlir/include/mlir/Bindings/Python/NanobindUtils.h
@@ -7,8 +7,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef MLIR_BINDINGS_PYTHON_PYBINDUTILS_H
-#define MLIR_BINDINGS_PYTHON_PYBINDUTILS_H
+#ifndef MLIR_BINDINGS_PYTHON_NANOBINDUTILS_H
+#define MLIR_BINDINGS_PYTHON_NANOBINDUTILS_H
#include "mlir-c/Support.h"
#include "mlir/Bindings/Python/Nanobind.h"
@@ -433,4 +433,4 @@ struct DenseMapInfo<MlirTypeID> {
};
} // namespace llvm
-#endif // MLIR_BINDINGS_PYTHON_PYBINDUTILS_H
+#endif // MLIR_BINDINGS_PYTHON_NANOBINDUTILS_H
diff --git a/mlir/lib/Bindings/Python/AsyncPasses.cpp b/mlir/lib/Bindings/Python/AsyncPasses.cpp
index cfb8dcaaa72ae..9b7b7e1fdfc24 100644
--- a/mlir/lib/Bindings/Python/AsyncPasses.cpp
+++ b/mlir/lib/Bindings/Python/AsyncPasses.cpp
@@ -1,4 +1,4 @@
-//===- AsyncPasses.cpp - Pybind module for the Async passes -------------===//
+//===- AsyncPasses.cpp - Python extension module for Async passes ---------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/DialectAMDGPU.cpp b/mlir/lib/Bindings/Python/DialectAMDGPU.cpp
index e5a969fffe940..14cd42e32205d 100644
--- a/mlir/lib/Bindings/Python/DialectAMDGPU.cpp
+++ b/mlir/lib/Bindings/Python/DialectAMDGPU.cpp
@@ -1,4 +1,4 @@
-//===--- DialectAMDGPU.cpp - Pybind module for AMDGPU dialect API support -===//
+//===--- DialectAMDGPU.cpp - Python extension module for AMDGPU API support -===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/DialectGPU.cpp b/mlir/lib/Bindings/Python/DialectGPU.cpp
index 067abda53d0a8..a7d0220a2e763 100644
--- a/mlir/lib/Bindings/Python/DialectGPU.cpp
+++ b/mlir/lib/Bindings/Python/DialectGPU.cpp
@@ -1,4 +1,4 @@
-//===- DialectGPU.cpp - Pybind module for the GPU passes ------------------===//
+//===- DialectGPU.cpp - Python extension module for the GPU passes --------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/DialectIRDL.cpp b/mlir/lib/Bindings/Python/DialectIRDL.cpp
index 85567d9986e3a..fdfa98125ae00 100644
--- a/mlir/lib/Bindings/Python/DialectIRDL.cpp
+++ b/mlir/lib/Bindings/Python/DialectIRDL.cpp
@@ -1,4 +1,4 @@
-//===--- DialectIRDL.cpp - Pybind module for IRDL dialect API support ---===//
+//===--- DialectIRDL.cpp - Python extension module for IRDL API support ---===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/DialectLLVM.cpp b/mlir/lib/Bindings/Python/DialectLLVM.cpp
index 0c579cf261eca..41041ef06d003 100644
--- a/mlir/lib/Bindings/Python/DialectLLVM.cpp
+++ b/mlir/lib/Bindings/Python/DialectLLVM.cpp
@@ -1,4 +1,4 @@
-//===- DialectLLVM.cpp - Pybind module for LLVM dialect API support -------===//
+//===- DialectLLVM.cpp - Python extension module for LLVM API support -----===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/DialectLinalg.cpp b/mlir/lib/Bindings/Python/DialectLinalg.cpp
index 299961e100786..27ad7236aa15b 100644
--- a/mlir/lib/Bindings/Python/DialectLinalg.cpp
+++ b/mlir/lib/Bindings/Python/DialectLinalg.cpp
@@ -1,4 +1,4 @@
-//===- DialectLinalg.cpp - Nanobind module for Linalg dialect API support -===//
+//===- DialectLinalg.cpp - Python extension module for Linalg API support -===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/DialectNVGPU.cpp b/mlir/lib/Bindings/Python/DialectNVGPU.cpp
index 66c3fcd6387c8..3bc86e420efbf 100644
--- a/mlir/lib/Bindings/Python/DialectNVGPU.cpp
+++ b/mlir/lib/Bindings/Python/DialectNVGPU.cpp
@@ -1,4 +1,4 @@
-//===--- DialectNVGPU.cpp - Pybind module for NVGPU dialect API support ---===//
+//===--- DialectNVGPU.cpp - Python extension module for NVGPU API support --===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/DialectSMT.cpp b/mlir/lib/Bindings/Python/DialectSMT.cpp
index eff10a0e55c05..f18e72b648ed6 100644
--- a/mlir/lib/Bindings/Python/DialectSMT.cpp
+++ b/mlir/lib/Bindings/Python/DialectSMT.cpp
@@ -1,4 +1,4 @@
-//===- DialectSMT.cpp - Pybind module for SMT dialect API support ---------===//
+//===- DialectSMT.cpp - Python extension module for SMT API support -------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/GPUPasses.cpp b/mlir/lib/Bindings/Python/GPUPasses.cpp
index be474edbe9639..c615e09b56eb0 100644
--- a/mlir/lib/Bindings/Python/GPUPasses.cpp
+++ b/mlir/lib/Bindings/Python/GPUPasses.cpp
@@ -1,4 +1,4 @@
-//===- GPUPasses.cpp - Pybind module for the GPU passes ------------------===//
+//===- GPUPasses.cpp - Python extension module for the GPU passes ---------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/Globals.cpp b/mlir/lib/Bindings/Python/Globals.cpp
index e2e8693ba45f3..897c54b235e5d 100644
--- a/mlir/lib/Bindings/Python/Globals.cpp
+++ b/mlir/lib/Bindings/Python/Globals.cpp
@@ -1,4 +1,4 @@
-//===- IRModule.cpp - IR pybind module ------------------------------------===//
+//===- Globals.cpp - Globals for MLIR Python bindings ----------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/IRAffine.cpp b/mlir/lib/Bindings/Python/IRAffine.cpp
index 3c2da03181e6a..a211cd584c018 100644
--- a/mlir/lib/Bindings/Python/IRAffine.cpp
+++ b/mlir/lib/Bindings/Python/IRAffine.cpp
@@ -18,7 +18,7 @@
#include "mlir/Bindings/Python/IRCore.h"
// clang-format off
#include "mlir/Bindings/Python/NanobindUtils.h"
-#include "mlir-c/Bindings/Python/Interop.h" // This is expected after nanobind.
+#include "mlir-c/Bindings/Python/Interop.h" // Expected after binding headers.
// clang-format on
#include "mlir-c/IntegerSet.h"
#include "mlir/Bindings/Python/Nanobind.h"
diff --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp
index f04f0b6271630..daf9806efd8b6 100644
--- a/mlir/lib/Bindings/Python/IRCore.cpp
+++ b/mlir/lib/Bindings/Python/IRCore.cpp
@@ -1,4 +1,4 @@
-//===- IRModules.cpp - IR Submodules of pybind module ---------------------===//
+//===- IRCore.cpp - IR submodules of MLIR Python bindings -----------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -10,7 +10,7 @@
#include "mlir/Bindings/Python/Globals.h"
#include "mlir/Bindings/Python/IRCore.h"
#include "mlir/Bindings/Python/NanobindUtils.h"
-#include "mlir-c/Bindings/Python/Interop.h" // This is expected after nanobind.
+#include "mlir-c/Bindings/Python/Interop.h" // Expected after binding headers.
// clang-format on
#include "mlir-c/BuiltinAttributes.h"
#include "mlir-c/Debug.h"
@@ -529,7 +529,7 @@ nb::object PyMlirContext::attachDiagnosticHandler(nb::object callback) {
(void)pyHandlerObject.inc_ref();
// In these C callbacks, the userData is a PyDiagnosticHandler* that is
- // guaranteed to be known to pybind.
+ // guaranteed to be known to the binding layer.
auto handlerCallback =
+[](MlirDiagnostic diagnostic, void *userData) -> MlirLogicalResult {
PyDiagnostic *pyDiagnostic = new PyDiagnostic(diagnostic);
diff --git a/mlir/lib/Bindings/Python/IRInterfaces.cpp b/mlir/lib/Bindings/Python/IRInterfaces.cpp
index 09112d4989ae4..92ec5bc359e95 100644
--- a/mlir/lib/Bindings/Python/IRInterfaces.cpp
+++ b/mlir/lib/Bindings/Python/IRInterfaces.cpp
@@ -1,4 +1,4 @@
-//===- IRInterfaces.cpp - MLIR IR interfaces pybind -----------------------===//
+//===- IRInterfaces.cpp - MLIR IR interfaces bindings ----------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/LinalgPasses.cpp b/mlir/lib/Bindings/Python/LinalgPasses.cpp
index 49f2ea94151a0..f443447c42834 100644
--- a/mlir/lib/Bindings/Python/LinalgPasses.cpp
+++ b/mlir/lib/Bindings/Python/LinalgPasses.cpp
@@ -1,4 +1,4 @@
-//===- LinalgPasses.cpp - Pybind module for the Linalg passes -------------===//
+//===- LinalgPasses.cpp - Python extension module for the Linalg passes ---===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/MainModule.cpp b/mlir/lib/Bindings/Python/MainModule.cpp
index 88f58d45cdd75..e5964e5c49a4e 100644
--- a/mlir/lib/Bindings/Python/MainModule.cpp
+++ b/mlir/lib/Bindings/Python/MainModule.cpp
@@ -1,4 +1,4 @@
-//===- MainModule.cpp - Main pybind module --------------------------------===//
+//===- MainModule.cpp - Main Python extension module ----------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -56,7 +56,8 @@ NB_MODULE(_mlir, m) {
populatePassManagerSubmodule(passManagerModule);
nanobind::register_exception_translator(
[](const std::exception_ptr &p, void *payload) {
- // We can't define exceptions with custom fields through pybind, so
+ // We can't define exceptions with custom fields through the binding
+ // library, so
// instead the exception class is defined in python and imported here.
try {
if (p)
diff --git a/mlir/lib/Bindings/Python/Pass.cpp b/mlir/lib/Bindings/Python/Pass.cpp
index 6cf5066b244eb..82d906c4b4a72 100644
--- a/mlir/lib/Bindings/Python/Pass.cpp
+++ b/mlir/lib/Bindings/Python/Pass.cpp
@@ -13,7 +13,7 @@
#include "mlir/Bindings/Python/IRCore.h"
// clang-format off
#include "mlir/Bindings/Python/Nanobind.h"
-#include "mlir-c/Bindings/Python/Interop.h" // This is expected after nanobind.
+#include "mlir-c/Bindings/Python/Interop.h" // Expected after binding headers.
// clang-format on
namespace nb = nanobind;
diff --git a/mlir/lib/Bindings/Python/Pass.h b/mlir/lib/Bindings/Python/Pass.h
index 1a311666ebecd..c95e0c97bcc8d 100644
--- a/mlir/lib/Bindings/Python/Pass.h
+++ b/mlir/lib/Bindings/Python/Pass.h
@@ -1,4 +1,4 @@
-//===- Pass.h - PassManager Submodules of pybind module -------------------===//
+//===- Pass.h - PassManager submodule declarations ------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/Rewrite.cpp b/mlir/lib/Bindings/Python/Rewrite.cpp
index 2b649f79c5982..feeff4ad06686 100644
--- a/mlir/lib/Bindings/Python/Rewrite.cpp
+++ b/mlir/lib/Bindings/Python/Rewrite.cpp
@@ -14,7 +14,7 @@
#include "mlir/Bindings/Python/IRCore.h"
// clang-format off
#include "mlir/Bindings/Python/Nanobind.h"
-#include "mlir-c/Bindings/Python/Interop.h" // This is expected after nanobind.
+#include "mlir-c/Bindings/Python/Interop.h" // Expected after binding headers.
// clang-format on
#include "mlir/Config/mlir-config.h"
#include "nanobind/nanobind.h"
diff --git a/mlir/lib/Bindings/Python/Rewrite.h b/mlir/lib/Bindings/Python/Rewrite.h
index d287f19187708..96127ad60b833 100644
--- a/mlir/lib/Bindings/Python/Rewrite.h
+++ b/mlir/lib/Bindings/Python/Rewrite.h
@@ -1,4 +1,4 @@
-//===- Rewrite.h - Rewrite Submodules of pybind module --------------------===//
+//===- Rewrite.h - Rewrite submodule declarations -------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/SparseTensorPasses.cpp b/mlir/lib/Bindings/Python/SparseTensorPasses.cpp
index 8242f0973a446..630bb994db72a 100644
--- a/mlir/lib/Bindings/Python/SparseTensorPasses.cpp
+++ b/mlir/lib/Bindings/Python/SparseTensorPasses.cpp
@@ -1,4 +1,4 @@
-//===- SparseTensorPasses.cpp - Pybind module for the SparseTensor passes -===//
+//===- SparseTensorPasses.cpp - Python extension module for SparseTensor passes -===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/TransformInterpreter.cpp b/mlir/lib/Bindings/Python/TransformInterpreter.cpp
index a9f204ff9d0a5..1878a7cd9fe8d 100644
--- a/mlir/lib/Bindings/Python/TransformInterpreter.cpp
+++ b/mlir/lib/Bindings/Python/TransformInterpreter.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
//
-// Pybind classes for the transform dialect interpreter.
+// Python bindings classes for the transform dialect interpreter.
//
//===----------------------------------------------------------------------===//
diff --git a/mlir/python/mlir/_mlir_libs/__init__.py b/mlir/python/mlir/_mlir_libs/__init__.py
index c0e8775149d41..55ae10ade1705 100644
--- a/mlir/python/mlir/_mlir_libs/__init__.py
+++ b/mlir/python/mlir/_mlir_libs/__init__.py
@@ -35,7 +35,7 @@ def get_include_dirs() -> Sequence[str]:
#
# Aside from just being far more convenient to do this at the Python level,
# it is actually quite hard/impossible to have such __init__ hooks, given
-# the pybind memory model (i.e. there is not a Python reference to the object
+# the native extension memory model (i.e. there is not a Python reference to the object
# in the scope of the base class __init__).
#
# For #1, we:
diff --git a/mlir/python/mlir/dialects/func.py b/mlir/python/mlir/dialects/func.py
index 1898fc1565cd4..0372c35a821b8 100644
--- a/mlir/python/mlir/dialects/func.py
+++ b/mlir/python/mlir/dialects/func.py
@@ -282,7 +282,7 @@ def __init__(
"""
# TODO: consider supporting constructor "overloads", e.g., through a custom
- # or pybind-provided metaclass.
+ # metaclass provided by the bindings.
if isinstance(calleeOrResults, FuncOp):
if not isinstance(argumentsOrCallee, list):
raise ValueError(
diff --git a/mlir/python/mlir/dialects/linalg/__init__.py b/mlir/python/mlir/dialects/linalg/__init__.py
index 0a97bc03f584b..bbdf6bb7bda8c 100644
--- a/mlir/python/mlir/dialects/linalg/__init__.py
+++ b/mlir/python/mlir/dialects/linalg/__init__.py
@@ -2,7 +2,7 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-# Re-export the objects provided by pybind.
+# Re-export the objects provided by the native extension.
from ..._mlir_libs._mlirDialectsLinalg import *
# These are the backing OpView classes generated from the linalg tablegen
diff --git a/mlir/test/python/dialects/python_test.py b/mlir/test/python/dialects/python_test.py
index 9c0966d2d8798..40b314f9c56b9 100644
--- a/mlir/test/python/dialects/python_test.py
+++ b/mlir/test/python/dialects/python_test.py
@@ -601,7 +601,8 @@ def testCustomAttribute():
else:
raise
- # The following must trigger a TypeError from pybind (therefore, not
+ # The following must trigger a TypeError from the binding library
+ # (therefore, not
# checking its message) and must not crash.
try:
TestAttr(42, 56)
@@ -651,7 +652,8 @@ def testCustomType():
else:
raise
- # The following must trigger a TypeError from pybind (therefore, not
+ # The following must trigger a TypeError from the binding library
+ # (therefore, not
# checking its message) and must not crash.
try:
TestType(42, 56)
@@ -785,7 +787,8 @@ def type_caster(pytype):
except RuntimeError as e:
print(e)
- # python_test dialect registers a caster for RankedTensorType in its extension (pybind) module.
+ # python_test dialect registers a caster for RankedTensorType in its
+ # extension module.
# So this one replaces that one (successfully). And then just to be sure we restore the original caster below.
@register_type_caster(c.typeid, replace=True)
def type_caster(pytype):
diff --git a/mlir/test/python/multithreaded_tests.py b/mlir/test/python/multithreaded_tests.py
index 6e1a668346872..65491de2cb94f 100644
--- a/mlir/test/python/multithreaded_tests.py
+++ b/mlir/test/python/multithreaded_tests.py
@@ -214,7 +214,7 @@ def run_construct_and_print_in_module(f):
("dialects/ods_helpers", run),
("dialects/openmp_ops", run_with_insertion_point_v2),
("dialects/pdl_ops", run_with_insertion_point_v2),
- # ("dialects/python_test", run), # TODO: Need to pass pybind11 or nanobind argv
+ # ("dialects/python_test", run), # TODO: Need to pass binding argv
("dialects/quant", run),
("dialects/rocdl", run_with_insertion_point_v2),
("dialects/scf", run_with_insertion_point_v2),
>From d78865e9c830c5ff37414ffed621b5770ed208d2 Mon Sep 17 00:00:00 2001
From: Vitalii Shutov <vitalii.shutov at arm.com>
Date: Mon, 12 Jan 2026 12:42:39 +0000
Subject: [PATCH 2/4] fix linter
Change-Id: If3c34daff350e8ed689a62f58043fd512947555c
---
mlir/lib/Bindings/Python/DialectAMDGPU.cpp | 2 +-
mlir/lib/Bindings/Python/DialectNVGPU.cpp | 2 +-
mlir/lib/Bindings/Python/Globals.cpp | 2 +-
mlir/lib/Bindings/Python/IRInterfaces.cpp | 2 +-
mlir/lib/Bindings/Python/SparseTensorPasses.cpp | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/mlir/lib/Bindings/Python/DialectAMDGPU.cpp b/mlir/lib/Bindings/Python/DialectAMDGPU.cpp
index 14cd42e32205d..6053996acc55d 100644
--- a/mlir/lib/Bindings/Python/DialectAMDGPU.cpp
+++ b/mlir/lib/Bindings/Python/DialectAMDGPU.cpp
@@ -1,4 +1,4 @@
-//===--- DialectAMDGPU.cpp - Python extension module for AMDGPU API support -===//
+//===--- DialectAMDGPU.cpp - AMDGPU Python bindings -----------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/DialectNVGPU.cpp b/mlir/lib/Bindings/Python/DialectNVGPU.cpp
index 3bc86e420efbf..fbefaea9ba9dd 100644
--- a/mlir/lib/Bindings/Python/DialectNVGPU.cpp
+++ b/mlir/lib/Bindings/Python/DialectNVGPU.cpp
@@ -1,4 +1,4 @@
-//===--- DialectNVGPU.cpp - Python extension module for NVGPU API support --===//
+//===--- DialectNVGPU.cpp - NVGPU Python bindings -------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/Globals.cpp b/mlir/lib/Bindings/Python/Globals.cpp
index 897c54b235e5d..dabd3df67cf4b 100644
--- a/mlir/lib/Bindings/Python/Globals.cpp
+++ b/mlir/lib/Bindings/Python/Globals.cpp
@@ -1,4 +1,4 @@
-//===- Globals.cpp - Globals for MLIR Python bindings ----------------------===//
+//===- Globals.cpp - Globals for MLIR Python bindings ---------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/IRInterfaces.cpp b/mlir/lib/Bindings/Python/IRInterfaces.cpp
index 92ec5bc359e95..b355415a9c0a6 100644
--- a/mlir/lib/Bindings/Python/IRInterfaces.cpp
+++ b/mlir/lib/Bindings/Python/IRInterfaces.cpp
@@ -1,4 +1,4 @@
-//===- IRInterfaces.cpp - MLIR IR interfaces bindings ----------------------===//
+//===- IRInterfaces.cpp - MLIR IR interface bindings ----------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/SparseTensorPasses.cpp b/mlir/lib/Bindings/Python/SparseTensorPasses.cpp
index 630bb994db72a..dda29845d71ef 100644
--- a/mlir/lib/Bindings/Python/SparseTensorPasses.cpp
+++ b/mlir/lib/Bindings/Python/SparseTensorPasses.cpp
@@ -1,4 +1,4 @@
-//===- SparseTensorPasses.cpp - Python extension module for SparseTensor passes -===//
+//===- SparseTensorPasses.cpp - SparseTensor passes extension module ------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
>From ff7952bcbb001f9614df211237d698db3e7b4830 Mon Sep 17 00:00:00 2001
From: Vitalii Shutov <vitalii.shutov at arm.com>
Date: Thu, 22 Jan 2026 13:12:52 +0000
Subject: [PATCH 3/4] address comments
Change-Id: I65d270acf4889aa5415f48ab82e0dfa692457904
---
mlir/docs/Bindings/Python.md | 3 +--
.../python/StandaloneExtensionNanobind.cpp | 2 --
mlir/include/mlir-c/Bindings/Python/Interop.h | 2 +-
.../include/mlir/Bindings/Python/NanobindAdaptors.h | 8 ++------
mlir/lib/Bindings/Python/DialectAMDGPU.cpp | 2 +-
mlir/lib/Bindings/Python/DialectNVGPU.cpp | 2 +-
mlir/lib/Bindings/Python/IRAffine.cpp | 2 +-
mlir/lib/Bindings/Python/IRCore.cpp | 4 ++--
mlir/lib/Bindings/Python/MainModule.cpp | 3 +--
mlir/lib/Bindings/Python/Pass.cpp | 2 +-
mlir/lib/Bindings/Python/Rewrite.cpp | 2 +-
mlir/python/mlir/_mlir_libs/__init__.py | 4 ++--
mlir/python/mlir/dialects/func.py | 2 +-
mlir/python/mlir/dialects/linalg/__init__.py | 2 +-
mlir/test/python/dialects/python_test.py | 13 +++++--------
mlir/test/python/multithreaded_tests.py | 2 +-
16 files changed, 22 insertions(+), 33 deletions(-)
diff --git a/mlir/docs/Bindings/Python.md b/mlir/docs/Bindings/Python.md
index e64ee60fc7ae3..fa64f4a498796 100644
--- a/mlir/docs/Bindings/Python.md
+++ b/mlir/docs/Bindings/Python.md
@@ -140,8 +140,7 @@ concerns, etc that affect such things. Organizing the code into composable
modules (versus a monolithic `cpp` file) allows the flexibility to address many
of these as needed over time. Also, compilation time for all of the template
meta-programming in the binding layer scales with the number of things you
-define in a
-translation unit. Breaking into multiple translation units can significantly aid
+define in a translation unit. Breaking into multiple translation units can significantly aid
compile times for APIs with a large surface area.
### Submodules
diff --git a/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp b/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
index f2cd247eda041..7ed23292a1fd2 100644
--- a/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
+++ b/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
@@ -1,7 +1,5 @@
//===- StandaloneExtension.cpp - Extension module -------------------------===//
//
-// This is the nanobind version of the example module.
-//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
diff --git a/mlir/include/mlir-c/Bindings/Python/Interop.h b/mlir/include/mlir-c/Bindings/Python/Interop.h
index 09c4e26a0c546..fb0140b6f2588 100644
--- a/mlir/include/mlir-c/Bindings/Python/Interop.h
+++ b/mlir/include/mlir-c/Bindings/Python/Interop.h
@@ -25,7 +25,7 @@
// definitions for what we need below, however, importing Python.h directly on
// Windows results in the enforcement of either pythonX.lib or pythonX_d.lib
// depending on the build flavor. Instead, we rely on the fact that this file
-// (Interop.h) is always included AFTER the binding headers, which have already
+// (Interop.h) is always included AFTER the nanobind headers, which have already
// imported Python.h and applied any needed platform workarounds.
#if !defined(_MSC_VER)
#include <Python.h>
diff --git a/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h b/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h
index b5e30b99ee8c2..f09308870102a 100644
--- a/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h
+++ b/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h
@@ -10,10 +10,6 @@
// depend on implementation details of the MLIR Python API and do not introduce
// C++-level dependencies with it (requiring only Python and CAPI-level
// dependencies).
-//
-// It is encouraged to be used both in-tree and out-of-tree. For in-tree use
-// cases, it should be used for dialect implementations (versus relying on
-// internals of the core libraries).
//===----------------------------------------------------------------------===//
#ifndef MLIR_BINDINGS_PYTHON_NANOBINDADAPTORS_H
@@ -28,7 +24,7 @@
#include "mlir-c/IR.h"
// clang-format off
#include "mlir/Bindings/Python/Nanobind.h"
-#include "mlir-c/Bindings/Python/Interop.h" // Expected after binding headers.
+#include "mlir-c/Bindings/Python/Interop.h" // Expected after nanobind headers.
// clang-format on
#include "llvm/ADT/Twine.h"
@@ -663,7 +659,7 @@ class mlir_type_subclass : public pure_subclass {
// 'get_static_typeid' method.
// This is modeled as a static method instead of a static property because
// `def_property_readonly_static` is not available in `pure_subclass` and
- // we do not want to introduce additional complexity to implement it.
+ // we do not want to implement a custom descriptor to emulate it.
def_staticmethod(
"get_static_typeid",
[getTypeIDFunction]() { return getTypeIDFunction(); },
diff --git a/mlir/lib/Bindings/Python/DialectAMDGPU.cpp b/mlir/lib/Bindings/Python/DialectAMDGPU.cpp
index 6053996acc55d..81d29d5aba68b 100644
--- a/mlir/lib/Bindings/Python/DialectAMDGPU.cpp
+++ b/mlir/lib/Bindings/Python/DialectAMDGPU.cpp
@@ -1,4 +1,4 @@
-//===--- DialectAMDGPU.cpp - AMDGPU Python bindings -----------------------===//
+//===- DialectAMDGPU.cpp - Python extension module for AMDGPU API support -===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/DialectNVGPU.cpp b/mlir/lib/Bindings/Python/DialectNVGPU.cpp
index fbefaea9ba9dd..027dd1eea83cf 100644
--- a/mlir/lib/Bindings/Python/DialectNVGPU.cpp
+++ b/mlir/lib/Bindings/Python/DialectNVGPU.cpp
@@ -1,4 +1,4 @@
-//===--- DialectNVGPU.cpp - NVGPU Python bindings -------------------------===//
+//===--- DialectNVGPU.cpp - Python extension module for NVGPU API support -===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/lib/Bindings/Python/IRAffine.cpp b/mlir/lib/Bindings/Python/IRAffine.cpp
index 2c5f4e4e589ec..ba043e8642845 100644
--- a/mlir/lib/Bindings/Python/IRAffine.cpp
+++ b/mlir/lib/Bindings/Python/IRAffine.cpp
@@ -18,7 +18,7 @@
#include "mlir/Bindings/Python/IRCore.h"
// clang-format off
#include "mlir/Bindings/Python/NanobindUtils.h"
-#include "mlir-c/Bindings/Python/Interop.h" // Expected after binding headers.
+#include "mlir-c/Bindings/Python/Interop.h" // Expected after nanobind headers.
// clang-format on
#include "mlir-c/IntegerSet.h"
#include "mlir/Bindings/Python/Nanobind.h"
diff --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp
index ef82bdf33f30a..4a39e554556c5 100644
--- a/mlir/lib/Bindings/Python/IRCore.cpp
+++ b/mlir/lib/Bindings/Python/IRCore.cpp
@@ -11,7 +11,7 @@
#include "mlir/Bindings/Python/IRCore.h"
#include "mlir/Bindings/Python/NanobindUtils.h"
#include "mlir/Bindings/Python/NanobindAdaptors.h"
-#include "mlir-c/Bindings/Python/Interop.h" // This is expected after nanobind.
+#include "mlir-c/Bindings/Python/Interop.h" // Expected after nanobind headers.
// clang-format on
#include "mlir-c/BuiltinAttributes.h"
#include "mlir-c/Debug.h"
@@ -535,7 +535,7 @@ nb::object PyMlirContext::attachDiagnosticHandler(nb::object callback) {
(void)pyHandlerObject.inc_ref();
// In these C callbacks, the userData is a PyDiagnosticHandler* that is
- // guaranteed to be known to the binding layer.
+ // guaranteed to be known to the nanobind-based bindings.
auto handlerCallback =
+[](MlirDiagnostic diagnostic, void *userData) -> MlirLogicalResult {
PyDiagnostic *pyDiagnostic = new PyDiagnostic(diagnostic);
diff --git a/mlir/lib/Bindings/Python/MainModule.cpp b/mlir/lib/Bindings/Python/MainModule.cpp
index e5964e5c49a4e..62040f0ef9e80 100644
--- a/mlir/lib/Bindings/Python/MainModule.cpp
+++ b/mlir/lib/Bindings/Python/MainModule.cpp
@@ -56,8 +56,7 @@ NB_MODULE(_mlir, m) {
populatePassManagerSubmodule(passManagerModule);
nanobind::register_exception_translator(
[](const std::exception_ptr &p, void *payload) {
- // We can't define exceptions with custom fields through the binding
- // library, so
+ // We can't define exceptions with custom fields through nanobind, so
// instead the exception class is defined in python and imported here.
try {
if (p)
diff --git a/mlir/lib/Bindings/Python/Pass.cpp b/mlir/lib/Bindings/Python/Pass.cpp
index 82d906c4b4a72..87e185a2fb2f5 100644
--- a/mlir/lib/Bindings/Python/Pass.cpp
+++ b/mlir/lib/Bindings/Python/Pass.cpp
@@ -13,7 +13,7 @@
#include "mlir/Bindings/Python/IRCore.h"
// clang-format off
#include "mlir/Bindings/Python/Nanobind.h"
-#include "mlir-c/Bindings/Python/Interop.h" // Expected after binding headers.
+#include "mlir-c/Bindings/Python/Interop.h" // Expected after nanobind headers.
// clang-format on
namespace nb = nanobind;
diff --git a/mlir/lib/Bindings/Python/Rewrite.cpp b/mlir/lib/Bindings/Python/Rewrite.cpp
index feeff4ad06686..e71d44d930e11 100644
--- a/mlir/lib/Bindings/Python/Rewrite.cpp
+++ b/mlir/lib/Bindings/Python/Rewrite.cpp
@@ -14,7 +14,7 @@
#include "mlir/Bindings/Python/IRCore.h"
// clang-format off
#include "mlir/Bindings/Python/Nanobind.h"
-#include "mlir-c/Bindings/Python/Interop.h" // Expected after binding headers.
+#include "mlir-c/Bindings/Python/Interop.h" // Expected after nanobind headers.
// clang-format on
#include "mlir/Config/mlir-config.h"
#include "nanobind/nanobind.h"
diff --git a/mlir/python/mlir/_mlir_libs/__init__.py b/mlir/python/mlir/_mlir_libs/__init__.py
index 55ae10ade1705..14d16bc1b24d4 100644
--- a/mlir/python/mlir/_mlir_libs/__init__.py
+++ b/mlir/python/mlir/_mlir_libs/__init__.py
@@ -35,8 +35,8 @@ def get_include_dirs() -> Sequence[str]:
#
# Aside from just being far more convenient to do this at the Python level,
# it is actually quite hard/impossible to have such __init__ hooks, given
-# the native extension memory model (i.e. there is not a Python reference to the object
-# in the scope of the base class __init__).
+# the nanobind native extension memory model (i.e. there is not a Python
+# reference to the object in the scope of the base class __init__).
#
# For #1, we:
# a. Probe for modules named '_mlirRegisterEverything' and
diff --git a/mlir/python/mlir/dialects/func.py b/mlir/python/mlir/dialects/func.py
index 0372c35a821b8..aca96b86176f0 100644
--- a/mlir/python/mlir/dialects/func.py
+++ b/mlir/python/mlir/dialects/func.py
@@ -282,7 +282,7 @@ def __init__(
"""
# TODO: consider supporting constructor "overloads", e.g., through a custom
- # metaclass provided by the bindings.
+ # metaclass provided by the nanobind bindings.
if isinstance(calleeOrResults, FuncOp):
if not isinstance(argumentsOrCallee, list):
raise ValueError(
diff --git a/mlir/python/mlir/dialects/linalg/__init__.py b/mlir/python/mlir/dialects/linalg/__init__.py
index e39cc2246e2ee..8fc161d38f4a8 100644
--- a/mlir/python/mlir/dialects/linalg/__init__.py
+++ b/mlir/python/mlir/dialects/linalg/__init__.py
@@ -2,7 +2,7 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-# Re-export the objects provided by the native extension.
+# Re-export the objects provided by the nanobind native extension.
from ..._mlir_libs._mlirDialectsLinalg import *
# These are the backing OpView classes generated from the linalg tablegen
diff --git a/mlir/test/python/dialects/python_test.py b/mlir/test/python/dialects/python_test.py
index 523d634810736..247411bbf9332 100644
--- a/mlir/test/python/dialects/python_test.py
+++ b/mlir/test/python/dialects/python_test.py
@@ -601,9 +601,8 @@ def testCustomAttribute():
else:
raise
- # The following must trigger a TypeError from the binding library
- # (therefore, not
- # checking its message) and must not crash.
+ # The following must trigger a TypeError from the nanobind binding library
+ # (therefore, not checking its message) and must not crash.
try:
TestAttr(42, 56)
except TypeError:
@@ -652,9 +651,8 @@ def testCustomType():
else:
raise
- # The following must trigger a TypeError from the binding library
- # (therefore, not
- # checking its message) and must not crash.
+ # The following must trigger a TypeError from the nanobind binding library
+ # (therefore, not checking its message) and must not crash.
try:
TestType(42, 56)
except TypeError:
@@ -787,8 +785,7 @@ def type_caster(pytype):
except RuntimeError as e:
print(e)
- # python_test dialect registers a caster for RankedTensorType in its
- # extension module.
+ # python_test dialect registers a caster for RankedTensorType in its extension module.
# So this one replaces that one (successfully). And then just to be sure we restore the original caster below.
@register_type_caster(c.typeid, replace=True)
def type_caster(pytype):
diff --git a/mlir/test/python/multithreaded_tests.py b/mlir/test/python/multithreaded_tests.py
index 65491de2cb94f..06a8a9e569c92 100644
--- a/mlir/test/python/multithreaded_tests.py
+++ b/mlir/test/python/multithreaded_tests.py
@@ -214,7 +214,7 @@ def run_construct_and_print_in_module(f):
("dialects/ods_helpers", run),
("dialects/openmp_ops", run_with_insertion_point_v2),
("dialects/pdl_ops", run_with_insertion_point_v2),
- # ("dialects/python_test", run), # TODO: Need to pass binding argv
+ ("dialects/python_test", run),
("dialects/quant", run),
("dialects/rocdl", run_with_insertion_point_v2),
("dialects/scf", run_with_insertion_point_v2),
>From c960ed84ad11b40d8dd952f2d3ceedd13d9eb723 Mon Sep 17 00:00:00 2001
From: Vitalii Shutov <vitalii.shutov at arm.com>
Date: Fri, 23 Jan 2026 18:31:07 +0000
Subject: [PATCH 4/4] address comments
Change-Id: Ib601fe0819653e519fd2f856ac3fbf3c72b80d9d
---
mlir/docs/Bindings/Python.md | 4 ++--
mlir/include/mlir/Bindings/Python/NanobindAdaptors.h | 3 ++-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/mlir/docs/Bindings/Python.md b/mlir/docs/Bindings/Python.md
index fa64f4a498796..1a9fcfb055989 100644
--- a/mlir/docs/Bindings/Python.md
+++ b/mlir/docs/Bindings/Python.md
@@ -139,8 +139,8 @@ There are a lot of co-related issues of shared library linkage, distribution
concerns, etc that affect such things. Organizing the code into composable
modules (versus a monolithic `cpp` file) allows the flexibility to address many
of these as needed over time. Also, compilation time for all of the template
-meta-programming in the binding layer scales with the number of things you
-define in a translation unit. Breaking into multiple translation units can significantly aid
+meta-programming in nanobind scales with the number of things you define in a
+translation unit. Breaking into multiple translation units can significantly aid
compile times for APIs with a large surface area.
### Submodules
diff --git a/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h b/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h
index f09308870102a..5e5324e546046 100644
--- a/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h
+++ b/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h
@@ -659,7 +659,8 @@ class mlir_type_subclass : public pure_subclass {
// 'get_static_typeid' method.
// This is modeled as a static method instead of a static property because
// `def_property_readonly_static` is not available in `pure_subclass` and
- // we do not want to implement a custom descriptor to emulate it.
+ // we do not want to introduce the complexity that nanobind uses to
+ // implement it.
def_staticmethod(
"get_static_typeid",
[getTypeIDFunction]() { return getTypeIDFunction(); },
More information about the Mlir-commits
mailing list