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

tqchen pushed a commit to branch script/canonical-parser-df
in repository https://gitbox.apache.org/repos/asf/tvm.git

commit 203dcebb9d56fc4379160289f82532cf69065394
Author: Tianqi Chen <[email protected]>
AuthorDate: Wed Sep 23 04:24:51 2026 +0000

    Quote symbolic shapes until their Python parameters are bound
---
 src/tirx/script/printer/buffer.cc   |  7 -------
 src/tirx/script/printer/function.cc | 12 +++---------
 src/tirx/script/printer/utils.h     |  4 ++--
 3 files changed, 5 insertions(+), 18 deletions(-)

diff --git a/src/tirx/script/printer/buffer.cc 
b/src/tirx/script/printer/buffer.cc
index 0b37da6e3d..d9d866e79a 100644
--- a/src/tirx/script/printer/buffer.cc
+++ b/src/tirx/script/printer/buffer.cc
@@ -94,9 +94,7 @@ ffi::Map<ffi::String, ExprDoc> BufferAttrs(
       AccessPath e_p = shape_p->ArrayItem(i);
       bool contains_new_var = false;
       bool contains_compound_shape_var = false;
-      std::unordered_set<Var> vars_in_shape;
       auto walk_fn = [&](const Var& var) -> ffi::Expected<ffi::WalkResult> {
-        vars_in_shape.insert(var);
         contains_new_var =
             contains_new_var || !d->IsVarDefined(var) || 
stringify_shape_vars.count(var);
         contains_compound_shape_var =
@@ -114,11 +112,6 @@ ffi::Map<ffi::String, ExprDoc> BufferAttrs(
       results.push_back((stringify_undefined_shape && contains_new_var) || 
stringify_compound_expr
                             ? ExprStringDoc(result, e_p)
                             : result);
-      // A quoted shape expression defines every Var it contains.  Do not quote
-      // later dimensions merely because they reuse a Var introduced here.
-      for (const Var& var : vars_in_shape) {
-        stringify_shape_vars.erase(var);
-      }
     }
     kwargs.Set("shape", TupleDoc(results));
   }
diff --git a/src/tirx/script/printer/function.cc 
b/src/tirx/script/printer/function.cc
index 7e37317a74..8cb05af4a3 100644
--- a/src/tirx/script/printer/function.cc
+++ b/src/tirx/script/printer/function.cc
@@ -80,8 +80,8 @@ TVM_FFI_STATIC_INIT_BLOCK() {
         std::unordered_map<const tirx::VarNode*, ExprDoc> scalar_param_docs;
         // Define scalar docs up front so a preceding Buffer parameter can 
render
         // a reference to a later scalar parameter.  `bound_signature_vars`
-        // separately tracks source order: the first shape expression that sees
-        // an unbound Var must be quoted because Buffer shapes are match 
scopes.
+        // separately tracks Python bindings in source order. Quoted shapes
+        // resolve native symbols without binding their names in Python.
         std::unordered_set<tirx::Var> bound_signature_vars;
         for (const tirx::Var& param : func->params) {
           if (!param->ty.as<tirx::BufferTypeNode>()) {
@@ -95,12 +95,9 @@ TVM_FFI_STATIC_INIT_BLOCK() {
             tirx::BufferVar buffer(var);
             std::unordered_set<tirx::Var> stringify_shape_vars;
             std::unordered_set<tirx::Var> stringify_compound_shape_vars;
-            std::unordered_set<tirx::Var> shape_vars;
             auto walk_fn = [&](const tirx::Var& shape_var) -> 
ffi::Expected<ffi::WalkResult> {
-              shape_vars.insert(shape_var);
               bool is_type_var = type_vars.count(shape_var.get());
-              if (!use_postponed_annotations && 
!bound_signature_vars.count(shape_var) &&
-                  !is_type_var) {
+              if (!bound_signature_vars.count(shape_var) && !is_type_var) {
                 stringify_shape_vars.insert(shape_var);
               }
               if (!use_postponed_annotations && is_type_var) {
@@ -116,9 +113,6 @@ TVM_FFI_STATIC_INIT_BLOCK() {
                 BufferAttn(buffer, var_p->Attr("ty"), *f, d, 
std::move(stringify_shape_vars),
                            std::move(stringify_compound_shape_vars));
             args.push_back(AssignDoc(lhs, std::nullopt, annotation));
-            for (const tirx::Var& shape_var : shape_vars) {
-              bound_signature_vars.insert(shape_var);
-            }
             continue;
           }
           ExprDoc a = d->AsDoc<ExprDoc>(var->ty, var_p->Attr("ty"));
diff --git a/src/tirx/script/printer/utils.h b/src/tirx/script/printer/utils.h
index 172b4e88f9..fca09c45b5 100644
--- a/src/tirx/script/printer/utils.h
+++ b/src/tirx/script/printer/utils.h
@@ -322,8 +322,8 @@ ExprDoc BufferDecl(const tirx::BufferVar& buffer, const 
ffi::String& method,
  * \param p The object path
  * \param f The frame
  * \param d The IRDocsifier
- * \param stringify_shape_vars Variables whose first shape use must be 
stringified.  The set is
- *     passed by value so entries can be consumed as dimensions are emitted.
+ * \param stringify_shape_vars Variables without a Python binding at this 
annotation. Every
+ *     shape expression containing one of these variables must be stringified.
  * \param stringify_compound_shape_vars Variables whose compound shape 
expressions must be
  *     stringified while their bare-name uses remain direct.
  * \return The ExprDoc corresponding to the buffer declaration

Reply via email to