Skip to content

IRDLOperation definition failed when more than one optional operand #4504

@ice-tong

Description

@ice-tong

Thank so much for the xDSL project! xDSL has made it much easier for people to start developing MLIR, which is a really great achievement!

When I was looking into xDSL development recently, I had a problem when I tried to define operations with more than two optional operands, which caused unexpected errors. I'm not sure if this is what was expected.

Below is a small piece of code that shows the problem:

from xdsl.dialects.builtin import *
from xdsl.ir import *
from xdsl.irdl import *

@irdl_op_definition
class TestOp(IRDLOperation):
    name = "test.op"

    input1 = opt_operand_def(AnyAttr())
    input2 = opt_operand_def(AnyAttr())

    output = result_def(AnyAttr())

We got the following error message. We might be treating the optional operand like the variadic operand when we check multiple variadic operands.

❯ python test_opt_operand_def.py
Traceback (most recent call last):
  File "/xxx/test_opt_operand_def.py", line 7, in <module>
    class TestOp(IRDLOperation):
  File "/xxx/xdsl/irdl/operations.py", line 2048, in irdl_op_definition
    new_attrs = get_accessors_from_op_def(op_def, getattr(cls, "verify_", None))
  File "/xxx/xdsl/xdsl/irdl/operations.py", line 1959, in get_accessors_from_op_def
    irdl_op_arg_definition(new_attrs, VarIRConstruct.OPERAND, op_def)
  File "/xxx/xdsl/irdl/operations.py", line 1891, in irdl_op_arg_definition
    raise PyRDLOpDefinitionError(
xdsl.utils.exceptions.PyRDLOpDefinitionError: Operation test.op defines more than two variadic operands, but do not define any of SameVariadicOperandSize or AttrSizedOperandSegments PyRDL options.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions