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

[Relax] Normalize use of void-type variable to inline R.tuple() #16658

Merged

Conversation

Lunderberg
Copy link
Contributor

This is a follow-up commit to #16641. While parsing of relax expressions without a variable binding could be implemented at that point (e.g. R.assert_op(condition) instead of dummy_var = R.assert_op(condition)), the corresponding printing changes could not. This was because a variable that satisfies relax::HasVoidStructInfo(var) could still be used later in the function, and removing its binding would result in use of an undefined variable.

This commit normalizes use of void-type variables to an in-line R.tuple(). This simplifies the relax function, and also allows the binding of void-type variables to be hidden.

@Lunderberg
Copy link
Contributor Author

This commit includes #16641 in its history, and is marked as a draft until #16641 lands.

Copy link
Contributor

@slyubomirsky slyubomirsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be good for avoiding the tricky situation that arises with #16641, mainly where it can be a problem to omit the binding of a unit-type variable if the var is used later. I think it's pretty harmless to simply inline all unit values.

This is a follow-up commit to
apache#16641.  While parsing of relax
expressions without a variable binding could be implemented at that
point (e.g. `R.assert_op(condition)` instead of `dummy_var =
R.assert_op(condition)`), the corresponding printing changes could
not.  This was because a variable that satisfies
`relax::HasVoidStructInfo(var)` could still be used later in the
function, and removing its binding would result in use of an undefined
variable.

This commit normalizes use of void-type variables to an in-line
`R.tuple()`.  This simplifies the relax function, and also allows the
binding of void-type variables to be hidden.
@Lunderberg Lunderberg force-pushed the relax_normalize_use_of_void_variable branch from edddfc3 to 844f06c Compare March 12, 2024 15:37
@Lunderberg Lunderberg marked this pull request as ready for review March 12, 2024 15:37
@Lunderberg Lunderberg changed the title [Draft][Relax] Normalize use of void-type variable to inline R.tuple() [Relax] Normalize use of void-type variable to inline R.tuple() Mar 12, 2024
@Lunderberg
Copy link
Contributor Author

I think it's pretty harmless to simply inline all unit values.

Agreed, and it matches our existing behavior for things like R.ExternFunc and R.const.

@Lunderberg Lunderberg merged commit 8023a98 into apache:main Mar 13, 2024
18 checks passed
@Lunderberg Lunderberg deleted the relax_normalize_use_of_void_variable branch March 13, 2024 21:52
thaisacs pushed a commit to thaisacs/tvm that referenced this pull request Apr 3, 2024
…he#16658)

* [Relax] Normalize use of void-type variable to inline R.tuple()

This is a follow-up commit to
apache#16641.  While parsing of relax
expressions without a variable binding could be implemented at that
point (e.g. `R.assert_op(condition)` instead of `dummy_var =
R.assert_op(condition)`), the corresponding printing changes could
not.  This was because a variable that satisfies
`relax::HasVoidStructInfo(var)` could still be used later in the
function, and removing its binding would result in use of an undefined
variable.

This commit normalizes use of void-type variables to an in-line
`R.tuple()`.  This simplifies the relax function, and also allows the
binding of void-type variables to be hidden.

* Fix breakage in unit tests
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.

None yet

2 participants