refactor(domain): share string and name comparison results (#16334)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-03 12:18:48 +00:00
1 parent 1b3e3ee83e
commit 7e1cb05849
1 file changed
+42 -90
+42 -90
View File
@@ -234,28 +234,46 @@ const compareStringsAndNames = (
const stringFacts = compareReferencedStrings(leftStrings, rightStrings);
const leftNamesAndLiterals = nameAndSwiftProjection(left, complete);
const rightNamesAndLiterals = nameAndSwiftProjection(right, complete);
if (stringFacts.changed)
return stringsAndNamesResult({
leftStrings,
rightStrings,
leftNamesAndLiterals,
rightNamesAndLiterals,
context,
status: "changed",
limitations: [
...stringFacts.limitations,
...(leftNamesAndLiterals === null || rightNamesAndLiterals === null
? [
"Reference source locations could not be normalized to function offsets.",
]
: []),
...(complete
? []
: [
"Swift String literal coverage differs or is partial; complete coverage does not establish a differing literal.",
]),
],
const result = (
status: "changed" | "unchanged",
limitations: readonly string[] = [],
leftNames = leftNamesAndLiterals,
rightNames = rightNamesAndLiterals,
): FunctionDimension =>
dimensionResult({
dimension: "strings_names",
status,
left: {
referenced_strings: leftStrings,
names_and_literals: leftNames,
},
right: {
referenced_strings: rightStrings,
names_and_literals: rightNames,
},
...context,
// Names that cannot be placed in the function leave the side's count unknown.
leftCount:
leftNames === null ? null : leftStrings.length + leftNames.length,
rightCount:
rightNames === null ? null : rightStrings.length + rightNames.length,
textDelta: null,
limitations,
});
if (stringFacts.changed)
return result("changed", [
...stringFacts.limitations,
...(leftNamesAndLiterals === null || rightNamesAndLiterals === null
? [
"Reference source locations could not be normalized to function offsets.",
]
: []),
...(complete
? []
: [
"Swift String literal coverage differs or is partial; complete coverage does not establish a differing literal.",
]),
]);
if (leftNamesAndLiterals === null || rightNamesAndLiterals === null)
return unresolvedDimension({
dimension: "strings_names",
@@ -273,15 +291,7 @@ const compareStringsAndNames = (
context,
);
if (compared.status === "changed")
return stringsAndNamesResult({
leftStrings,
rightStrings,
leftNamesAndLiterals,
rightNamesAndLiterals,
context,
status: "changed",
limitations: stringFacts.limitations,
});
return result("changed", stringFacts.limitations);
// A retained literal differs only when the opposite dossier establishes its absence.
if (swiftLiteralSitesConflict(left, right)) {
const leftAll = nameAndSwiftProjection(left);
@@ -294,15 +304,7 @@ const compareStringsAndNames = (
context,
);
if (literalComparison.status === "changed")
return stringsAndNamesResult({
leftStrings,
rightStrings,
leftNamesAndLiterals: leftAll,
rightNamesAndLiterals: rightAll,
context,
status: "changed",
limitations: stringFacts.limitations,
});
return result("changed", stringFacts.limitations, leftAll, rightAll);
}
}
const limitations = [
@@ -313,15 +315,7 @@ const compareStringsAndNames = (
"Swift String literal coverage differs or is partial; complete coverage does not establish a differing literal.",
]),
];
if (limitations.length === 0)
return stringsAndNamesResult({
leftStrings,
rightStrings,
leftNamesAndLiterals,
rightNamesAndLiterals,
context,
status: "unchanged",
});
if (limitations.length === 0) return result("unchanged");
return unresolvedDimension({
dimension: "strings_names",
links: context.links,
@@ -331,48 +325,6 @@ const compareStringsAndNames = (
});
};
const stringsAndNamesResult = ({
leftStrings,
rightStrings,
leftNamesAndLiterals,
rightNamesAndLiterals,
context,
status,
limitations = [],
}: {
readonly leftStrings: readonly ReferencedStringFact[];
readonly rightStrings: readonly ReferencedStringFact[];
readonly leftNamesAndLiterals: readonly unknown[] | null;
readonly rightNamesAndLiterals: readonly unknown[] | null;
readonly context: ComparisonContext;
readonly status: "changed" | "unchanged";
readonly limitations?: readonly string[];
}): FunctionDimension =>
dimensionResult({
dimension: "strings_names",
status,
left: {
referenced_strings: leftStrings,
names_and_literals: leftNamesAndLiterals,
},
right: {
referenced_strings: rightStrings,
names_and_literals: rightNamesAndLiterals,
},
...context,
// Names that cannot be placed in the function leave the side's count unknown.
leftCount:
leftNamesAndLiterals === null
? null
: leftStrings.length + leftNamesAndLiterals.length,
rightCount:
rightNamesAndLiterals === null
? null
: rightStrings.length + rightNamesAndLiterals.length,
textDelta: null,
limitations,
});
type ReferencedStringFact = ReturnType<
typeof referencedStringProjection
>[number];