From 0614fc972d295ca89edc70be87c0d87066219595 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Fri, 24 May 2024 22:28:20 -0700 Subject: [PATCH] [Index] Write empty record files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When indexing an empty Swift file, we get a unit file that doesn’t have any record dependency declared on the source file. Because of this, we always assume that the empty file has an out of date index store entry and re-index it on project open. Write empty record files to fix this. rdar://128711594 --- lib/Index/IndexRecord.cpp | 5 ----- test/Index/Store/record-empty.swift | 2 +- test/Index/Store/unit-from-compile.swift | 3 ++- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/Index/IndexRecord.cpp b/lib/Index/IndexRecord.cpp index 59be895b4eac3..c9d24d69b2e7f 100644 --- a/lib/Index/IndexRecord.cpp +++ b/lib/Index/IndexRecord.cpp @@ -285,11 +285,6 @@ StringRef StdlibGroupsIndexRecordingConsumer::findGroupForSymbol(const IndexSymb static bool writeRecord(SymbolTracker &record, std::string Filename, std::string indexStorePath, DiagnosticEngine *diags, std::string &outRecordFile) { - if (record.getOccurrences().empty()) { - outRecordFile = std::string(); - return false; - } - IndexRecordWriter recordWriter(indexStorePath); std::string error; auto result = recordWriter.beginRecord( diff --git a/test/Index/Store/record-empty.swift b/test/Index/Store/record-empty.swift index d72b5cc1544da..22e293bb8bfb1 100644 --- a/test/Index/Store/record-empty.swift +++ b/test/Index/Store/record-empty.swift @@ -2,4 +2,4 @@ // RUN: %target-swift-frontend -index-store-path %t/idx -o %t/file.o -typecheck -primary-file %s // RUN: %target-swift-frontend -index-store-path %t/idx -o %t/file.o -typecheck %s // RUN: c-index-test core -print-unit %t/idx | %FileCheck %s -// CHECK-NOT: Record{{.*}}record-empty +// CHECK: Record | user | {{.*}}{{/|\\}}record-empty.swift diff --git a/test/Index/Store/unit-from-compile.swift b/test/Index/Store/unit-from-compile.swift index e2cc61aa27810..e62a86a0cbc25 100644 --- a/test/Index/Store/unit-from-compile.swift +++ b/test/Index/Store/unit-from-compile.swift @@ -16,6 +16,7 @@ // CHECK: DEPEND START // CHECK: Unit | system | {{.*}}{{/|\\}}Swift.swiftmodule -// CHECK: DEPEND END (1) +// CHECK: Record | user | {{.*}}{{/|\\}}unit-from-compile.swift +// CHECK: DEPEND END (2) // OPT: is-debug: 1