You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "tqchen (via GitHub)" <gi...@apache.org> on 2026/04/29 20:40:37 UTC

[PR] [REFACTOR][SCRIPT] Per-dialect TVMScript restructure with registry [tvm]

tqchen opened a new pull request, #19479:
URL: https://github.com/apache/tvm/pull/19479

   ## Summary
   
   Restructure TVMScript so each extension dialect (TIRX, Relax) owns
   its own script subtree, while the shared script core (Doc IR,
   IRDocsifier, IRBuilder, IR-layer handlers) stays in `src/script/`.
   IR is below script in the dependency stack and is not treated as
   a peer dialect — its script handlers live in the core.
   
   This PR:
   
   - Moves per-dialect printer + builder from
     `src/script/{printer,ir_builder}/{tirx,relax}/` to
     `src/{tirx,relax}/script/{printer,builder}/`.
   - Tightens `src/script/*.cc` CMake glob to the dialect-free core.
   - Refactors `IRBuilder::DeclFunction` to dispatch via an FFI registry
     (`script.ir_builder.decl_function.<type-key>`) — eliminates
     cross-dialect includes from the shared core.
   - Duplicates the `TVM_SCRIPT_REPR` macro per-dialect, consistent with
     each dialect owning its printer's static-init.
   - Adds a `tvm.script.register_dialect` API + `__getattr__` + a
     `sys.meta_path` finder for Python-side dialect discovery.  In-tree
     dialects (tirx, relax) are registered centrally in
     `python/tvm/__init__.py`; out-of-tree dialects can register from
     their own packages.
   - Drops the obsolete static re-export shims at
     `python/tvm/script/{parser,ir_builder}/{tirx,relax}/`.
   
   Public Python API surface unchanged: ``from tvm.script import tirx
   as T``, ``from tvm.script.parser.tirx import T``, etc. continue to
   work through the new redirect.
   
   ## Test plan
   
   - Full ninja build (USE_LLVM=ON), `./cpptest` 118/118.
   - `pytest tests/python/tvmscript/` — **771 passed, 1 xfailed** (expected).
   - `pytest tests/python/runtime/` — 68 passed.
   - `pytest tests/python/all-platform-minimal-test/` — 65 passed, 77 hardware-skipped.
   - `pytest tests/python/relax/test_tvmscript_ir_builder.py tests/python/relax/test_analysis_struct_info_analysis.py` — green.
   - `pre-commit run` on changed files — clean.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [REFACTOR][SCRIPT] Per-dialect TVMScript restructure with registry [tvm]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #19479:
URL: https://github.com/apache/tvm/pull/19479#discussion_r3164046390


##########
src/script/printer/utils.h:
##########
@@ -38,16 +38,11 @@ namespace tvm {
 namespace script {
 namespace printer {
 
-#define TVM_SCRIPT_REPR(ObjectType, Method)                                                    \
-  TVM_FFI_STATIC_INIT_BLOCK() {                                                                \
-    namespace refl = tvm::ffi::reflection;                                                     \
-    refl::TypeAttrDef<ObjectType>().def(refl::type_attr::kRepr,                                \
-                                        [](ffi::ObjectRef obj, ffi::Function) -> ffi::String { \
-                                          return RedirectedReprPrinterMethod(obj);             \
-                                        });                                                    \
-  }                                                                                            \
-  TVM_STATIC_IR_FUNCTOR(TVMScriptPrinter, vtable).set_dispatch<ObjectType>(Method)
-
+// Note: the `TVM_SCRIPT_REPR` macro is intentionally duplicated in each
+// dialect-local `src/<dialect>/script/printer/utils.h`. Keeping a single
+// definition here would force the dialect headers to depend on this shared
+// header, which the per-dialect restructure aims to avoid for cross-directory
+// references. See each `<dialect>/script/printer/utils.h` for the macro.

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The justification for duplicating the `TVM_SCRIPT_REPR` macro is to avoid cross-directory references. However, the dialect-specific headers (e.g., `src/relax/script/printer/utils.h` at line 35 and `src/tirx/script/printer/utils.h` at line 38) already include this shared header to access `RedirectedReprPrinterMethod`. Since the dependency is already present and required for the macro to function, duplicating the macro across multiple files increases maintenance burden without providing the intended decoupling. It is recommended to keep the macro definition here.
   
   ```c
   #define TVM_SCRIPT_REPR(ObjectType, Method)                                                    \
     TVM_FFI_STATIC_INIT_BLOCK() {                                                                \
       namespace refl = tvm::ffi::reflection;                                                     \
       refl::TypeAttrDef<ObjectType>().def(refl::type_attr::kRepr,                                \
                                           [](ffi::ObjectRef obj, ffi::Function) -> ffi::String { \
                                             return RedirectedReprPrinterMethod(obj);             \
                                           });                                                    \
     }                                                                                            \
     TVM_STATIC_IR_FUNCTOR(TVMScriptPrinter, vtable).set_dispatch<ObjectType>(Method)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [REFACTOR][SCRIPT] TVMScript dialect-friendly refactor: per-dialect restructure + dialect registry [tvm]

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen merged PR #19479:
URL: https://github.com/apache/tvm/pull/19479


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org