You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "cyx-6 (via GitHub)" <gi...@apache.org> on 2023/01/25 01:16:20 UTC

[GitHub] [tvm] cyx-6 opened a new pull request, #13839: [TVMScript] Comments and docstrings printing

cyx-6 opened a new pull request, #13839:
URL: https://github.com/apache/tvm/pull/13839

   This PR introduces the `CommentDoc` for comments printing and `DocStringDoc` for docstring printing. It enables to add free comments and docstring as `stmt` in printing, e.g.
   ```python
   # comment 1
   # comment 2
   """
   docstring 1
   docstring 2
   """
   ```
   The free here means to not be bound to any `stmt`, but acts as a single `stmt`, similar to `ExprStmtDoc` for `ExprDoc`. 
   
   This PR also introduces an example for the `CommentDoc`, as follow up of #13819.
   In the old printer, we always print a `# with T.block("root"):`, when there is an implicit root block skipped when printing. For example,
   ```
   @T.prim_func
   def main():
     # with T.block("root"):
     a = T.alloc_buffer((128, 128))
     for i, j in T.grid(128, 128):
       with T.block(""):
         ...
   ```
   We bring this syntax reminder back in this PR.


-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] junrushao commented on a diff in pull request #13839: [TVMScript] Comments and docstrings printing

Posted by "junrushao (via GitHub)" <gi...@apache.org>.
junrushao commented on code in PR #13839:
URL: https://github.com/apache/tvm/pull/13839#discussion_r1086976751


##########
src/script/printer/doc_printer/python_doc_printer.cc:
##########
@@ -642,11 +652,40 @@ void PythonDocPrinter::PrintTypedDoc(const ClassDoc& doc) {
   NewLineWithoutIndent();
 }
 
+void PythonDocPrinter::PrintTypedDoc(const CommentDoc& doc) {
+  if (doc->comment.defined()) {
+    MaybePrintCommenMultiLines(doc, false);
+  }
+}
+
+void PythonDocPrinter::PrintTypedDoc(const DocStringDoc& doc) {
+  if (doc->comment.defined() && !doc->comment.value().empty()) {
+    output_ << "\"\"\"" << doc->comment.value() << "\"\"\"";
+  }
+}
+
 String DocToPythonScript(Doc doc, const PrinterConfig& cfg) {
   if (cfg->num_context_lines < 0) {
     cfg->num_context_lines = std::numeric_limits<int32_t>::max();
   }
   PythonDocPrinter printer(cfg);
+  if (cfg->print_headers) {
+    Array<StmtDoc> headers;
+    if (cfg->ir_usage.count("ir")) {
+      headers.push_back(CommentDoc("from tvm.script import ir as " + cfg->ir_prefix));
+    }
+    if (cfg->ir_usage.count("tir")) {
+      headers.push_back(CommentDoc("from tvm.script import tir as " + cfg->tir_prefix));
+    }
+    if (cfg->ir_usage.count("relax")) {
+      headers.push_back(CommentDoc("from tvm.script import relax as " + cfg->relax_prefix));
+    }
+    if (headers.size()) {
+      // Add a blank line between headers and script codes
+      headers.push_back(CommentDoc(""));
+    }
+    printer.Append(StmtBlockDoc(headers));
+  }

Review Comment:
   We should move this logic to the caller site :-)



-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] junrushao merged pull request #13839: [TVMScript] Comments and docstrings printing

Posted by "junrushao (via GitHub)" <gi...@apache.org>.
junrushao merged PR #13839:
URL: https://github.com/apache/tvm/pull/13839


-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] tvm-bot commented on pull request #13839: [TVMScript] Comments and docstrings printing

Posted by "tvm-bot (via GitHub)" <gi...@apache.org>.
tvm-bot commented on PR #13839:
URL: https://github.com/apache/tvm/pull/13839#issuecomment-1402913394

   <!---bot-comment-->
   
   Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from [Reviewers](https://github.com/apache/incubator-tvm/blob/master/CONTRIBUTORS.md#reviewers) by @-ing them in a comment.
   
   <!--bot-comment-ccs-start-->
    * cc @junrushao <sub>See [#10317](https://github.com/apache/tvm/issues/10317) for details</sub><!--bot-comment-ccs-end-->
   
   <sub>Generated by [tvm-bot](https://github.com/apache/tvm/blob/main/ci/README.md#github-actions)</sub>


-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org