[Mlir-commits] [mlir] [MLIR][Python] Register Containers as Sequences for `match` compatibility (PR #174091)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Dec 31 05:42:19 PST 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {darker}-->
:warning: Python code formatter, darker found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
darker --check --diff -r origin/main...HEAD mlir/test/python/ir/blocks.py mlir/test/python/ir/operation.py
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from darker here.
</summary>
``````````diff
--- blocks.py 2025-12-31 13:01:56.000000 +0000
+++ blocks.py 2025-12-31 13:41:49.153974 +0000
@@ -79,13 +79,13 @@
successors=[
Block(
predecessors=[matched_entry_block],
successors=[
Block(predecessors=[matched_middle_block], successors=[])
- ]
+ ],
)
- ]
+ ],
) if entry_block == matched_entry_block and middle_block == matched_middle_block:
assert True
case _:
assert False
--- operation.py 2025-12-31 13:01:56.000000 +0000
+++ operation.py 2025-12-31 13:41:49.513928 +0000
@@ -204,11 +204,11 @@
# CHECK: Argument 0, type i8
# CHECK: Argument 1, type i16
# CHECK: Argument 2, type i24
for arg in entry_block.arguments:
print(f"Argument {arg.arg_number}, type {arg.type}")
-
+
# CHECK: Matched Arg 0, type i8
# CHECK: Matched Arg 1, type i16
# CHECK: Matched Arg 2, type i24
match func_op:
case func.FuncOp(body=Region(blocks=[Block(arguments=[a0, a1])])):
@@ -271,14 +271,26 @@
assert len(consumer.operands) == 2
# CHECK: Operand 0, type i32
# CHECK: Operand 1, type i64
for i, operand in enumerate(consumer.operands):
print(f"Operand {i}, type {operand.type}")
-
+
match module.body.operations:
case [
- func.FuncOp(body=Region(blocks=[Block(operations=[_, OpView(operands=[o1, o2]) as matched_consumer, *_])]))
+ func.FuncOp(
+ body=Region(
+ blocks=[
+ Block(
+ operations=[
+ _,
+ OpView(operands=[o1, o2]) as matched_consumer,
+ *_,
+ ]
+ )
+ ]
+ )
+ )
]:
print(f"Matched Operand 0, type {o1.type}")
print(f"Matched Operand 1, type {o2.type}")
@@ -504,11 +516,17 @@
# CHECK: Matched Result r0, type i32
# CHECK: Matched Result r1, type f64
# CHECK: Matched Result r2, type index
match caller:
- case func.FuncOp(body=Region(blocks=[Block(operations=[OpView(results=[r0, r1, r2]) as matched_call, *_])])):
+ case func.FuncOp(
+ body=Region(
+ blocks=[
+ Block(operations=[OpView(results=[r0, r1, r2]) as matched_call, *_])
+ ]
+ )
+ ):
assert matched_call == call
print(f"Matched Result r0, type {r0.type}")
print(f"Matched Result r1, type {r1.type}")
print(f"Matched Result r2, type {r2.type}")
case _:
@@ -638,11 +656,17 @@
# CHECK: Matched Mapping Attribute 'other.attribute': 3.0
# CHECK: Matched Mapping Attribute 'dependent': text
match op:
case OpView(attributes={"does_not_exist": a0}):
assert False
- case OpView(attributes={"some.attribute": Attribute() as some_attr, "other.attribute": Attribute() as other_attr, "dependent": Attribute() as dep_attr}):
+ case OpView(
+ attributes={
+ "some.attribute": Attribute() as some_attr,
+ "other.attribute": Attribute() as other_attr,
+ "dependent": Attribute() as dep_attr,
+ }
+ ):
print(f"Matched Mapping Attribute 'some.attribute': {some_attr.value}")
print(f"Matched Mapping Attribute 'other.attribute': {other_attr.value}")
print(f"Matched Mapping Attribute 'dependent': {dep_attr.value}")
case _:
print("Did not match!")
``````````
</details>
https://github.com/llvm/llvm-project/pull/174091
More information about the Mlir-commits
mailing list