Commit 4291ff2
Fix non-deterministic rewriter behavior in multi-output pattern matching (#2880)
`GraphPattern.__init__` collects output nodes into a `set[NodePattern]`,
then converts to a list via `list(output_nodes)`. Python's hash
randomization means this list has non-deterministic order across process
invocations. For multi-output patterns (e.g. `SlicesSplit`), the matcher
fixes `output_nodes[0]` to the current node and searches for
`output_nodes[1:]` — so different orderings cause the same rule to match
or not match non-deterministically.
- Replace `set[NodePattern]` with `dict[NodePattern, None]` (ordered set
idiom) to preserve deterministic insertion order from the `outputs`
sequence
- Add regression test verifying `output_nodes` ordering is stable across
repeated `GraphPattern` constructions
```python
# Before: non-deterministic iteration order
output_nodes: set[NodePattern] = set()
...
output_nodes.add(candidate)
...
self.output_nodes: list[NodePattern] = list(output_nodes)
# After: preserves insertion order from outputs sequence
output_nodes: dict[NodePattern, None] = {}
...
output_nodes[candidate] = None
...
self.output_nodes: list[NodePattern] = list(output_nodes)
```
Fix #2878
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>1 parent 5391619 commit 4291ff2
2 files changed
+31
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
836 | 836 | | |
837 | 837 | | |
838 | 838 | | |
839 | | - | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
840 | 844 | | |
841 | 845 | | |
842 | 846 | | |
| |||
848 | 852 | | |
849 | 853 | | |
850 | 854 | | |
851 | | - | |
| 855 | + | |
852 | 856 | | |
853 | 857 | | |
854 | 858 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
74 | 99 | | |
75 | 100 | | |
76 | 101 | | |
0 commit comments