[IR][Relax][TIRx] Unify Var identity#20004
Conversation
There was a problem hiding this comment.
Code Review
This pull request unifies the representation of variables across TVM by replacing dialect-specific variable classes with a canonical tvm.ir.Var and introducing tirx.PrimVar for primitive variables. This refactoring spans C++ and Python APIs, parsers, printers, and transformation passes. A critical issue was found in the TVMScript parser where tvm.ir.Type instances are compared using == (pointer equality) instead of structural equality, which would cause type verification for declared symbolic variables to always fail.
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.
Classify slot-backed primitive right-hand sides and demanded runtime results during shape-slot collection, then apply that plan during lowering. Emit runtime leaf matches directly while preserving structural match rounds and immediate compound scheduling.
Apply the pinned clang-format result to the changed C++ range, update Ruff union-style isinstance syntax, and forward-port the upstream DLight loop-factor fixes so obsolete F821 suppressions can be removed.
Restore natural TIRx recursion and the existing UndefinedVars-based leaf discovery. Production pipelines normalize runtime compound expressions with ComputePrimValue before VMShapeLower, while compound shape and type expressions remain slot-map-driven.
327d095 to
c98615b
Compare
Motivation
IR, Relax, and TIRx previously carried overlapping variable representations
and repeated runtime checks for ordinary, primitive, and dataflow values. That
made identity-sensitive maps, substitutions, and visitors fragile: logically
identical variables could cross subsystem boundaries through different views,
while downstream code repeatedly reconstructed the same type invariant.
This change gives each variable one canonical identity and expresses its role
through checked typed views and explicit semantic boundaries.
Design
Varidentity. Exact ordinaryvariables with
PrimTypeadmit the zero-state checkedPrimVarview;DataflowVarremains a runtime dataflow subtype even when primitive-typed.PrimVardirectly. Mixed-domain maps retainVaronly where Relax values are legitimate inputs.Relax visitors explicitly define their primitive-expression boundary, and
dependent type fields use a narrow callback that does not recurse through
unrelated runtime structure.
.nameAPI while the internal C++storage field remains
name_hint.Direct zero-argument
T.dtype()assignments declare symbols;I.meta_var(...)is the explicit shared parser-time escape. Other primitiveexpressions produce normal Relax bindings, and printing remains marker-free
with explicit
PrimTypeannotations.computations before VM shape lowering. Shape lowering derives demand from
live uses and dependent shape/type edges, uses canonical Var leaves and
UndefinedVarsfor dependencies, and keeps definition roots out of demand.One slot map controls heap loads and runtime-result capture without an
operator whitelist or whole-compound-root scalar classification.
Compatibility
.namefor public variable names;name_hintremains aninternal C++ storage detail.
dtype=constructor spellingare removed in favor of canonical
VarplusPrimTypeAPIs.R.prim_value(...)remains accepted input syntax but is not emitted by theprinter.
T.meta_varremains an alias of the sharedI.meta_varimplementation.
Validation
25/25 passed.
All 147 residual failures reproduced unchanged in an independent baseline
checkout, with no change-only failure.
regressions pass.