Skip to content
This repository was archived by the owner on Oct 11, 2025. It is now read-only.

Commit f5df17a

Browse files
committed
Revert "[mlir python] Port Python core code to nanobind. (#118583)"
This reverts commit 29e4706. Breakage detected, rolling back.
1 parent 29e4706 commit f5df17a

File tree

14 files changed

+1552
-1845
lines changed

14 files changed

+1552
-1845
lines changed

mlir/lib/Bindings/Python/Globals.h

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@
99
#ifndef MLIR_BINDINGS_PYTHON_GLOBALS_H
1010
#define MLIR_BINDINGS_PYTHON_GLOBALS_H
1111

12-
#include <optional>
13-
#include <string>
14-
#include <vector>
12+
#include "PybindUtils.h"
1513

16-
#include "NanobindUtils.h"
1714
#include "mlir-c/IR.h"
1815
#include "mlir/CAPI/Support.h"
1916
#include "llvm/ADT/DenseMap.h"
2017
#include "llvm/ADT/StringRef.h"
2118
#include "llvm/ADT/StringSet.h"
2219

20+
#include <optional>
21+
#include <string>
22+
#include <vector>
23+
2324
namespace mlir {
2425
namespace python {
2526

@@ -56,71 +57,71 @@ class PyGlobals {
5657
/// Raises an exception if the mapping already exists and replace == false.
5758
/// This is intended to be called by implementation code.
5859
void registerAttributeBuilder(const std::string &attributeKind,
59-
nanobind::callable pyFunc,
60+
pybind11::function pyFunc,
6061
bool replace = false);
6162

6263
/// Adds a user-friendly type caster. Raises an exception if the mapping
6364
/// already exists and replace == false. This is intended to be called by
6465
/// implementation code.
65-
void registerTypeCaster(MlirTypeID mlirTypeID, nanobind::callable typeCaster,
66+
void registerTypeCaster(MlirTypeID mlirTypeID, pybind11::function typeCaster,
6667
bool replace = false);
6768

6869
/// Adds a user-friendly value caster. Raises an exception if the mapping
6970
/// already exists and replace == false. This is intended to be called by
7071
/// implementation code.
7172
void registerValueCaster(MlirTypeID mlirTypeID,
72-
nanobind::callable valueCaster,
73+
pybind11::function valueCaster,
7374
bool replace = false);
7475

7576
/// Adds a concrete implementation dialect class.
7677
/// Raises an exception if the mapping already exists.
7778
/// This is intended to be called by implementation code.
7879
void registerDialectImpl(const std::string &dialectNamespace,
79-
nanobind::object pyClass);
80+
pybind11::object pyClass);
8081

8182
/// Adds a concrete implementation operation class.
8283
/// Raises an exception if the mapping already exists and replace == false.
8384
/// This is intended to be called by implementation code.
8485
void registerOperationImpl(const std::string &operationName,
85-
nanobind::object pyClass, bool replace = false);
86+
pybind11::object pyClass, bool replace = false);
8687

8788
/// Returns the custom Attribute builder for Attribute kind.
88-
std::optional<nanobind::callable>
89+
std::optional<pybind11::function>
8990
lookupAttributeBuilder(const std::string &attributeKind);
9091

9192
/// Returns the custom type caster for MlirTypeID mlirTypeID.
92-
std::optional<nanobind::callable> lookupTypeCaster(MlirTypeID mlirTypeID,
93+
std::optional<pybind11::function> lookupTypeCaster(MlirTypeID mlirTypeID,
9394
MlirDialect dialect);
9495

9596
/// Returns the custom value caster for MlirTypeID mlirTypeID.
96-
std::optional<nanobind::callable> lookupValueCaster(MlirTypeID mlirTypeID,
97+
std::optional<pybind11::function> lookupValueCaster(MlirTypeID mlirTypeID,
9798
MlirDialect dialect);
9899

99100
/// Looks up a registered dialect class by namespace. Note that this may
100101
/// trigger loading of the defining module and can arbitrarily re-enter.
101-
std::optional<nanobind::object>
102+
std::optional<pybind11::object>
102103
lookupDialectClass(const std::string &dialectNamespace);
103104

104105
/// Looks up a registered operation class (deriving from OpView) by operation
105106
/// name. Note that this may trigger a load of the dialect, which can
106107
/// arbitrarily re-enter.
107-
std::optional<nanobind::object>
108+
std::optional<pybind11::object>
108109
lookupOperationClass(llvm::StringRef operationName);
109110

110111
private:
111112
static PyGlobals *instance;
112113
/// Module name prefixes to search under for dialect implementation modules.
113114
std::vector<std::string> dialectSearchPrefixes;
114115
/// Map of dialect namespace to external dialect class object.
115-
llvm::StringMap<nanobind::object> dialectClassMap;
116+
llvm::StringMap<pybind11::object> dialectClassMap;
116117
/// Map of full operation name to external operation class object.
117-
llvm::StringMap<nanobind::object> operationClassMap;
118+
llvm::StringMap<pybind11::object> operationClassMap;
118119
/// Map of attribute ODS name to custom builder.
119-
llvm::StringMap<nanobind::callable> attributeBuilderMap;
120+
llvm::StringMap<pybind11::object> attributeBuilderMap;
120121
/// Map of MlirTypeID to custom type caster.
121-
llvm::DenseMap<MlirTypeID, nanobind::callable> typeCasterMap;
122+
llvm::DenseMap<MlirTypeID, pybind11::object> typeCasterMap;
122123
/// Map of MlirTypeID to custom value caster.
123-
llvm::DenseMap<MlirTypeID, nanobind::callable> valueCasterMap;
124+
llvm::DenseMap<MlirTypeID, pybind11::object> valueCasterMap;
124125
/// Set of dialect namespaces that we have attempted to import implementation
125126
/// modules for.
126127
llvm::StringSet<> loadedDialectModules;

0 commit comments

Comments
 (0)