Skip to content

[REFACTOR][STUBGEN] refactor the stubgen logic.#608

Open
Seven-Streams wants to merge 1 commit into
apache:mainfrom
Seven-Streams:main-dev/2026-06-04/stubgen_refactor
Open

[REFACTOR][STUBGEN] refactor the stubgen logic.#608
Seven-Streams wants to merge 1 commit into
apache:mainfrom
Seven-Streams:main-dev/2026-06-04/stubgen_refactor

Conversation

@Seven-Streams

Copy link
Copy Markdown

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:

python/tvm_ffi/stub/
├── __init__.py
├── cli.py
├── consts.py
├── file_utils.py
├── lib_state.py
├── utils.py
├── generator.py
└── python_generator/
    ├── __init__.py
    ├── generator.py
    ├── codegen.py
    ├── consts.py
    └── utils.py

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread python/tvm_ffi/stub/python_generator/codegen.py Outdated
Comment thread python/tvm_ffi/stub/python_generator/utils.py
Comment thread python/tvm_ffi/stub/python_generator/generator.py Outdated
@Seven-Streams Seven-Streams force-pushed the main-dev/2026-06-04/stubgen_refactor branch 2 times, most recently from 8045591 to 28c48ca Compare June 9, 2026 16:37
Signed-off-by: yuchuan <yuchuan.7streams@gmail.com>
@Seven-Streams Seven-Streams force-pushed the main-dev/2026-06-04/stubgen_refactor branch from 28c48ca to af56ed0 Compare June 9, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant