[mlir] Apply py::module_local() to a few more classes.
authorSean Silva <silvasean@google.com>
Tue, 14 Sep 2021 21:55:54 +0000 (21:55 +0000)
committerSean Silva <silvasean@google.com>
Tue, 14 Sep 2021 21:56:14 +0000 (21:56 +0000)
Reviewed By: ftynse

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

mlir/lib/Bindings/Python/DialectSparseTensor.cpp
mlir/lib/Bindings/Python/IRModule.h
mlir/lib/Bindings/Python/PybindUtils.h

index faf240e..6afd081 100644 (file)
@@ -20,7 +20,7 @@ void mlir::python::populateDialectSparseTensorSubmodule(
     py::module m, const py::module &irModule) {
   auto attributeClass = irModule.attr("Attribute");
 
-  py::enum_<MlirSparseTensorDimLevelType>(m, "DimLevelType")
+  py::enum_<MlirSparseTensorDimLevelType>(m, "DimLevelType", py::module_local())
       .value("dense", MLIR_SPARSE_TENSOR_DIM_LEVEL_DENSE)
       .value("compressed", MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED)
       .value("singleton", MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON);
index 9d217c8..7028704 100644 (file)
@@ -678,7 +678,8 @@ public:
   }
 
   static void bind(pybind11::module &m) {
-    auto cls = ClassTy(m, DerivedTy::pyClassName, pybind11::buffer_protocol());
+    auto cls = ClassTy(m, DerivedTy::pyClassName, pybind11::buffer_protocol(),
+                       pybind11::module_local());
     cls.def(pybind11::init<PyAttribute &>(), pybind11::keep_alive<0, 1>());
     DerivedTy::bindDerived(cls);
   }
@@ -741,7 +742,7 @@ public:
   }
 
   static void bind(pybind11::module &m) {
-    auto cls = ClassTy(m, DerivedTy::pyClassName);
+    auto cls = ClassTy(m, DerivedTy::pyClassName, pybind11::module_local());
     cls.def(pybind11::init<PyType &>(), pybind11::keep_alive<0, 1>());
     cls.def_static("isinstance", [](PyType &otherType) -> bool {
       return DerivedTy::isaFunction(otherType);
index 7a9b8ec..9fecc7c 100644 (file)
@@ -262,7 +262,8 @@ public:
 
   /// Binds the indexing and length methods in the Python class.
   static void bind(pybind11::module &m) {
-    auto clazz = pybind11::class_<Derived>(m, Derived::pyClassName)
+    auto clazz = pybind11::class_<Derived>(m, Derived::pyClassName,
+                                           pybind11::module_local())
                      .def("__len__", &Sliceable::dunderLen)
                      .def("__getitem__", &Sliceable::dunderGetItem)
                      .def("__getitem__", &Sliceable::dunderGetItemSlice);