Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transformations: (pdl) Different type matching between polymorphic and fixed case #3405

Merged
merged 5 commits into from
Nov 11, 2024

Conversation

qaco
Copy link
Collaborator

@qaco qaco commented Nov 6, 2024

No description provided.

@qaco qaco added transformations Changes or adds a transformatio interpreter xDSL Interpreter labels Nov 6, 2024
@qaco qaco requested a review from superlopuh November 6, 2024 10:09
@qaco qaco self-assigned this Nov 6, 2024
Copy link

codecov bot commented Nov 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.18%. Comparing base (f3414f3) to head (bfddda6).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3405      +/-   ##
==========================================
+ Coverage   90.16%   90.18%   +0.01%     
==========================================
  Files         456      456              
  Lines       57540    57567      +27     
  Branches     5540     5541       +1     
==========================================
+ Hits        51883    51917      +34     
+ Misses       4197     4191       -6     
+ Partials     1460     1459       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@superlopuh superlopuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add a pytest unit test?

@qaco
Copy link
Collaborator Author

qaco commented Nov 6, 2024

could you please add a pytest unit test?

Ok done !

Comment on lines 485 to 536
def test_distinct_types_polymorph_matching():
@ModuleOp
@Builder.implicit_region
def input_module():
test.TestOp.create(result_types=[IntegerType(32)])
test.TestOp.create(result_types=[IntegerType(64)])

@ModuleOp
@Builder.implicit_region
def pdl_module():
with ImplicitBuilder(pdl.PatternOp(2, None).body):
pdl_type = pdl.TypeOp().result
pdl_op = pdl.OperationOp(StringAttr("test.op"), type_values=[pdl_type]).op
with ImplicitBuilder(pdl.RewriteOp(pdl_op).body):
pdl.EraseOp(pdl_op)

pdl_rewrite_op = next(
op for op in pdl_module.walk() if isinstance(op, pdl.RewriteOp)
)

ctx = MLContext()
pattern_walker = PatternRewriteWalker(PDLRewritePattern(pdl_rewrite_op, ctx))

pattern_walker.rewrite_module(input_module)
assert input_module.is_structurally_equivalent(ModuleOp([]))


def test_distinct_types_matching():
@ModuleOp
@Builder.implicit_region
def input_module():
test.TestOp.create(result_types=[IntegerType(32)])
test.TestOp.create(result_types=[IntegerType(64)])

@ModuleOp
@Builder.implicit_region
def output_module():
test.TestOp.create(result_types=[IntegerType(64)])

@ModuleOp
@Builder.implicit_region
def pdl_module():
with ImplicitBuilder(pdl.PatternOp(2, None).body):
pdl_type = pdl.TypeOp(IntegerType(32)).result
pdl_op = pdl.OperationOp(StringAttr("test.op"), type_values=[pdl_type]).op
with ImplicitBuilder(pdl.RewriteOp(pdl_op).body):
pdl.EraseOp(pdl_op)

pdl_rewrite_op = next(
op for op in pdl_module.walk() if isinstance(op, pdl.RewriteOp)
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I apologise, I should have been more precise! I didn't mean for you to do all this work to reimplement the inputs etc. In my head, it was a much smaller function, and I didn't realise that there was no precedent already in this file for it. Here is what I was hoping we would already have in this file:

def test_match_type():
    matcher = PDLMatcher()

    pdl_op = pdl.TypeOp()
    ssa_value = pdl_op.result
    xdsl_value = StringAttr("a")

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

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

    # Other value
    assert not matcher.match_type(ssa_value, pdl_op, StringAttr("b"))
    assert matcher.matching_context == {ssa_value: xdsl_value}

I was thinking that it would be just 5 minutes work to add the new test cases for the functionality you added. As it stands these tests are duplicating the functionality tested in the filecheck test, which is probably the better place for them now that you've added the filecheck functionality.

I don't want to block you any more, so if you would like to merge as-is, I think that would also be ok, but if you have the time to replace these two tests with a more targeted test like the one above that just checks the one function you modified I think it would help debug in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, ok, I didn't get what you requested. That's fine, I'll do it !

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok it's done I guess

Copy link
Member

@superlopuh superlopuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@qaco
Copy link
Collaborator Author

qaco commented Nov 11, 2024

Thank you!

Dos it mean that I do the merge ?

@superlopuh
Copy link
Member

Yep, all you need is one green tick, and no leftover comments from the review

@superlopuh superlopuh merged commit c5a1c4e into xdslproject:main Nov 11, 2024
15 checks passed
@qaco qaco deleted the matching_types branch November 21, 2024 10:57
EdmundGoodman pushed a commit to EdmundGoodman/xdsl that referenced this pull request Dec 6, 2024
…d fixed case (xdslproject#3405)

Co-authored-by: Sasha Lopoukhine <superlopuh@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter xDSL Interpreter transformations Changes or adds a transformatio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants