[mlir][python] remove eager loading of dialect module (for type and value casting) (#72338)

This commit is contained in:
Maksim Levental 2023-11-20 19:54:55 -06:00 committed by GitHub
parent 525396a3ae
commit 26dc765088
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -132,10 +132,8 @@ PyGlobals::lookupAttributeBuilder(const std::string &attributeKind) {
std::optional<py::function> PyGlobals::lookupTypeCaster(MlirTypeID mlirTypeID,
MlirDialect dialect) {
// Make sure dialect module is loaded.
if (!loadDialectModule(unwrap(mlirDialectGetNamespace(dialect))))
return std::nullopt;
// Try to load dialect module.
(void)loadDialectModule(unwrap(mlirDialectGetNamespace(dialect)));
const auto foundIt = typeCasterMap.find(mlirTypeID);
if (foundIt != typeCasterMap.end()) {
assert(foundIt->second && "type caster is defined");
@ -146,7 +144,8 @@ std::optional<py::function> PyGlobals::lookupTypeCaster(MlirTypeID mlirTypeID,
std::optional<py::function> PyGlobals::lookupValueCaster(MlirTypeID mlirTypeID,
MlirDialect dialect) {
loadDialectModule(unwrap(mlirDialectGetNamespace(dialect)));
// Try to load dialect module.
(void)loadDialectModule(unwrap(mlirDialectGetNamespace(dialect)));
const auto foundIt = valueCasterMap.find(mlirTypeID);
if (foundIt != valueCasterMap.end()) {
assert(foundIt->second && "value caster is defined");