[Mlir-commits] [mlir] [tblgen] Use `emitError` for inferResultTypes failures (PR #165488)
Stef Lindall
llvmlistbot at llvm.org
Wed Oct 29 11:17:58 PDT 2025
bethebunny wrote:
The context here is using MLIR through FFI, in particular I heavily use MLIR through Python bindings. When MLIR asserts, it crashes the python compiler with not stack trace, so instead for op creation failures we take the diagnostics and raise them as a Python exception.
For instance the generic `Operation::create` doesn't assert. It's generally not fallible, the contract as I understand it is to create the op and then call `verify` which uses `emitError` to report failures.
In the MLIR C API, since inferring result types may fail, the contract is to [return a null Operation](https://github.com/llvm/llvm-project/blob/main/mlir/lib/CAPI/IR/IR.cpp#L615-L623) rather than assert.
> What folks do here sometimes is two step, infer result type and then build (if valid) with explicit type. That could be made into a helper.
I think that's exactly what the generated builders for inferred result types do. My goal here is to be able to use the generated builders rather than expect to have to explicitly write all builders for inferred result types. Additionally we sometimes define custom builders which call generated builders, and we would need to take care to never call generated builders in that case.
https://github.com/llvm/llvm-project/pull/165488
More information about the Mlir-commits
mailing list