Skip to content

pattern based rewrite rule #309

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

Open
Roger-luo opened this issue Mar 5, 2025 · 0 comments
Open

pattern based rewrite rule #309

Roger-luo opened this issue Mar 5, 2025 · 0 comments
Labels
enhancement New feature or request rewrite rewrite related issues

Comments

@Roger-luo
Copy link
Member

It is quite inconvenient to specify a pattern to match, not to say description the equivalence of a given match_and_rewrite rule. While dispatching on type signature like xDSL/MLIR is OK, I'm more leaning towards an actual pattern description language e.g

@pattern(py.Add(py.Constant(2.0), py.Add()))
def rewrite(node: ir.Statement):
    pass

the actual design probably still need a bit more thoughts but this is why I originally didn't choose to do dispatch/multiple dispatch. We should provide something like https://github.com/JuliaSymbolics/Metatheory.jl which also describes how to do bidirectional rewrite so PRs like QuEraComputing/bloqade#183 are no longer necessary.

So roughly there are decorators/objects that one can optionally use but always fallback to the most generic Python visitor if none of them applies, e.g

py.Add(py.Constant(2.0), py.Add(node)) <=> py.Mult(3.0, node)

however, we need to think about how to model this with a proper Python syntax it seems tricky doing this in Python. Could be a special rule class? e.g

class EquivRule:
    equiv_rules = {
        py.Add(py.Constant(2.0), py.Add(node)): py.Mult(3.0, node)
    }
    directional = {...}
@Roger-luo Roger-luo added enhancement New feature or request rewrite rewrite related issues labels Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request rewrite rewrite related issues
Projects
None yet
Development

No branches or pull requests

1 participant