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

[Bugfix][TVMScript] Handle LetStmt for var1 = var2 expressions #14320

Merged
merged 4 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions python/tvm/script/parser/core/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ def exist(self, value: Any) -> bool:
res : bool
The existence of the value.
"""
for v in self.name2value.values():
if v is value:
for value_stack in self.name2value.values():
if value in value_stack:
return True
return False

Expand Down
25 changes: 25 additions & 0 deletions tests/python/unittest/test_tvmscript_syntax_sugar.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,5 +399,30 @@ def implicit(A: T.Buffer(1, "int32")):
assert_structural_equal(implicit, explicit)


def test_preserve_trivial_let_binding():
@T.prim_func
def explicit(i: T.int32):
j = T.int32()
T.LetStmt(i, var=j)
T.evaluate(j)

@T.prim_func
def implicit(i: T.int32):
j = i
T.evaluate(j)

assert_structural_equal(implicit, explicit)


def test_preserve_parameter_name():
@T.prim_func
def func(i: T.int32):
j = i
T.evaluate(j)

param_name = func.params[0].name
assert param_name == "i"


if __name__ == "__main__":
tvm.testing.main()