[REFACTOR][STUBGEN] refactor the stubgen logic.#608
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the tvm-ffi-stubgen tool to support pluggable code generators by separating language-agnostic infrastructure from language-specific rendering. It introduces a Generator protocol, extracts Python-specific codegen logic into a new python_generator package, and updates the CLI to support a --target option. Feedback on the changes highlights a few issues: a discrepancy in defined_type_keys mapping during FFI API generation, a potential bug in module prefix matching for imports where sub-modules are not properly distinguished, and a robust parsing improvement for the type_checking_only parameter in the Python generator.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
8045591 to
28c48ca
Compare
Signed-off-by: yuchuan <yuchuan.7streams@gmail.com>
28c48ca to
af56ed0
Compare
Summary
This PR refactors the Python stubgen implementation to improve extensibility and separation of concerns. No functional changes are intended, and the generated output should remain unchanged.
Design
The current stubgen implementation contains both language-independent logic (e.g., file processing and library analysis) and language-specific code generation. This PR separates these responsibilities by introducing a generator abstraction for the code generation layer, making it easier to support additional target languages in the future.
The reorganized file structure is:
This refactoring lays the groundwork for future support of Rust stub generation and other language backends.
Testing
This PR is a pure refactor and is not expected to change existing behavior. Therefore, no new tests are added.