Skip to content

Commit 2d53e6a

Browse files
authored
[Unity][Transform] Handle replacement at both var binding and usage (#16367)
Resolve a bug that caused undefined relax variables in the output of `CanonicalizeBindings` for cases where `VisitVarDef(const Var&)` replaces a variable, and `VisitExpr_(const VarNode*)` returns a value with different struct info, both occurring within the same `VarBinding`. The ExprMutator is only allowed to update a variable's struct info if the value bound to it has new struct info. When CanonicalizeBindings replaces a trivial binding, this may provide better struct info as a result. Prior to this commit, `ExprMutator::ReEmitBinding` defined a remap for `binding->var->vid`, even if the derived class defined a replacement by overriding `VisitVarDef`. If the derived class defines a new variable binding by overriding `VisitVarDef`, and also causes a variable replacement by overriding `VisitExpr` and returning a type with different struct info, then `ExprMutator` must check for both `binding->var->vid` *AND* `new_var->vid`. The former may be present in the unmodified graph, and the latter may be produced by the derived class before delegating to the base class. This commit updates `ExprMutator::ReEmitBinding` to define entries for both replacements that may be required.
1 parent 1e95b63 commit 2d53e6a

File tree

2 files changed

+133
-55
lines changed

2 files changed

+133
-55
lines changed

src/relax/ir/expr_functor.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,9 @@ void ExprMutator::ReEmitBinding(const VarBindingNode* binding, Expr new_value) {
682682
if (!temp.same_as(new_var)) {
683683
new_var = temp;
684684
}
685+
685686
this->var_remap_[binding->var->vid] = new_var;
687+
this->var_remap_[new_var->vid] = new_var;
686688

687689
builder_->EmitNormalized(VarBinding(new_var, new_value));
688690
}

0 commit comments

Comments
 (0)