This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch tvmscript-generic-parser-builder
in repository https://gitbox.apache.org/repos/asf/tvm.git

commit 3ffbdc6680c6ea3c7bdcea49cee0c7538650b8d5
Author: Tianqi Chen <[email protected]>
AuthorDate: Mon Sep 21 03:41:27 2026 +0000

    Keep macro capture hygiene distinct from inline closure binding
---
 python/tvm/script/parser_v2/frontend.py | 6 +++---
 python/tvm/tirx/script/v2.py            | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/python/tvm/script/parser_v2/frontend.py 
b/python/tvm/script/parser_v2/frontend.py
index 9229213baa..cbf325bbb6 100644
--- a/python/tvm/script/parser_v2/frontend.py
+++ b/python/tvm/script/parser_v2/frontend.py
@@ -127,8 +127,8 @@ def make_decorator(builder, *, option_map=None, 
defaults=None):
     )
 
 
-def make_helper(builder, *, preserve_return=True):
-    """Create an explicit construction helper using the active shared 
builder."""
+def make_helper(builder, *, preserve_return=True, late_binding=False):
+    """Create a construction helper, optionally retaining live Python closure 
cells."""
 
     def decorator(function=None, **options):
         if function is not None and not inspect.isfunction(function):
@@ -142,7 +142,7 @@ def make_helper(builder, *, preserve_return=True):
                 bound = inspect.signature(function).bind(*args, **kwargs)
                 bound.apply_defaults()
                 environment = (
-                    {**definition_env, **_closure_values(function)}
+                    {**definition_env, **(_closure_values(function) if 
late_binding else {})}
                     if options.get("hygienic", True)
                     else _capture(function)
                 )
diff --git a/python/tvm/tirx/script/v2.py b/python/tvm/tirx/script/v2.py
index de66be6956..bfdc129210 100644
--- a/python/tvm/tirx/script/v2.py
+++ b/python/tvm/tirx/script/v2.py
@@ -38,7 +38,7 @@ tile = _tile
 prim_func = _make_decorator(
     _builder, option_map={"private": "private", "s_tir": "s_tir", 
"persistent": "persistent"}
 )
-inline = _make_helper(_builder, preserve_return=True)
+inline = _make_helper(_builder, preserve_return=True, late_binding=True)
 macro = _make_helper(_builder, preserve_return=False)
 
 _register_namespace("T", _sys.modules[__name__])

Reply via email to