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: [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]

Reply via email to