slyubomirsky commented on code in PR #16641:
URL: https://github.com/apache/tvm/pull/16641#discussion_r1503451237
##########
python/tvm/script/parser/relax/parser.py:
##########
@@ -274,7 +274,21 @@ def post_visit_local_function(self: Parser, node:
doc.Expr) -> None:
@dispatch.register(token="relax", type_name="Expr")
def visit_expr_stmt(self: Parser, node: doc.Expr) -> None:
value = self.eval_expr(node.value)
- if value is not None:
+ if isinstance(value, relax.Expr):
+ var = R.emit(value)
+ IRBuilder.name("_", var)
+ is_void_value = (
+ isinstance(var.struct_info, relax.TupleStructInfo) and
len(var.struct_info.fields) == 0
+ )
+
+ if not is_void_value:
+ self.report_error(
+ node,
+ f"Non-void relax expressions must be bound to a variable, "
+ f"but expression of type {var.struct_info} was used as a
statement.",
+ )
Review Comment:
I wonder if we should even have this as a rule. Why not let users evaluate
expressions without binding them regardless of their return type?
--
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]