Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Unity][Transform] Handle replacement at both var binding and usage #16367

Conversation

Lunderberg
Copy link
Contributor

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.

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.
@vinx13 vinx13 requested a review from Hzfengsy January 8, 2024 22:19
@Hzfengsy Hzfengsy merged commit 2d53e6a into apache:unity Jan 9, 2024
15 checks passed
@Lunderberg Lunderberg deleted the unity_canonicalize_var_and_expr_in_same_binding branch January 9, 2024 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants