tqchen commented on code in PR #19959:
URL: https://github.com/apache/tvm/pull/19959#discussion_r3530339336


##########
src/relax/ir/expr_functor.cc:
##########
@@ -544,19 +544,36 @@ PrimExpr ExprMutatorBase::VisitTypePrimExprField(const 
PrimExpr& expr) {
 // ==================
 // ExprMutator
 
+namespace {
+
+template <typename TMap>
+void RedirectVarRemapTargets(TMap* var_remap, const Var& old_target, const 
Var& new_target) {
+  if (old_target.same_as(new_target)) {
+    return;
+  }
+  for (auto& entry : *var_remap) {
+    if (entry.second.same_as(old_target)) {
+      entry.second = new_target;
+    }
+  }
+}
+
+}  // namespace

Review Comment:
   Resolved by c180e9e293. The full-map RedirectVarRemapTargets scan is removed 
entirely. var_remap_ remains a direct one-hop map: ReEmitBinding and MatchCast 
record the original, visited, and final variables with constant-time 
unordered-map writes, while downstream mutators retain ownership of any 
recursive remapping they need. User-defined A-to-B/B-to-A mappings are 
therefore never traversed recursively and cannot loop. Validation rebuilt 
tvm_compiler and cpptest; 4/4 C++ expression tests passed; 214 existing focused 
Python tests passed with one expected xfail across ExprMutator, 
canonicalization/type updates, layout, CSE, LambdaLift, lazy transform params, 
CUDA graph, mixed precision, and script builder. No tests were added.



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