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/07/04 23:33:34 UTC

[PR] [TIRx] Phase out duplicate Var type_annotation [tvm]

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

   ## Rationale
   
   TIRx variables use inherited `ExprNode::ty` as their single semantic type. Retaining a primitive handle surrogate erases the distinction between scalar values, typed pointers, and true opaque pointers, then forces later passes and code generators to reconstruct information that the IR already owns.
   
   ## Changes
   
   - Remove the duplicate reflected `Var::type_annotation` state and preserve exact `PrimType` or `PointerType` through construction, visitors, transforms, specialization, builders, printers, and code generation.
   - Keep scalar-only boundaries explicit through `PrimExpr`, `PrimVar`, and `PrimType`; pointer-capable values remain general `Expr` or `Var`.
   - Keep helper boundaries no broader than their contracts: TE tensor variable indices use `PrimVar`, while expression deep equality recurses through general `Expr` only where pointer-bearing `Call` arguments require it and does not generalize private arithmetic subclasses.
   - Keep core statement reflection typed as `Expr`, name general reinterpret targets as `target_ty`, and preserve exact pointer calls in the general vectorization path with explicit scalarization behavior.
   - Delete `PrimType::Handle()` and `PrimType::IsHandle()`. True opaque pointers use `PointerType::VoidPointerTy()`; TVMScript renders the canonical global type as `T.handle`, standalone values as `T.handle()`, and scoped void pointers with a keyword-only storage scope.
   - Make `CodeGenSourceBase::SSAGetID` a single `Type` boundary across source backends, without a separate primitive-type or runtime-dtype variant.
   - Keep WebGPU semantic argument classification type-aware: storage buffers are identified from `PointerType`, POD arguments from `PrimType`, and only the final `FunctionInfo` launch ABI is serialized to `DLDataType`.
   - Preserve exact pointer semantics at runtime boundaries, including access pointers, packed calls and returns, external calls, storage rewrites, and target-specific lowering.


-- 
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] [TIRx] Phase out duplicate Var type_annotation [tvm]

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


##########
src/relax/ir/binding_rewrite.cc:
##########
@@ -102,14 +108,18 @@ void DataflowBlockRewriteNode::ReplaceAllUses(Var old_var, Var new_var) {
   // new_var -> {?}           | changed to old_var users
   for (Var user : to_users_[old_var]) {
     auto new_var_uses = to_users_[new_var];
-    if (new_var_uses.end() == std::find(new_var_uses.begin(), new_var_uses.end(), user)) {
+    if (new_var_uses.end() ==
+        std::find_if(new_var_uses.begin(), new_var_uses.end(),
+                     [&](const Var& candidate) { return candidate.same_as(user); })) {
       new_var_uses.push_back(user);
     }
   }

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   In `ReplaceAllUses`, the loop retrieves `new_var_uses` from `to_users_` in each iteration, appends the user to a local copy, but never writes the updated array back to the `to_users_` map. This causes the users of `old_var` to be lost and not actually transferred to `new_var`.\n\nTo fix this, retrieve `new_var_uses` once before the loop, update it inside the loop, and then call `to_users_.Set(new_var, new_var_uses)` after the loop.
   
   ```c
     ffi::Array<Var> new_var_uses = to_users_.Get(new_var).value_or(ffi::Array<Var>());\n  for (Var user : to_users_[old_var]) {\n    if (new_var_uses.end() ==\n        std::find_if(new_var_uses.begin(), new_var_uses.end(),\n                     [&](const Var& candidate) { return candidate.same_as(user); })) {\n      new_var_uses.push_back(user);\n    }\n  }\n  to_users_.Set(new_var, new_var_uses);
   ```



-- 
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] [TIRx] Phase out duplicate Var type_annotation [tvm]

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


-- 
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] [TIRx] Phase out duplicate Var type_annotation [tvm]

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on code in PR #19944:
URL: https://github.com/apache/tvm/pull/19944#discussion_r3524026111


##########
src/relax/ir/binding_rewrite.cc:
##########
@@ -102,14 +108,18 @@ void DataflowBlockRewriteNode::ReplaceAllUses(Var old_var, Var new_var) {
   // new_var -> {?}           | changed to old_var users
   for (Var user : to_users_[old_var]) {
     auto new_var_uses = to_users_[new_var];
-    if (new_var_uses.end() == std::find(new_var_uses.begin(), new_var_uses.end(), user)) {
+    if (new_var_uses.end() ==
+        std::find_if(new_var_uses.begin(), new_var_uses.end(),
+                     [&](const Var& candidate) { return candidate.same_as(user); })) {
       new_var_uses.push_back(user);
     }
   }

Review Comment:
   Confirmed. `ffi::Map::operator[]` returns the stored `ffi::Array` by value, and `push_back` copy-on-write detached the local array, so the appended users were not persisted.
   
   Commit `f9a9281e66` hoists the destination user array, performs identity-based deduplication across all transferred users, and writes it back with `to_users_.Set(new_var, new_var_uses)` before clearing the old entry. It also treats an existing `old_var.same_as(new_var)` replacement as a no-op after the presence checks, preventing the shared map entry from being cleared.
   
   The regression now proves that the destination cannot be removed after replacement because its two transferred users remain recorded. The full Relax binding-rewrite file passes 12/12 tests.
   



-- 
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