Skip to content

Commit c886856

Browse files
author
Tristan Konolige
committed
[TVMScript,Fix] Fix findsource when classes are indented
Leaving class definitions was not correctly handled when recreating scoping information. The fix correctly pops scope whenever the indentation level becomes less than the current scope.
1 parent cec5f0b commit c886856

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

python/tvm/script/parser/core/diagnostics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ def findsource(obj):
163163
name = tokens[1].split(":")[0].split("(")[0] + "<locals>"
164164
elif tokens[0] == "class":
165165
name = tokens[1].split(":")[0].split("(")[0]
166+
while scope_stack and indent_info[scope_stack[-1]] >= indent:
167+
scope_stack.pop()
166168
if name:
167-
while scope_stack and indent_info[scope_stack[-1]] >= indent:
168-
scope_stack.pop()
169169
scope_stack.append(name)
170170
indent_info[name] = indent
171171
if scope_stack == qual_names:

tests/python/unittest/test_tvmscript_parser_source.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,19 @@ def test_source_ast():
8282
assert isinstance(for_block, doc.With) and len(for_block.body) == 2
8383

8484

85+
def test_nesting_parsing():
86+
class dummy:
87+
pass
88+
89+
for i in range(1):
90+
@tvm.script.ir_module
91+
class Module:
92+
@T.prim_func
93+
def impl(
94+
A: T.Buffer[(12, 196, 64), "float32"],
95+
) -> None:
96+
T.evaluate(0)
97+
98+
8599
if __name__ == "__main__":
86100
tvm.testing.main()

0 commit comments

Comments
 (0)