slyubomirsky commented on code in PR #14394:
URL: https://github.com/apache/tvm/pull/14394#discussion_r1151352245


##########
src/script/printer/relax/call.cc:
##########
@@ -132,13 +132,75 @@ Optional<ExprDoc> PrintCallTIRDPSPacked(const 
relax::Call& n, const ObjectPath&
   return Relax(d, "call_tir")->Call(args, kwargs_keys, kwargs_values);
 }
 
+Optional<ExprDoc> PrintCallPure(const relax::Call& n, const ObjectPath& n_p, 
const IRDocsifier& d) {
+  static const Op& call_pure_op = Op::Get("relax.call_pure");
+  if (!n->op.same_as(call_pure_op)) {
+    return NullOpt;
+  }
+  ICHECK(n->args.size() >= 1);
+  // just wrap R.call_pure around the inner call
+  auto inner_call = UnwrapCallPure(n);
+  auto inner_call_doc = d->AsDoc<ExprDoc>(inner_call, 
n_p->Attr("args")->ArrayIndex(0));
+  return Relax(d, "call_pure")->Call({inner_call_doc});
+}
+
+Optional<ExprDoc> PrintAssertOp(const relax::Call& n, const ObjectPath& n_p, 
const IRDocsifier& d) {
+  static const Op& assert_op = Op::Get("relax.assert_op");
+  if (!n->op.same_as(assert_op)) {
+    return NullOpt;
+  }
+  ICHECK(n->args.size() >= 2);
+  // special handling: it is important to indicate that the format string 
(second argument)
+  // is the _format_ string, or else roundtripping will fail
+  // (the format string will be interpreted as an argument and there will be a 
new default format
+  // string given)
+  Array<ExprDoc> args;
+  args.push_back(d->AsDoc<ExprDoc>(n->args[0], 
n_p->Attr("args")->ArrayIndex(0)));
+  ExprDoc second_arg = d->AsDoc<ExprDoc>(n->args[1], 
n_p->Attr("args")->ArrayIndex(1));
+  for (size_t i = 2; i < n->args.size(); i++) {
+    args.push_back(d->AsDoc<ExprDoc>(n->args[i], 
n_p->Attr("args")->ArrayIndex(i)));
+  }
+  return Relax(d, "assert_op")->Call(args, {"format"}, {second_arg});
+}
+
+Optional<ExprDoc> PrintRelaxPrint(const relax::Call& n, const ObjectPath& n_p,
+                                  const IRDocsifier& d) {
+  static const Op& print_op = Op::Get("relax.print");
+  if (!n->op.same_as(print_op)) {
+    return NullOpt;
+  }
+  ICHECK(n->args.size() >= 1);
+  // special handling: it is important to indicate that the format string 
(first argument)
+  // is the _format_ string, or else roundtripping will fail
+  // (the format string will be interpreted as an argument and there will be a 
new default format
+  // string given)
+  ExprDoc first_arg = d->AsDoc<ExprDoc>(n->args[0], 
n_p->Attr("args")->ArrayIndex(0));
+  Array<ExprDoc> args;
+  for (size_t i = 1; i < n->args.size(); i++) {
+    args.push_back(d->AsDoc<ExprDoc>(n->args[i], 
n_p->Attr("args")->ArrayIndex(i)));
+  }
+  return Relax(d, "print")->Call(args, {"format"}, {first_arg});
+}

Review Comment:
   One would think this isn't related to these changes at all, but in the 
process of testing roundtripping for `call_pure`, I discovered roundtripping 
bugs for `print` and `assert_op` (both having to do with their format strings).



-- 
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]

Reply via email to