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

tqchen pushed a commit to branch tqchen/printer-refinement
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/tqchen/printer-refinement by 
this push:
     new d973228323 [FIX][Script] Use native translator adapter and variable 
destinations
d973228323 is described below

commit d973228323186ec9d71d47386d580e6f5d8b3622
Author: Tianqi Chen <[email protected]>
AuthorDate: Thu Oct 1 16:08:01 2026 +0000

    [FIX][Script] Use native translator adapter and variable destinations
    
    Keep public translation destinations as Var objects and give the native 
dispatch adapter a named function with static linkage.
---
 src/script/printer/doc_translator.cc | 10 ++++++----
 src/tirx/script/printer/expr.cc      |  2 +-
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/script/printer/doc_translator.cc 
b/src/script/printer/doc_translator.cc
index 7cc3a0fb91..a2fe6ce197 100644
--- a/src/script/printer/doc_translator.cc
+++ b/src/script/printer/doc_translator.cc
@@ -126,12 +126,14 @@ class TranslationEngine : public DocTranslatorObj {
     return reinterpret_cast<typename View::ABIType>(
         ffi::Any(View::template FromNative<Function>()).template 
cast<void*>());
   }
+  static ffi::Optional<ExprDoc> Dispatch(DocTranslatorObj* d, ffi::AnyView 
value,
+                                         const ffi::Object* destination) {
+    return d->DefaultTranslate(value, destination);
+  }
   static const DocTranslatorVTable* VTable() {
     static const DocTranslatorVTable table{
         Adapter<ffi::Optional<ExprDoc>(DocTranslatorObj*, ffi::AnyView, const 
ffi::Object*),
-                [](DocTranslatorObj* d, ffi::AnyView value, const ffi::Object* 
destination) {
-                  return d->DefaultTranslate(value, destination);
-                }>(),
+                &Dispatch>(),
         Adapter<IdDoc(DocTranslatorObj*, ffi::AnyView), &Allocate>(),
         Adapter<IdDoc(DocTranslatorObj*, ffi::AnyView, bool), 
&GetOrAllocate>(),
         Adapter<ffi::Dict<Var, IdDoc>(DocTranslatorObj*), 
&ImplicitDefinitions>(),
@@ -191,7 +193,7 @@ details::TranslationResult TranslateComplete(ffi::AnyView 
obj, TranslationEngine
               [](const auto& a, const auto& b) { return a.second->name < 
b.second->name; });
     for (const auto& [var, _] : remaining) {
       if (!pending.count(var)) continue;
-      if (auto rhs = engine->Translate(var, var.get())) {
+      if (auto rhs = engine->Translate(var, var)) {
         engine->Emit(AssignDoc(engine->VarGetOrAllocId(var, true), 
rhs.value(), std::nullopt), var);
       }
     }
diff --git a/src/tirx/script/printer/expr.cc b/src/tirx/script/printer/expr.cc
index 0b6b3e0a4a..9f9d4974a3 100644
--- a/src/tirx/script/printer/expr.cc
+++ b/src/tirx/script/printer/expr.cc
@@ -69,7 +69,7 @@ ffi::Optional<ExprDoc> VarDocTranslate(DocTranslatorObj* d, 
ffi::AnyView input,
     ffi::StructuralWalk<ffi::WalkOrder::kPreOrder>(
         var->ty, [&](const Var& dependency) -> ffi::Expected<ffi::WalkResult> {
           if (d->GetImplicitDefs().count(dependency)) {
-            if (auto rhs = d->Translate(dependency, dependency.get())) {
+            if (auto rhs = d->Translate(dependency, dependency)) {
               d->Emit(AssignDoc(VarDoc(d, dependency), rhs.value(), 
std::nullopt), dependency);
             }
           }

Reply via email to