[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:00:45 PDT 2026
https://github.com/aidint created https://github.com/llvm/llvm-project/pull/235462
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
>From 7fc43e1ccaee59ebc68c79353372a188c6c1d0ba Mon Sep 17 00:00:00 2001
From: aidint <at.aidin at gmail.com>
Date: Sun, 25 Oct 2026 15:31:44 +0100
Subject: [PATCH] [mlir][python] Make test stubgen depend on
_mlirRegisterEverything
Importing _mlirPythonTestNanobind runs _site_initialize(), which also
imports _mlirRegisterEverything. The stubgen rule didn't depend on it,
so incremental builds could run stubgen against a stale copy and crash
with "free(): invalid pointer".
Assisted-by: Claude Opus 5.5
---
mlir/python/CMakeLists.txt | 2 ++
1 file changed, 2 insertions(+)
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}"
More information about the Mlir-commits
mailing list