[llvm] update_test_checks: keep meta variables stable by default (PR #76748)
Nicolai Hähnle via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 6 11:39:20 PST 2024
================
@@ -1187,20 +1233,317 @@ def may_clash_with_default_check_prefix_name(check_prefix, var):
)
+def find_diff_matching(lhs: List[str], rhs: List[str]) -> List[int]:
+ """
+ Find a large ordered matching between strings in lhs and rhs.
+
+ Think of this as finding the *unchanged* lines in a diff, where the entries
+ of lhs and rhs are lines of the files being diffed.
+
+ Returns a list of matched (lhs_idx, rhs_idx) pairs.
+ """
+
+ # Collect matches in reverse order.
+ matches = []
+
+ def recurse(lhs_start, lhs_end, rhs_start, rhs_end):
+ if lhs_start == lhs_end or rhs_start == rhs_end:
+ return
+
+ # First, collect a set of candidate matching edges. We limit this to a
+ # constant multiple of the input size to avoid quadratic runtime.
+ patterns = collections.defaultdict(lambda: ([], []))
+
+ for idx in range(lhs_start, lhs_end):
+ patterns[lhs[idx]][0].append(idx)
+ for idx in range(rhs_start, rhs_end):
+ patterns[rhs[idx]][1].append(idx)
+
+ multiple_patterns = []
+
+ candidates = []
+ for pattern in patterns.values():
+ if not pattern[0] or not pattern[1]:
+ continue
+
+ if len(pattern[0]) == len(pattern[1]) == 1:
+ candidates.append((pattern[0][0], pattern[1][0]))
+ else:
+ multiple_patterns.append(pattern)
+
+ multiple_patterns.sort(key=lambda pattern: len(pattern[0]) * len(pattern[1]))
+
+ for pattern in multiple_patterns:
+ if len(candidates) + len(pattern[0]) * len(pattern[1]) > 2 * (len(lhs) + len(rhs)):
----------------
nhaehnle wrote:
Yes, I considered such options, but I also wanted to be able to write a reasonable test case that still hits the case where we drop candidates due to this check. If you feel really strongly about it (and can ideally support it with a concrete test case) I can look at it, but I'd prefer to just land something simpler for the first version.
https://github.com/llvm/llvm-project/pull/76748
More information about the llvm-commits
mailing list