Skip to content

Commit 1d4debe

Browse files
authored
Merge pull request swiftlang#33869 from CodaFi/the-right-sort-of-stuff
[Gardening] Document a Strange Sort
2 parents 7f26d97 + 9876513 commit 1d4debe

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,24 @@ swift::frontend::utils::escapeForMake(StringRef raw,
139139
return buffer.data();
140140
}
141141

142+
/// This sorting function is used to stabilize the order in which dependencies
143+
/// are emitted into \c .d files that are consumed by external build systems.
144+
/// This serves to eliminate order as a source of non-determinism in these
145+
/// outputs.
146+
///
147+
/// The exact sorting predicate is not important. Currently, it is a
148+
/// lexicographic comparison that reverses the provided strings before applying
149+
/// the sorting predicate. This has the benefit of being somewhat
150+
/// invariant with respect to the installation location of various system
151+
/// components. e.g. on two systems, the same file identified by two different
152+
/// paths differing only in their relative install location such as
153+
///
154+
/// /Applications/MyXcode.app/Path/To/A/Framework/In/The/SDK/Header.h
155+
/// /Applications/Xcodes/AnotherXcode.app/Path/To/A/Framework/In/The/SDK/Header.h
156+
///
157+
/// should appear in roughly the same order relative to other paths. Ultimately,
158+
/// this makes it easier to test the contents of the emitted files with tools
159+
/// like FileCheck.
142160
static std::vector<std::string>
143161
reversePathSortedFilenames(const ArrayRef<std::string> elts) {
144162
std::vector<std::string> tmp(elts.begin(), elts.end());

0 commit comments

Comments
 (0)