[llvm] update_test_checks: improve IR value name stability (PR #110940)

Jannik Silvanus via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 4 03:14:46 PDT 2024


Nicolai =?utf-8?q?Hähnle?= <nicolai.haehnle at amd.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/110940 at github.com>


================
@@ -1534,14 +1534,35 @@ def diffify_line(line, mapper):
 
         candidate_matches = find_diff_matching(lhs_lines, rhs_lines)
 
-        # Apply commits greedily on a match-by-match basis
-        matches = [(-1, -1)]
-        committed_anything = False
-        for lhs_idx, rhs_idx in candidate_matches:
+        candidate_matches = [
+            (old_begin + lhs_idx, new_begin + rhs_idx)
+            for lhs_idx, rhs_idx in candidate_matches
+        ]
+
+        # Candidate matches may conflict if they require conflicting mappings of
+        # names.
+        #
+        # Treat the candidate matches as vertices in a conflict graph. Greedily
+        # color the vertices.
+        class Color:
+            def __init__(self):
+                # (lhs_idx, rhs_idx) of matches in this color
+                self.matches = []
+
+                # rhs_name -> lhs_name mappings required by this color
+                self.mapping = {}
+
+                # lhs_names committed for this color
+                self.committed = set()
+        colors = []
+
+        for match_idx, (lhs_idx, rhs_idx) in enumerate(candidate_matches):
             lhs_line = old_line_infos[lhs_idx]
             rhs_line = new_line_infos[rhs_idx]
 
-            local_commits = {}
+            compatible_colors = colors[:]
----------------
jasilvanus wrote:

I had to look that up, maybe `copy.copy(colors)` instead? If you feel it is sufficiently idiomatic then fine with me.

https://github.com/llvm/llvm-project/pull/110940


More information about the llvm-commits mailing list