hugr icon indicating copy to clipboard operation
hugr copied to clipboard

Conversion SimpleReplacement -> Replacement

Open lmondada opened this issue 8 months ago • 2 comments

Implement

impl From<SimpleReplacement> for Replacement

or a similar dedicated trait to convert a SimpleReplacement to Replacement. This could also be a method on SimpleReplacement, but that would make it impossible to provide blanket implementations of Rewrite<PersistentHugr>.

This is required to be able to add SimpleReplacements to PersistentHugrs, which will (presumably) be made of Replacements.

Note that there is an argument for not implementing From, but rather a custom trait: one could imagine a rewrite struct InlineCall that only stores the Node ID of a call op, but can be turned into a Replacement if it is given a reference to the underlying Hugr: it needs to clone the body of the function to be inlined into the replacement graph. Such a conversion would have the signature fn into_replacement(self, hugr: &impl HugrView) -> Replacement

lmondada avatar Apr 07 '25 20:04 lmondada

For the time being I have opted to use SimpleReplacements in PersistentHugr. We can reevaluate this once we have a clearer ideas of the use cases we need to support.

lmondada avatar Apr 17 '25 13:04 lmondada

Note that there is already a fn to_replace function already implemented in simple_replace.rs, within the tests. It might be that exposing that is all that is required!

lmondada avatar May 10 '25 16:05 lmondada