An _mlirRegisterEverything.*.so file from an old build that referenced
MLIRPythonExtension.RegisterEverything, but which no longer references
that extension in a new build, causes runtime errors in the new build
like:
ImportError: _mlirRegisterEverything.cpython-38-x86_64-linux-gnu.so: undefined symbol: mlirRegisterAllPasses
The error occurs because the MLIR Python binding tries to dynamically
import the _mlirRegisterEverything module but the dynamic importer
fails since the new build no longer references
MLIRPythonExtension.RegisterEverything.
One possible solution is for the user to manually remove the
_mlirRegisterEverything.*.so file. This patch instead resolves the
problem in code by printing a waning if the module cannot be
imported.
The downside listed is a big one, in my opinion. While I am sympathetic to the upgrade plight, I've found the silently swallowing errors love this is a bigger foot gun.
Can you split the excpetion handler? Keep ModuleNotFound first, then add another one for ImportError. In that one, log an error with exc_info=True with a very draconian message like "error importing mlir initializer {module_name}. This may happen in unclean incremental builds but is likely a real bug if encountered elsewhere and the MLIR Python API may not function."