You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by tq...@apache.org on 2026/09/21 14:36:58 UTC
(tvm) 12/33: Preserve Relax standalone expression semantics
This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch tvmscript-generic-parser-builder
in repository https://gitbox.apache.org/repos/asf/tvm.git
commit 5280a423c315850f395a515cc5eceeac1c2c4df9
Author: Tianqi Chen <tq...@users.noreply.github.com>
AuthorDate: Mon Sep 21 01:15:19 2026 +0000
Preserve Relax standalone expression semantics
---
python/tvm/relax/script/builder_v2/__init__.py | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/python/tvm/relax/script/builder_v2/__init__.py b/python/tvm/relax/script/builder_v2/__init__.py
index 066de66265..34cd2124fc 100644
--- a/python/tvm/relax/script/builder_v2/__init__.py
+++ b/python/tvm/relax/script/builder_v2/__init__.py
@@ -302,9 +302,17 @@ def bind_(
def emit_(value, *, span=None):
- """Consume an expression statement; effect-only operations return None."""
- if value is not None:
- bind_(value, span=span)
+ """Emit a void expression statement, retaining effect-only operations returning None."""
+ if value is None:
+ return
+ if not isinstance(value, _relax.Expr):
+ raise TypeError(f"Unsupported expression statement value: {type(value).__name__}")
+ result = bind_(value, name="_", span=span)
+ if not isinstance(result.ty, _ir.TupleType) or len(result.ty.fields) != 0:
+ raise ValueError(
+ "Non-void expressions must be bound to a variable; "
+ f"expression of type {result.ty} was used as a statement"
+ )
def return_(value=None, *, span=None):