You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/12/18 09:01:22 UTC

[GitHub] [tvm] lightzhan-intellif commented on a diff in pull request #13640: [BugFix][TVMScript]fix var capturing order error.

lightzhan-intellif commented on code in PR #13640:
URL: https://github.com/apache/tvm/pull/13640#discussion_r1051557843


##########
tests/python/unittest/test_tvmscript_regression.py:
##########
@@ -58,7 +58,24 @@ def func_ref():
     tvm.ir.assert_structural_equal(test_case, func_ref)
 
 
+def test_var_capturing_order():
+    b = 2
+
+    @T.prim_func
+    def test_case():
+        k: T.int32 = b
+
+    @T.prim_func
+    def func_ref():
+        k: T.int32 = 2
+        T.evaluate(0)
+
+    tvm.ir.assert_structural_equal(test_case, func_ref)
+
+
 if __name__ == "__main__":
+    b = 1

Review Comment:
   Yea, I've moved it!
   
   > what is the behavior when there are nested closures?
   
   I just had a test:
   ```python
   def test_var():
       a = 1
       def test_var_0():
           a = 2
           @T.prim_func
           def test_case():
               k: T.int32 = a
           
           return test_case
       
       print(test_var_0().script())
   ```
   Call `test_var` and get the output:
   ```
   # from tvm.script import tir as T
   @T.prim_func
   def func():
       # body
       k: T.int32 = 2
       T.evaluate(0)
   ```
   It works as our expectation!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org