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

fix(compiler): Type inference rewriter: Handle return-like operations correctly #796

Merged
merged 1 commit into from
Apr 19, 2024

Conversation

andidr
Copy link
Contributor

@andidr andidr commented Apr 19, 2024

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.

… correctly

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.
@BourgerieQuentin BourgerieQuentin merged commit e238067 into main Apr 19, 2024
28 of 29 checks passed
@BourgerieQuentin BourgerieQuentin deleted the andi/type-inference-fixes branch April 19, 2024 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants