[Mlir-commits] [mlir] [mlir][python] Make test stubgen depend on _mlirRegisterEverything (PR #235462)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Oct 25 08:01:19 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: AidinT (aidint)
<details>
<summary>Changes</summary>
Generating the type stub for `_mlirPythonTestNanobind` imports `mlir._mlir_libs._mlirPythonTestNanobind`. That runs `mlir/_mlir_libs/__init__.py`, whose `_site_initialize()` also imports `_mlirRegisterEverything`. The stubgen rule doesn't depend on that extension, so ninja can run stubgen before it has been rebuilt.
In a large incremental build, this can load a stale `_mlirRegisterEverything` that was built against older versions of the
MLIR libraries, mixing old and new code in one process, and stubgen aborts with "free(): invalid pointer".
Adding `_mlirRegisterEverything` to the rule's `DEPENDS_TARGETS` only changes build order: the stub already depends on almost everything the extension needs, so the extra cost is one small compile and one small link. Only builds with `MLIR_INCLUDE_TESTS` and stubgen enabled are affected.
Assisted-by: Claude Opus 5.5
---
Full diff: https://github.com/llvm/llvm-project/pull/235462.diff
1 Files Affected:
- (modified) mlir/python/CMakeLists.txt (+2)
``````````diff
diff --git a/mlir/python/CMakeLists.txt b/mlir/python/CMakeLists.txt
index d7a57a15f82420..4c890ee62d89ff 100644
--- a/mlir/python/CMakeLists.txt
+++ b/mlir/python/CMakeLists.txt
@@ -952,6 +952,8 @@ if(MLIR_PYTHON_STUBGEN_ENABLED)
MLIRPythonModules.extension._mlirPythonTestNanobind.dso
# You need this one so that ir.py "built" because mlir._mlir_libs.__init__.py import mlir.ir in _site_initialize.
MLIRPythonModules.sources.MLIRPythonSources.Core.Python
+ # You need this one because _site_initialize also imports _mlirRegisterEverything (a stale copy can crash stubgen).
+ MLIRPythonModules.extension._mlirRegisterEverything.dso
OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/type_stubs/_mlir_libs"
OUTPUTS _mlirPythonTestNanobind.pyi
DEPENDS_TARGET_SRC_DEPS "${_test_extension_srcs}"
``````````
</details>
https://github.com/llvm/llvm-project/pull/235462
More information about the Mlir-commits
mailing list