gemini-code-assist[bot] commented on code in PR #18857:
URL: https://github.com/apache/tvm/pull/18857#discussion_r2869208322


##########
src/target/source/codegen_c.cc:
##########
@@ -1079,12 +1079,45 @@ void CodeGenC::VisitStmt_(const AttrStmtNode* op) {
   this->PrintStmt(op->body);
 }
 
+void CodeGenC::PrintEscapedCString(const std::string& str, std::ostream& os) {
+  os << "\"";
+  for (char c : str) {
+    if (c == '"') {
+      os << "\\\"";
+    } else if (c == '\\') {
+      os << "\\\\";
+    } else if (c == '\n') {
+      os << "\\n";
+    } else {
+      os << c;
+    }
+  }
+  os << "\"";
+}

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The `PrintEscapedCString` helper function is a great addition for robust 
string literal generation. To make it even more comprehensive, consider 
handling other common C escape sequences like `\t` (tab) and `\r` (carriage 
return). Using a `switch` statement could also make the implementation cleaner 
and more extensible for any future additions.
   
   ```c
   void CodeGenC::PrintEscapedCString(const std::string& str, std::ostream& os) 
{
     os << "\"";
     for (char c : str) {
       switch (c) {
         case '"':
           os << "\\\"";
           break;
         case '\\':
           os << "\\\\";
           break;
         case '\n':
           os << "\\n";
           break;
         case '\t':
           os << "\\t";
           break;
         case '\r':
           os << "\\r";
           break;
         default:
           os << c;
           break;
       }
     }
     os << "\"";
   }
   ```



##########
python/tvm/script/ir_builder/tir/ir.py:
##########
@@ -920,16 +920,21 @@ def grid(*extents: PrimExpr) -> frame.ForFrame:
     return _ffi_api.Grid(extents)  # type: ignore[attr-defined] # pylint: 
disable=no-member
 
 
-def Assert(condition: PrimExpr, message: str) -> frame.AssertFrame:  # pylint: 
disable=invalid-name
+def Assert(condition: PrimExpr, message, kind: str = "RuntimeError") -> 
frame.AssertFrame:  # pylint: disable=invalid-name
     """Create an assertion statement.
 
     Parameters
     ----------
     condition : PrimExpr
         The PrimExpr to test.
 
-    message : str
-        The output error message when the assertion fails.
+    message : str or list[str]
+        The error message when the assertion fails. Can be a single string
+        or a list of string parts (fragments stored separately in the IR
+        for binary size reduction through string reuse).
+
+    kind : str
+        The error kind (e.g. "RuntimeError", "TypeError", "ValueError").

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   For better type safety and clarity, it would be beneficial to provide a more 
specific type hint for the `message` parameter. The current implementation 
handles `str`, `list`, and `tuple`, but the type hint is missing and the 
docstring only mentions `list`. A type hint like `str | list[str] | tuple[str, 
...]` would be more accurate. Also, updating the docstring to include `tuple` 
would improve consistency.
   
   ```suggestion
   def Assert(condition: PrimExpr, message: str | list[str] | tuple[str, ...], 
kind: str = "RuntimeError") -> frame.AssertFrame:  # pylint: 
disable=invalid-name
       """Create an assertion statement.
   
       Parameters
       ----------
       condition : PrimExpr
           The PrimExpr to test.
   
       message : str | list[str] | tuple[str, ...]
           The error message when the assertion fails. Can be a single string
           or a list or tuple of string parts (fragments stored separately in 
the IR
           for binary size reduction through string reuse).
   
       kind : str
           The error kind (e.g. "RuntimeError", "TypeError", "ValueError").
   ```



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