tqchen opened a new pull request, #19631:
URL: https://github.com/apache/tvm/pull/19631
## Background
The `tvm::ir` layer previously had a reverse dependency on `tvm::script`,
injected via the `TVM_OBJECT_ENABLE_SCRIPT_PRINTER()` macro that added a
`Script()` member method to IR node types (IRModule, PrimExpr, Buffer,
PrimFunc, Stmt). This violated the intended one-way dependency: `script` should
depend on `ir`, never the other way around.
Additionally, `PrinterConfigNode` accumulated dialect-specific fields
(`tir_prefix`, `tir_import_module`, `tirx_prefix`, `relax_prefix`,
`buffer_dtype`) that created leakage between the generic printer infrastructure
and dialect internals.
## Changes
This PR restores the clean dependency direction and encapsulates dialect
config properly, in 5 commits:
1. **Lift TVMScript entry point into `script/printer/printer.h`**: New
header `include/tvm/script/printer/printer.h` introduces:
- `tvm::Script()` free function replacing `TVMScriptPrinter::Script()`
static method
- `TVMScriptPrinter` class with vtable (`NodeFunctor<std::string(...)>`)
- `TVM_REGISTER_SCRIPT_AS_REPR` macro for registering per-type repr
callbacks
2. **Drop `TVM_OBJECT_ENABLE_SCRIPT_PRINTER` macro**: Remove the macro from
all IR headers (`ir/expr.h`, `ir/module.h`, `tirx/buffer.h`, `tirx/function.h`,
`tirx/stmt.h`), eliminating the reverse `ir` → `script` dependency. All call
sites of `.Script()` member methods updated to use `tvm::Script()`.
3. **Move dialect-specific `PrinterConfig` fields to `extra_config`**:
Remove `tir_prefix`, `tir_import_module`, `tirx_prefix`, `relax_prefix`,
`buffer_dtype` from `PrinterConfigNode`. Dialect internals now read their
config via `GetExtraConfig<T>(key, fallback)` with dotted keys (e.g.,
`"tirx.prefix"`, `"tirx.buffer_dtype"`).
4. **Python: drop dialect kwargs, expose `extra_config`**: Update
`PrinterConfig`, `Scriptable.script()`, `Scriptable.show()`,
`Scriptable._relax_script()`, and `BasePyModule.script()` to use `extra_config:
dict | None = None` instead of individual dialect kwargs. The tirx auto-switch
logic is preserved.
5. **Fix transitive include breakage**: Explicitly add direct includes for
`config.h` and `node_functor.h` where headers previously relied on transitive
paths through `expr.h`/`module.h`.
## Testing
- C++ unit tests: 118/118 pass
- TVMScript printer tests: 771 passed, 1 skipped, 1 xfailed
- TIR namespace tests (`tests/python/tirx/test_printer_tir_namespaces.py`):
13/13 pass
- Relax AST printer tests: 24/24 pass
- Minimal platform tests: 37/37 pass
- Pre-commit (ASF headers, ruff, clang-format): all 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]