ConvolutedDog commented on code in PR #19583:
URL: https://github.com/apache/tvm/pull/19583#discussion_r3257725676


##########
src/script/printer/ir/ir.cc:
##########
@@ -35,15 +35,24 @@ struct SortableFunction {
       : priority(0), gv(obj.first), func(obj.second) {
     if (gv->name_hint == "main") {
       priority = 1000;
-    } else if (obj.second->GetTypeKey() == "tirx.PrimFunc") {
-      priority = 1;
-    } else if (obj.second->GetTypeKey() == "relax.expr.ExternFunc") {
-      priority = 2;
-    } else if (obj.second->GetTypeKey() == "relax.expr.Function") {
-      priority = 3;
+    } else if (func.defined()) {
+      if (func->GetTypeKey() == "tirx.PrimFunc") {
+        priority = 1;
+      } else if (func->GetTypeKey() == "relax.expr.ExternFunc") {
+        priority = 2;
+      } else if (func->GetTypeKey() == "relax.expr.Function") {
+        priority = 3;
+      } else {
+        TVM_FFI_THROW(TypeError) << "TVMScript cannot print functions of type: 
"
+                                 << func->GetTypeKey();
+      }
     } else {
-      TVM_FFI_THROW(TypeError) << "TVMScript cannot print functions of type: "
-                               << obj.second->GetTypeKey();
+      // PrimFuncPass may leave undefined GlobalVar slots when transforming
+      // this function (see tirx/ir/transform.cc); this transient state may
+      // be encountered during the internal call Dump(mod) executed in
+      // PrimFuncPass during debugging.
+      priority = 999;
+      LOG(INFO) << "Function " << gv->name_hint << " is undefined";
     }

Review Comment:
   `main` is handled once at the top, we always give it priority 1000 when the 
name is "main", whether or not the `BaseFunc` is defined. That matches the 
original intent (print `main` last) and avoids duplicating `gv->name_hint == 
"main"` in the undefined branch. So the minimal fix is: `main` first -> `else 
if (func.defined())` → `else` for transient undefined.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to