[Mlir-commits] [mlir] assert with more information to help debug (PR #132194)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Mar 20 04:55:47 PDT 2025
https://github.com/fengxie created https://github.com/llvm/llvm-project/pull/132194
This PR output debug message to assertion to help debug user python code. Will print out more friendly information
```
> assert isinstance(arg, _cext.ir.Value), f"expects Value, got {type(arg)}"
E AssertionError: expected Value, got <class 'UserDefinedClass'>
```
>From b30db3ec33e043733f9872f240f26d439c23b7a8 Mon Sep 17 00:00:00 2001
From: Fung Xie <ftse at nvidia.com>
Date: Thu, 20 Mar 2025 19:50:28 +0800
Subject: [PATCH 1/2] assert with more information to help debug
---
mlir/python/mlir/dialects/_ods_common.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/python/mlir/dialects/_ods_common.py b/mlir/python/mlir/dialects/_ods_common.py
index 1e7e8244ed442..0b320cee12fcb 100644
--- a/mlir/python/mlir/dialects/_ods_common.py
+++ b/mlir/python/mlir/dialects/_ods_common.py
@@ -104,7 +104,7 @@ def get_op_result_or_value(
elif isinstance(arg, _cext.ir.OpResultList):
return arg[0]
else:
- assert isinstance(arg, _cext.ir.Value)
+ assert isinstance(arg, _cext.ir.Value), f"expected Value, got {type(arg)}"
return arg
>From 43bc949c5859674f6f021a2ebc4a4ae4119795ca Mon Sep 17 00:00:00 2001
From: Fung Xie <ftse at nvidia.com>
Date: Thu, 20 Mar 2025 19:55:12 +0800
Subject: [PATCH 2/2] fix a typo
---
mlir/python/mlir/dialects/_ods_common.py | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/mlir/python/mlir/dialects/_ods_common.py b/mlir/python/mlir/dialects/_ods_common.py
index 0b320cee12fcb..11c363abe2ecd 100644
--- a/mlir/python/mlir/dialects/_ods_common.py
+++ b/mlir/python/mlir/dialects/_ods_common.py
@@ -104,7 +104,7 @@ def get_op_result_or_value(
elif isinstance(arg, _cext.ir.OpResultList):
return arg[0]
else:
- assert isinstance(arg, _cext.ir.Value), f"expected Value, got {type(arg)}"
+ assert isinstance(arg, _cext.ir.Value), f"expects Value, got {type(arg)}"
return arg
@@ -137,11 +137,10 @@ def get_op_result_or_op_results(
return (
list(get_op_results_or_values(op))
if len(op.results) > 1
- else get_op_result_or_value(op)
- if len(op.results) > 0
- else op
+ else get_op_result_or_value(op) if len(op.results) > 0 else op
)
+
ResultValueTypeTuple = _cext.ir.Operation, _cext.ir.OpView, _cext.ir.Value
ResultValueT = _Union[ResultValueTypeTuple]
VariadicResultValueT = _Union[ResultValueT, _Sequence[ResultValueT]]
More information about the Mlir-commits
mailing list