Skip to content

Commit

Permalink
interpreter: (pdl) fix match_operand matching for already matched value
Browse files Browse the repository at this point in the history
  • Loading branch information
superlopuh committed Nov 17, 2024
1 parent 1abf6ad commit 5630add
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions tests/interpreters/test_pdl_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
ModuleOp,
StringAttr,
i32,
i64,
)
from xdsl.interpreter import Interpreter
from xdsl.interpreters.pdl import PDLMatcher, PDLRewriteFunctions, PDLRewritePattern
Expand Down Expand Up @@ -119,6 +120,34 @@ def test_not_match_fixed_type():
assert matcher.matching_context == {}


def test_match_operand():
matcher = PDLMatcher()

pdl_op = pdl.OperandOp()
ssa_value = pdl_op.value
xdsl_value = TestSSAValue(i32)

# New value
assert matcher.match_operand(ssa_value, pdl_op, xdsl_value)
assert matcher.matching_context == {ssa_value: xdsl_value}

# Same value
assert matcher.match_operand(ssa_value, pdl_op, xdsl_value)
assert matcher.matching_context == {ssa_value: xdsl_value}

# Other value
other_value = TestSSAValue(i32)
assert not matcher.match_operand(ssa_value, pdl_op, other_value)
assert matcher.matching_context == {ssa_value: xdsl_value}

# Wrong type
type_op = pdl.TypeOp(i64)
new_pdl_op = pdl.OperandOp(type_op.result)
new_value = TestSSAValue(i32)
assert not matcher.match_operand(new_pdl_op.value, new_pdl_op, new_value)
assert matcher.matching_context == {ssa_value: xdsl_value}


def test_native_constraint_constant_parameter():
"""
Check that `pdl.apply_native_constraint` can take constant attribute parameters
Expand Down
2 changes: 1 addition & 1 deletion xdsl/interpreters/pdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def match_operand(
self, ssa_val: SSAValue, pdl_op: pdl.OperandOp, xdsl_val: SSAValue
):
if ssa_val in self.matching_context:
return True
return self.matching_context[ssa_val] == xdsl_val

if pdl_op.value_type is not None:
assert isinstance(pdl_op.value_type, OpResult)
Expand Down

0 comments on commit 5630add

Please sign in to comment.