mirror of
https://github.com/intel/llvm.git
synced 2026-01-13 11:02:04 +08:00
[mlir][python] Propagate error diagnostics when an op couldn't be created. (#169499)
This commit is contained in:
committed by
GitHub
parent
83d9c636b7
commit
012721d320
@@ -1411,9 +1411,10 @@ nb::object PyOperation::create(std::string_view name,
|
||||
}
|
||||
|
||||
// Construct the operation.
|
||||
PyMlirContext::ErrorCapture errors(location.getContext());
|
||||
MlirOperation operation = mlirOperationCreate(&state);
|
||||
if (!operation.ptr)
|
||||
throw nb::value_error("Operation creation failed");
|
||||
throw MLIRError("Operation creation failed", errors.take());
|
||||
PyOperationRef created =
|
||||
PyOperation::createDetached(location.getContext(), operation);
|
||||
maybeInsertOperation(created, maybeIp);
|
||||
|
||||
@@ -5,7 +5,7 @@ import io
|
||||
from tempfile import NamedTemporaryFile
|
||||
from mlir.ir import *
|
||||
from mlir.dialects.builtin import ModuleOp
|
||||
from mlir.dialects import arith, func, scf
|
||||
from mlir.dialects import arith, func, scf, shape
|
||||
from mlir.dialects._ods_common import _cext
|
||||
from mlir.extras import types as T
|
||||
|
||||
@@ -774,6 +774,21 @@ def testKnownOpView():
|
||||
print(repr(constant))
|
||||
|
||||
|
||||
# CHECK-LABEL: TEST: testFailedGenericOperationCreationReportsError
|
||||
@run
|
||||
def testFailedGenericOperationCreationReportsError():
|
||||
with Context(), Location.unknown():
|
||||
c0 = shape.const_shape([])
|
||||
c1 = shape.const_shape([1, 2, 3])
|
||||
try:
|
||||
shape.MeetOp.build_generic(operands=[c0, c1])
|
||||
except MLIRError as e:
|
||||
# CHECK: unequal shape cardinality
|
||||
print(e)
|
||||
else:
|
||||
assert False, "Expected exception"
|
||||
|
||||
|
||||
# CHECK-LABEL: TEST: testSingleResultProperty
|
||||
@run
|
||||
def testSingleResultProperty():
|
||||
|
||||
Reference in New Issue
Block a user