[Mlir-commits] [mlir] [MLIR][Python] Add more field specifiers to Python-defined operations (PR #188064)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Mar 26 09:22:25 PDT 2026
================
@@ -777,3 +819,59 @@ class OpWithAttr(TestAttrInOp.Operation, name="op_with_attr"):
# CHECK: "ext_attr_in_op.op_with_attr"() {a = 42 : i32, b = i32} : () -> ()
# CHECK: "ext_attr_in_op.op_with_attr"() {a = "hello", b = i64} : () -> ()
print(module)
+
+
+ at run
+def testExtDialectFieldSpecifiers():
+ class TestFieldSpecifiers(Dialect, name="ext_field_specifiers"):
+ pass
+
+ class OperandSpecifierOp(TestFieldSpecifiers.Operation, name="operand_specifier"):
+ a: Operand[IntegerType[32]] = operand()
+ b: Optional[Operand[IntegerType[32]]] = None
+ c: Operand[IntegerType[32]] = operand(kw_only=True)
+
+ class ResultSpecifierOp(TestFieldSpecifiers.Operation, name="result_specifier"):
+ a: Result[IntegerType[32]] = result()
+ b: Result[IntegerType[16]] = result(infer_type=True)
+ c: Result[IntegerType] = result(
+ default_factory=lambda: IntegerType.get_signless(8)
+ )
+ d: Sequence[Result[IntegerType]] = result(default_factory=list)
+ e: Result[IntegerType[32]] = result(kw_only=True)
----------------
PragmaTwice wrote:
Yup. But there is an issue about `kw_only`.
The default value of `kw_only` is `False`, and it will be set to `True` internally if `default_factory` is not None.
So if you write `default_factory=lambda:..., kw_only=False`, then `kw_only=False` will be ignored.
https://github.com/llvm/llvm-project/pull/188064
More information about the Mlir-commits
mailing list