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


##########
python/tvm/script/parser/tir/parser.py:
##########
@@ -168,6 +168,28 @@ def find_decorator_annotation(node: doc.FunctionDef, 
annotation: str, default: b
     return default
 
 
+def range_sugar(
+    start: PrimExpr,
+    stop: PrimExpr = None,
+    step: Optional[PrimExpr] = None,
+    *,
+    annotations: Dict[str, Any] = None,
+) -> T.frame.ForFrame:
+    """The sugar for python range builtin."""
+
+    # Since `tir.For` do not support reversed iteration semantic,
+    # the step must be checked to be positive integer when use range sugar
+    if step is not None:
+        try:
+            step = int(step)
+            if step < 0:
+                raise ValueError(f"Only support positive step in range(), get 
{step}")

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   Python's `range()` function does not allow a step of zero. It's better to 
check for this case here and provide a more specific error message, similar to 
Python's behavior. The `CanonicalizeLoop` pass would catch this later, but 
failing early with a more informative message would improve user experience.
   
   ```suggestion
               if step == 0:
                   raise ValueError("range() arg 3 must not be zero")
               if step < 0:
                   raise ValueError(f"Only support positive step in range(), 
get {step}")
   ```



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