From 5cdc7db420816a75b2f55621fa3acd3c6e2c5bb8 Mon Sep 17 00:00:00 2001 From: Ben Barham Date: Tue, 15 Aug 2023 17:57:11 -0700 Subject: [PATCH] [Index] Write stdlib records in alphabetical order The order for writing records of the stdlib currently depends on `StringMap` iteration (in a slightly roundabout manner). Sort these alphabetically instead. --- lib/Index/IndexRecord.cpp | 14 ++++++++++---- .../unit-one-file-multi-file-invocation.swift | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/Index/IndexRecord.cpp b/lib/Index/IndexRecord.cpp index 25290537e2979..fc1ed9c4d1654 100644 --- a/lib/Index/IndexRecord.cpp +++ b/lib/Index/IndexRecord.cpp @@ -233,10 +233,16 @@ class StdlibGroupsIndexRecordingConsumer : public IndexDataConsumer { } void finish() override { - for (auto &pair : TrackerByGroup) { - StringRef groupName = pair.first(); - SymbolTracker &tracker = *pair.second; - bool cont = onFinish(groupName, tracker); + SmallVector, 0> SortedGroups; + for (auto &entry : TrackerByGroup) { + SortedGroups.emplace_back(entry.first(), entry.second.get()); + } + llvm::sort(SortedGroups, llvm::less_first()); + + for (auto &pair : SortedGroups) { + StringRef groupName = pair.first; + SymbolTracker *tracker = pair.second; + bool cont = onFinish(groupName, *tracker); if (!cont) break; } diff --git a/test/Index/Store/unit-one-file-multi-file-invocation.swift b/test/Index/Store/unit-one-file-multi-file-invocation.swift index ab49dc9aa875a..ae56ae7d3b8a6 100644 --- a/test/Index/Store/unit-one-file-multi-file-invocation.swift +++ b/test/Index/Store/unit-one-file-multi-file-invocation.swift @@ -18,8 +18,8 @@ // CHECK: [[SWIFT]] // CHECK: DEPEND START -// CHECK: Record | system | Swift.String | [[MODULE]] | {{.+}}.swiftinterface_String-{{.*}} // CHECK: Record | system | Swift.Math.Floating | [[MODULE]] | {{.+}}.swiftinterface_Math_Floating-{{.*}} +// CHECK: Record | system | Swift.String | [[MODULE]] | {{.+}}.swiftinterface_String-{{.*}} // CHECK: DEPEND END func test1() {