fix(compiler): Type inference rewriter: Handle return-like operations correctly #796
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.
Return-like operations require special treatment by the type inference rewriter, since their operand types are both tied to the result types of their producers and to result types of their parent operations.
The inference scheme for ordinary operations, in which the initial local inference state is composed of the operand types of the rewritten producers and the old types of related operations before rewriting is insufficient, since this may result in a mismatch between the inferred types and the actual types of the already rewritten parent operation.
Until now, precedence of the new result types of the parent operation has been implemented by simply designating these types as the operand types of a return-like operation. However, while this works as intended for return-like operations, which simply forward values (e.g.,
func.return
), this creates invalid IR for other return-like operations (e.g.,tensor.yield
).This change implements precedence of the result types of the parent operation of a return-like operation by adding the return types of the already rewritten parent operation to the initial local inference state before final invocation of type inference.