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

MultiPatterns #168

Closed
wants to merge 10 commits into from
Closed

MultiPatterns #168

wants to merge 10 commits into from

Conversation

philzook58
Copy link
Contributor

@philzook58 philzook58 commented Mar 11, 2022

Multipatterns are multiple possibly disjoint patterns to seek out in a search process. They are distinct from guards in that they may bind new variables. This pull request attempts to implement somewhat efficient multipatterns in a backwards compatible way.
The pattern compiler can remain mostly as is. Compiler state about what patterns are where in the subst map needs to be retained between each single pattern compilation.
Multipatterns require changes to the abstract machine because scanning for roots of the 2nd pattern onwards becomes required.
Extending the interface to be able to give pattern names to the root of the pattern itself enables significant extra modelling power. Note that labelled multipatterns allows one to implement efficient manual scheduling of search even for single patterns via flattening or breaking the pattern trees up.

This PR is still a work in progress, but examples can be found in the datalog.rs test. The syntax for creating multipatterns might change, but it looks this currently:

    let rules = vec![
        multi_rewrite!("base-case"; "?x = true = (edge ?a ?b)" => "?x = (path ?a ?b)"),
        multi_rewrite!("transitive"; "?x = true = (path ?a ?b) = (edge ?b ?c)" => "?x = (path ?a ?c)"),
    ];

Closes #39

@philzook58
Copy link
Contributor Author

philzook58 commented Mar 19, 2022

In the right hand side, I think I can only express equality to a variable bound in the lhs. In the Applier impl for MultiPattern, I would think one should allow creating new bindings only in the ?x = _ variable position to give name to new terms constructed. See test unbound_rhs. I understand there is something suspicious about allowing new bindings in the rhs, but I genuinely think this is useful and enhances expressivity. I should probably come up with a less contrived example though.
I have slightly changed how Applier works to allow this.

let mut added = vec![];
for mat in matches {
for subst in &mat.substs {
let mut subst = subst.clone();
Copy link
Contributor Author

@philzook58 philzook58 Mar 19, 2022

Choose a reason for hiding this comment

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

This is an unfortunate clone, but I don't see an elegant way around it without changing interface of matches to be &mut or something.

@mwillsey
Copy link
Member

This was merged, but I guess the fast-forward make github not see it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support multi-patterns for rewrite rules
2 participants