Skip to content

Inefficient Binding Replacement in Rules YAML Format #285

@maxonfjvipon

Description

@maxonfjvipon

Imagine I have set of bindings:

Q -> [[
  x -> 1,
  y -> 2,
  z -> 3,
  ...
]]

I want to take each binding and surround it with some other bindings:

Q -> [[
  x1 -> "before x",
  x -> 1,
  x2 -> "after x",
  y1 -> "before y",
  y -> 2,
  y2 -> "after y",
  z1 -> "before z",
  z -> 3,
  z2 -> "after z"
  ...
]]

Now, to achieve that, I need to write such pattern (simplified):

pattern: [[ !B-before, !a -> !e, !B-after ]]
result:  [[ !B -> before, !a1 -> "before", !a -> !e, !a2 -> "after", !B-after ]]
when !e is number
where !a1 is x1 and !a2 is x2

When the original program just matches for the first time I'll get 3 possible places where such transformation can be applied. But right after first replacement 2 last substitutions will be no more relevant since !B-before is not matched with bindings after first replacement. So to extend all N bindings, we need to do N cycles of "match + build + replace". That's affects performance.

I suggest we extend our rules yaml format so we can do something like this:

target-bindings:
  - x -> 1
result-bindings:
  - x1 -> "before"
  - x -> 1
  - x2 -> "after"

Here target-bindings will describe set of bindings which we'll try to find in the program, when we find them - we just replace it with result-bindings. That's it. No need to define !B-before, !B-after, no need to rematch and re-replace after each replacement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood-titlequestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions