Skip to content

Commit a5a24c9

Browse files
committed
Remove misused RAII gil_scoped_release/gil_scoped_acquire: without name they don't have any effect
I'm not sure what is the right fix here, but adding a name to all these lead to many segfaults. Reviewed By: stellaraccident Differential Revision: https://reviews.llvm.org/D116506
1 parent 29120a5 commit a5a24c9

File tree

2 files changed

+0
-9
lines changed

2 files changed

+0
-9
lines changed

mlir/lib/Bindings/Python/IRCore.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,6 @@ void PyOperationBase::print(py::object fileObject, bool binary,
868868
mlirOpPrintingFlagsPrintGenericOpForm(flags);
869869

870870
PyFileAccumulator accum(fileObject, binary);
871-
py::gil_scoped_release();
872871
mlirOperationPrintWithFlags(operation, flags, accum.getCallback(),
873872
accum.getUserData());
874873
mlirOpPrintingFlagsDestroy(flags);

mlir/lib/Bindings/Python/IRModule.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ PyGlobals::PyGlobals() {
3535
PyGlobals::~PyGlobals() { instance = nullptr; }
3636

3737
void PyGlobals::loadDialectModule(llvm::StringRef dialectNamespace) {
38-
py::gil_scoped_acquire();
3938
if (loadedDialectModulesCache.contains(dialectNamespace))
4039
return;
4140
// Since re-entrancy is possible, make a copy of the search prefixes.
@@ -46,7 +45,6 @@ void PyGlobals::loadDialectModule(llvm::StringRef dialectNamespace) {
4645
moduleName.append(dialectNamespace.data(), dialectNamespace.size());
4746

4847
try {
49-
py::gil_scoped_release();
5048
loaded = py::module::import(moduleName.c_str());
5149
} catch (py::error_already_set &e) {
5250
if (e.matches(PyExc_ModuleNotFoundError)) {
@@ -64,7 +62,6 @@ void PyGlobals::loadDialectModule(llvm::StringRef dialectNamespace) {
6462

6563
void PyGlobals::registerDialectImpl(const std::string &dialectNamespace,
6664
py::object pyClass) {
67-
py::gil_scoped_acquire();
6865
py::object &found = dialectClassMap[dialectNamespace];
6966
if (found) {
7067
throw SetPyError(PyExc_RuntimeError, llvm::Twine("Dialect namespace '") +
@@ -77,7 +74,6 @@ void PyGlobals::registerDialectImpl(const std::string &dialectNamespace,
7774
void PyGlobals::registerOperationImpl(const std::string &operationName,
7875
py::object pyClass,
7976
py::object rawOpViewClass) {
80-
py::gil_scoped_acquire();
8177
py::object &found = operationClassMap[operationName];
8278
if (found) {
8379
throw SetPyError(PyExc_RuntimeError, llvm::Twine("Operation '") +
@@ -90,7 +86,6 @@ void PyGlobals::registerOperationImpl(const std::string &operationName,
9086

9187
llvm::Optional<py::object>
9288
PyGlobals::lookupDialectClass(const std::string &dialectNamespace) {
93-
py::gil_scoped_acquire();
9489
loadDialectModule(dialectNamespace);
9590
// Fast match against the class map first (common case).
9691
const auto foundIt = dialectClassMap.find(dialectNamespace);
@@ -109,7 +104,6 @@ PyGlobals::lookupDialectClass(const std::string &dialectNamespace) {
109104
llvm::Optional<pybind11::object>
110105
PyGlobals::lookupRawOpViewClass(llvm::StringRef operationName) {
111106
{
112-
py::gil_scoped_acquire();
113107
auto foundIt = rawOpViewClassMapCache.find(operationName);
114108
if (foundIt != rawOpViewClassMapCache.end()) {
115109
if (foundIt->second.is_none())
@@ -126,7 +120,6 @@ PyGlobals::lookupRawOpViewClass(llvm::StringRef operationName) {
126120

127121
// Attempt to find from the canonical map and cache.
128122
{
129-
py::gil_scoped_acquire();
130123
auto foundIt = rawOpViewClassMap.find(operationName);
131124
if (foundIt != rawOpViewClassMap.end()) {
132125
if (foundIt->second.is_none())
@@ -143,7 +136,6 @@ PyGlobals::lookupRawOpViewClass(llvm::StringRef operationName) {
143136
}
144137

145138
void PyGlobals::clearImportCache() {
146-
py::gil_scoped_acquire();
147139
loadedDialectModulesCache.clear();
148140
rawOpViewClassMapCache.clear();
149141
}

0 commit comments

Comments
 (0)