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

Some way to apply a rewrite to a region of a Hugr #246

Closed
acl-cqc opened this issue Jul 5, 2023 · 5 comments
Closed

Some way to apply a rewrite to a region of a Hugr #246

acl-cqc opened this issue Jul 5, 2023 · 5 comments
Assignees

Comments

@acl-cqc
Copy link
Contributor

acl-cqc commented Jul 5, 2023

The simplest way might be:

  • Make Rewrite::apply operate on any &mut impl HugrMut, rather than only on a &mut Hugr
  • impl HugrMut for FlatRegionView. This would presumably have to do some sanity checking that the relevant/affected/passed-in Nodes were "in" the region. I'm not sure how straightforward these would be, this might be the killer...
  • (Trivial) add HugrMut::apply_rewrite, as a Trait-default method I think (and moved from impl Hugr, in fact)
@aborgna-q
Copy link
Collaborator

HugrMut is pub(crate). apply_rewrite could go into a Rewritable : HugrMut or something similar, with some small changes to seal HugrMut.

impl HugrMut for FlatRegionView is not that straightforward since the views are immutable by default, but we can apply the rewrite on the underlying hugr and recreate the view (it's almost free).

@acl-cqc
Copy link
Contributor Author

acl-cqc commented Jul 5, 2023

HugrMut is pub(crate)

Ah yes good point. So pub(crate) would do for now but perhaps we do need a new, pub mutator trait....

but we can apply the rewrite on the underlying hugr and recreate the view (it's almost free)

Yes. One loses any protection against the rewrite changing anything outside the region, and thus indeed, any protection against the rewrite removing the region altogether, but....

@aborgna-q
Copy link
Collaborator

We can still run the checks before unwrapping (I think we'd only require the removed set to be in the graph)?

@acl-cqc
Copy link
Contributor Author

acl-cqc commented Jul 17, 2023

We can still run the checks before unwrapping (I think we'd only require the removed set to be in the graph)?

That works nicely for Replace, I think, yes. But there are other rewrite too, e.g. (Inline/Outline)(C/D)FG. We could write checks for each of those individually, and (hmmm) yes we probably will have to in order to determine in advance whether the rewrite will stay within a region or not.

We may also be able to make all Rewrites (not just Replace) do all their operations through a HugrView / MutRegion, so at least we can have some protection against accidents when the rewrite is being applied even if not in advance.

@acl-cqc
Copy link
Contributor Author

acl-cqc commented Sep 27, 2023

Done in #522 and #519 via SiblingMut

@acl-cqc acl-cqc closed this as completed Sep 27, 2023
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

No branches or pull requests

2 participants