[Mlir-commits] [mlir] assert with more information to help debug (PR #132194)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Mar 20 04:56:22 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: drazi (fengxie)
<details>
<summary>Changes</summary>
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'>
```
---
Full diff: https://github.com/llvm/llvm-project/pull/132194.diff
1 Files Affected:
- (modified) mlir/python/mlir/dialects/_ods_common.py (+3-4)
``````````diff
diff --git a/mlir/python/mlir/dialects/_ods_common.py b/mlir/python/mlir/dialects/_ods_common.py
index 1e7e8244ed442..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)
+ 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]]
``````````
</details>
https://github.com/llvm/llvm-project/pull/132194
More information about the Mlir-commits
mailing list