[Relax][Bugfix] Provide the full Expr to pattern-match rewriter#16828
Merged
tqchen merged 2 commits intoapache:mainfrom Apr 1, 2024
Merged
Conversation
This resolves a bug that was introduced in apache#16732. If a rewriter function returned a no-op, and the pattern-match continued, then the `matches` provided to the rewriter function in subsequent calls would contain a variable to which the matched expression was bound, not the matched expression itself. (e.g. For a match of `C = R.add(A,B)`, passing `C` to the rewriter instead of `R.add(A,B)`.) This bug was caused by incorrect re-wrapping of `OrPattern` in `ExprPatternRewriter`. Prior to apache#16732, all pattern-match results were populated by `ExtractMatchExpr`, and contained the result after applying `TryGetValOfVar`. When re-wrapping the result of an `OrPattern`, apache#16732 populated the additional matches with the result before applying `TryGetValOfVar`. This commit fixes the bug by applying `TryGetValOfVar`.
MasterJH5574
reviewed
Apr 1, 2024
|
|
||
| This is a regression test. In versions from | ||
| https://github.com/apache/tvm/pull/16732 to | ||
| https://github.com/apache/tvm/pull/#####, the `rewrite_call` |
Contributor
Author
There was a problem hiding this comment.
Thank you, and fixed!
slyubomirsky
approved these changes
Apr 1, 2024
Contributor
slyubomirsky
left a comment
There was a problem hiding this comment.
Ah, a sneaky bug. Thank you for fixing it and providing a test case.
Contributor
Author
Thank you, though @MasterJH5574 deserves credit for making the test case. That helped quite a bit in narrowing down where the bug was occurring, and was very much appreciated. |
thaisacs
pushed a commit
to thaisacs/tvm
that referenced
this pull request
Apr 3, 2024
…he#16828) * [Relax][Bugfix] Provide the full Expr to pattern-match rewriter This resolves a bug that was introduced in apache#16732. If a rewriter function returned a no-op, and the pattern-match continued, then the `matches` provided to the rewriter function in subsequent calls would contain a variable to which the matched expression was bound, not the matched expression itself. (e.g. For a match of `C = R.add(A,B)`, passing `C` to the rewriter instead of `R.add(A,B)`.) This bug was caused by incorrect re-wrapping of `OrPattern` in `ExprPatternRewriter`. Prior to apache#16732, all pattern-match results were populated by `ExtractMatchExpr`, and contained the result after applying `TryGetValOfVar`. When re-wrapping the result of an `OrPattern`, apache#16732 populated the additional matches with the result before applying `TryGetValOfVar`. This commit fixes the bug by applying `TryGetValOfVar`. * Update with PR link of bugfix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This resolves a bug that was introduced in #16732. If a rewriter function returned a no-op, and the pattern-match continued, then the
matchesprovided to the rewriter function in subsequent calls would contain a variable to which the matched expression was bound, not the matched expression itself. (e.g. For a match ofC = R.add(A,B), passingCto the rewriter instead ofR.add(A,B).)This bug was caused by incorrect re-wrapping of
OrPatterninExprPatternRewriter. Prior to #16732, all pattern-match results were populated byExtractMatchExpr, and contained the result after applyingTryGetValOfVar. When re-wrapping the result of anOrPattern, #16732 populated the additional matches with the result before applyingTryGetValOfVar. This commit fixes the bug by applyingTryGetValOfVar.