@@ -38,11 +38,8 @@ PyGlobals::PyGlobals() {
3838PyGlobals::~PyGlobals () { instance = nullptr ; }
3939
4040bool  PyGlobals::loadDialectModule (llvm::StringRef dialectNamespace) {
41-   {
42-     nb::ft_lock_guard lock (mutex);
43-     if  (loadedDialectModules.contains (dialectNamespace))
44-       return  true ;
45-   }
41+   if  (loadedDialectModules.contains (dialectNamespace))
42+     return  true ;
4643  //  Since re-entrancy is possible, make a copy of the search prefixes.
4744  std::vector<std::string> localSearchPrefixes = dialectSearchPrefixes;
4845  nb::object loaded = nb::none ();
@@ -65,14 +62,12 @@ bool PyGlobals::loadDialectModule(llvm::StringRef dialectNamespace) {
6562    return  false ;
6663  //  Note: Iterator cannot be shared from prior to loading, since re-entrancy
6764  //  may have occurred, which may do anything.
68-   nb::ft_lock_guard lock (mutex);
6965  loadedDialectModules.insert (dialectNamespace);
7066  return  true ;
7167}
7268
7369void  PyGlobals::registerAttributeBuilder (const  std::string &attributeKind,
7470                                         nb::callable pyFunc, bool  replace) {
75-   nb::ft_lock_guard lock (mutex);
7671  nb::object &found = attributeBuilderMap[attributeKind];
7772  if  (found && !replace) {
7873    throw  std::runtime_error ((llvm::Twine (" Attribute builder for '"  ) +
@@ -86,7 +81,6 @@ void PyGlobals::registerAttributeBuilder(const std::string &attributeKind,
8681
8782void  PyGlobals::registerTypeCaster (MlirTypeID mlirTypeID,
8883                                   nb::callable typeCaster, bool  replace) {
89-   nb::ft_lock_guard lock (mutex);
9084  nb::object &found = typeCasterMap[mlirTypeID];
9185  if  (found && !replace)
9286    throw  std::runtime_error (" Type caster is already registered with caster: "   +
@@ -96,7 +90,6 @@ void PyGlobals::registerTypeCaster(MlirTypeID mlirTypeID,
9690
9791void  PyGlobals::registerValueCaster (MlirTypeID mlirTypeID,
9892                                    nb::callable valueCaster, bool  replace) {
99-   nb::ft_lock_guard lock (mutex);
10093  nb::object &found = valueCasterMap[mlirTypeID];
10194  if  (found && !replace)
10295    throw  std::runtime_error (" Value caster is already registered: "   +
@@ -106,7 +99,6 @@ void PyGlobals::registerValueCaster(MlirTypeID mlirTypeID,
10699
107100void  PyGlobals::registerDialectImpl (const  std::string &dialectNamespace,
108101                                    nb::object pyClass) {
109-   nb::ft_lock_guard lock (mutex);
110102  nb::object &found = dialectClassMap[dialectNamespace];
111103  if  (found) {
112104    throw  std::runtime_error ((llvm::Twine (" Dialect namespace '"  ) +
@@ -118,7 +110,6 @@ void PyGlobals::registerDialectImpl(const std::string &dialectNamespace,
118110
119111void  PyGlobals::registerOperationImpl (const  std::string &operationName,
120112                                      nb::object pyClass, bool  replace) {
121-   nb::ft_lock_guard lock (mutex);
122113  nb::object &found = operationClassMap[operationName];
123114  if  (found && !replace) {
124115    throw  std::runtime_error ((llvm::Twine (" Operation '"  ) + operationName +
@@ -130,7 +121,6 @@ void PyGlobals::registerOperationImpl(const std::string &operationName,
130121
131122std::optional<nb::callable>
132123PyGlobals::lookupAttributeBuilder (const  std::string &attributeKind) {
133-   nb::ft_lock_guard lock (mutex);
134124  const  auto  foundIt = attributeBuilderMap.find (attributeKind);
135125  if  (foundIt != attributeBuilderMap.end ()) {
136126    assert (foundIt->second  && " attribute builder is defined"  );
@@ -143,7 +133,6 @@ std::optional<nb::callable> PyGlobals::lookupTypeCaster(MlirTypeID mlirTypeID,
143133                                                        MlirDialect dialect) {
144134  //  Try to load dialect module.
145135  (void )loadDialectModule (unwrap (mlirDialectGetNamespace (dialect)));
146-   nb::ft_lock_guard lock (mutex);
147136  const  auto  foundIt = typeCasterMap.find (mlirTypeID);
148137  if  (foundIt != typeCasterMap.end ()) {
149138    assert (foundIt->second  && " type caster is defined"  );
@@ -156,7 +145,6 @@ std::optional<nb::callable> PyGlobals::lookupValueCaster(MlirTypeID mlirTypeID,
156145                                                         MlirDialect dialect) {
157146  //  Try to load dialect module.
158147  (void )loadDialectModule (unwrap (mlirDialectGetNamespace (dialect)));
159-   nb::ft_lock_guard lock (mutex);
160148  const  auto  foundIt = valueCasterMap.find (mlirTypeID);
161149  if  (foundIt != valueCasterMap.end ()) {
162150    assert (foundIt->second  && " value caster is defined"  );
@@ -170,7 +158,6 @@ PyGlobals::lookupDialectClass(const std::string &dialectNamespace) {
170158  //  Make sure dialect module is loaded.
171159  if  (!loadDialectModule (dialectNamespace))
172160    return  std::nullopt ;
173-   nb::ft_lock_guard lock (mutex);
174161  const  auto  foundIt = dialectClassMap.find (dialectNamespace);
175162  if  (foundIt != dialectClassMap.end ()) {
176163    assert (foundIt->second  && " dialect class is defined"  );
@@ -188,7 +175,6 @@ PyGlobals::lookupOperationClass(llvm::StringRef operationName) {
188175  if  (!loadDialectModule (dialectNamespace))
189176    return  std::nullopt ;
190177
191-   nb::ft_lock_guard lock (mutex);
192178  auto  foundIt = operationClassMap.find (operationName);
193179  if  (foundIt != operationClassMap.end ()) {
194180    assert (foundIt->second  && " OpView is defined"  );
0 commit comments