Skip to content

Commit 181d7a2

Browse files
committed
FrontendTool: Deterministic order when a normal declname has same spelling as special declname
1 parent e5ffbbe commit 181d7a2

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/FrontendTool/ReferenceDependencies.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,16 @@ bool swift::emitReferenceDependencies(DiagnosticEngine &diags, SourceFile *SF,
354354
llvm::array_pod_sort(sortedMembers.begin(), sortedMembers.end(),
355355
[](const TableEntryTy *lhs,
356356
const TableEntryTy *rhs) -> int {
357-
if (lhs->first.first == rhs->first.first)
358-
return lhs->first.second.compare(rhs->first.second);
357+
if (auto cmp = lhs->first.first->getName().compare(rhs->first.first->getName()))
358+
return cmp;
359359

360-
if (lhs->first.first->getName() != rhs->first.first->getName())
361-
return lhs->first.first->getName().compare(rhs->first.first->getName());
360+
if (auto cmp = lhs->first.second.compare(rhs->first.second))
361+
return cmp;
362+
363+
// We can have two entries with the same member name if one of them
364+
// was the special 'init' name and the other is the plain 'init' token.
365+
if (lhs->second != rhs->second)
366+
return lhs->second ? -1 : 1;
362367

363368
// Break type name ties by mangled name.
364369
auto lhsMangledName = mangleTypeAsContext(lhs->first.first);

0 commit comments

Comments
 (0)