Skip to content
This repository was archived by the owner on Oct 11, 2025. It is now read-only.

Commit d5e5615

Browse files
authored
[MLIR][Python] fix stubgen (#157583)
In llvm/llvm-project#155741 I broke the cardinal rule of CMake: nothing happens when you think it happens 🤷. Meaning: `declare_mlir_python_sources(SOURCES_GLOB "_mlir_libs/${_module_name}/**/*.pyi")` wasn't picking up any sources _because they aren't generated yet_. This of course makes sense in retrospect (the stubs are generated as part of the build process, post extension compile, rather than the configure process). Thus, the API needs to be: ``` GENERATE_TYPE_STUBS: List of generated type stubs expected from stubgen, relative to _mlir_libs. ``` Partially as a result of this omission, the stubs weren't being installed into either the build dir nor the install dir. That is also fixed now: **Source dir (for easy reference):** <img width="300" height="674" alt="image" src="https://github.com/user-attachments/assets/a569f066-c2bd-4361-91f3-1c75181e51da" /> **Build dir (for forthcoming typechecker tests):** <img width="398" height="551" alt="image" src="https://github.com/user-attachments/assets/017859f9-fddb-49ee-85e5-915f5b5f7377" /> **Install dir:** <img width="456" height="884" alt="image" src="https://github.com/user-attachments/assets/8051be7e-898c-4ec8-a11e-e2408b241a56" />
1 parent 1c09d21 commit d5e5615

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

mlir/python/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,10 @@ declare_mlir_python_extension(MLIRPythonExtension.Core
506506
# Dialects
507507
MLIRCAPIFunc
508508
GENERATE_TYPE_STUBS
509+
"_mlir/__init__.pyi"
510+
"_mlir/ir.pyi"
511+
"_mlir/passmanager.pyi"
512+
"_mlir/rewrite.pyi"
509513
)
510514

511515
# This extension exposes an API to register all dialects, extensions, and passes
@@ -528,6 +532,7 @@ declare_mlir_python_extension(MLIRPythonExtension.RegisterEverything
528532
MLIRCAPITransforms
529533
MLIRCAPIRegisterEverything
530534
GENERATE_TYPE_STUBS
535+
"_mlirRegisterEverything.pyi"
531536
)
532537

533538
declare_mlir_python_extension(MLIRPythonExtension.Dialects.Linalg.Pybind
@@ -543,6 +548,7 @@ declare_mlir_python_extension(MLIRPythonExtension.Dialects.Linalg.Pybind
543548
MLIRCAPIIR
544549
MLIRCAPILinalg
545550
GENERATE_TYPE_STUBS
551+
"_mlirDialectsLinalg.pyi"
546552
)
547553

548554
declare_mlir_python_extension(MLIRPythonExtension.Dialects.GPU.Pybind
@@ -558,6 +564,7 @@ declare_mlir_python_extension(MLIRPythonExtension.Dialects.GPU.Pybind
558564
MLIRCAPIIR
559565
MLIRCAPIGPU
560566
GENERATE_TYPE_STUBS
567+
"_mlirDialectsGPU.pyi"
561568
)
562569

563570
declare_mlir_python_extension(MLIRPythonExtension.Dialects.LLVM.Pybind
@@ -573,6 +580,7 @@ declare_mlir_python_extension(MLIRPythonExtension.Dialects.LLVM.Pybind
573580
MLIRCAPIIR
574581
MLIRCAPILLVM
575582
GENERATE_TYPE_STUBS
583+
"_mlirDialectsLLVM.pyi"
576584
)
577585

578586
declare_mlir_python_extension(MLIRPythonExtension.Dialects.Quant.Pybind
@@ -588,6 +596,7 @@ declare_mlir_python_extension(MLIRPythonExtension.Dialects.Quant.Pybind
588596
MLIRCAPIIR
589597
MLIRCAPIQuant
590598
GENERATE_TYPE_STUBS
599+
"_mlirDialectsQuant.pyi"
591600
)
592601

593602
declare_mlir_python_extension(MLIRPythonExtension.Dialects.NVGPU.Pybind
@@ -603,6 +612,7 @@ declare_mlir_python_extension(MLIRPythonExtension.Dialects.NVGPU.Pybind
603612
MLIRCAPIIR
604613
MLIRCAPINVGPU
605614
GENERATE_TYPE_STUBS
615+
"_mlirDialectsNVGPU.pyi"
606616
)
607617

608618
declare_mlir_python_extension(MLIRPythonExtension.Dialects.PDL.Pybind
@@ -618,6 +628,7 @@ declare_mlir_python_extension(MLIRPythonExtension.Dialects.PDL.Pybind
618628
MLIRCAPIIR
619629
MLIRCAPIPDL
620630
GENERATE_TYPE_STUBS
631+
"_mlirDialectsPDL.pyi"
621632
)
622633

623634
declare_mlir_python_extension(MLIRPythonExtension.Dialects.SparseTensor.Pybind
@@ -633,6 +644,7 @@ declare_mlir_python_extension(MLIRPythonExtension.Dialects.SparseTensor.Pybind
633644
MLIRCAPIIR
634645
MLIRCAPISparseTensor
635646
GENERATE_TYPE_STUBS
647+
"_mlirDialectsSparseTensor.pyi"
636648
)
637649

638650
declare_mlir_python_extension(MLIRPythonExtension.Dialects.Transform.Pybind
@@ -648,6 +660,7 @@ declare_mlir_python_extension(MLIRPythonExtension.Dialects.Transform.Pybind
648660
MLIRCAPIIR
649661
MLIRCAPITransformDialect
650662
GENERATE_TYPE_STUBS
663+
"_mlirDialectsTransform.pyi"
651664
)
652665

653666
declare_mlir_python_extension(MLIRPythonExtension.AsyncDialectPasses
@@ -662,6 +675,7 @@ declare_mlir_python_extension(MLIRPythonExtension.AsyncDialectPasses
662675
EMBED_CAPI_LINK_LIBS
663676
MLIRCAPIAsync
664677
GENERATE_TYPE_STUBS
678+
"_mlirAsyncPasses.pyi"
665679
)
666680

667681
if(MLIR_ENABLE_EXECUTION_ENGINE)
@@ -677,6 +691,7 @@ if(MLIR_ENABLE_EXECUTION_ENGINE)
677691
EMBED_CAPI_LINK_LIBS
678692
MLIRCAPIExecutionEngine
679693
GENERATE_TYPE_STUBS
694+
"_mlirExecutionEngine.pyi"
680695
)
681696
endif()
682697

@@ -692,6 +707,7 @@ declare_mlir_python_extension(MLIRPythonExtension.GPUDialectPasses
692707
EMBED_CAPI_LINK_LIBS
693708
MLIRCAPIGPU
694709
GENERATE_TYPE_STUBS
710+
"_mlirGPUPasses.pyi"
695711
)
696712

697713
declare_mlir_python_extension(MLIRPythonExtension.LinalgPasses
@@ -706,6 +722,7 @@ declare_mlir_python_extension(MLIRPythonExtension.LinalgPasses
706722
EMBED_CAPI_LINK_LIBS
707723
MLIRCAPILinalg
708724
GENERATE_TYPE_STUBS
725+
"_mlirLinalgPasses.pyi"
709726
)
710727

711728
declare_mlir_python_extension(MLIRPythonExtension.Dialects.SMT.Pybind
@@ -724,6 +741,7 @@ declare_mlir_python_extension(MLIRPythonExtension.Dialects.SMT.Pybind
724741
MLIRCAPISMT
725742
MLIRCAPIExportSMTLIB
726743
GENERATE_TYPE_STUBS
744+
"_mlirDialectsSMT.pyi"
727745
)
728746

729747
declare_mlir_python_extension(MLIRPythonExtension.SparseTensorDialectPasses
@@ -738,6 +756,7 @@ declare_mlir_python_extension(MLIRPythonExtension.SparseTensorDialectPasses
738756
EMBED_CAPI_LINK_LIBS
739757
MLIRCAPISparseTensor
740758
GENERATE_TYPE_STUBS
759+
"_mlirSparseTensorPasses.pyi"
741760
)
742761

743762
declare_mlir_python_extension(MLIRPythonExtension.TransformInterpreter
@@ -752,6 +771,7 @@ declare_mlir_python_extension(MLIRPythonExtension.TransformInterpreter
752771
EMBED_CAPI_LINK_LIBS
753772
MLIRCAPITransformDialectTransforms
754773
GENERATE_TYPE_STUBS
774+
"_mlirTransformInterpreter.pyi"
755775
)
756776

757777
# TODO: Figure out how to put this in the test tree.
@@ -811,6 +831,7 @@ if(MLIR_INCLUDE_TESTS)
811831
EMBED_CAPI_LINK_LIBS
812832
MLIRCAPIPythonTestDialect
813833
GENERATE_TYPE_STUBS
834+
"_mlirPythonTestNanobind.pyi"
814835
)
815836
endif()
816837

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
_mlir/**/*.pyi
2+
*.pyi

0 commit comments

Comments
 (0)