Skip to content

Commit 9098e09

Browse files
committed
Address review comments from #1322
1 parent a858d30 commit 9098e09

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

Sources/SemanticIndex/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
add_library(SemanticIndex STATIC
33
CheckedIndex.swift
44
CompilerCommandLineOption.swift
5-
IndexStatusManager.swift
65
IndexTaskDescription.swift
76
PreparationTaskDescription.swift
87
SemanticIndexManager.swift
98
TestHooks.swift
109
UpdateIndexStoreTaskDescription.swift
10+
UpToDateTracker.swift
1111
)
1212
set_target_properties(SemanticIndex PROPERTIES
1313
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

Sources/SemanticIndex/PreparationTaskDescription.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public struct PreparationTaskDescription: IndexTaskDescription {
3535
/// The build system manager that is used to get the toolchain and build settings for the files to index.
3636
private let buildSystemManager: BuildSystemManager
3737

38-
private let preparationUpToDateStatus: IndexUpToDateStatusManager<ConfiguredTarget>
38+
private let preparationUpToDateTracker: UpToDateTracker<ConfiguredTarget>
3939

4040
/// See `SemanticIndexManager.indexProcessDidProduceResult`
4141
private let indexProcessDidProduceResult: @Sendable (IndexProcessResult) -> Void
@@ -59,13 +59,13 @@ public struct PreparationTaskDescription: IndexTaskDescription {
5959
init(
6060
targetsToPrepare: [ConfiguredTarget],
6161
buildSystemManager: BuildSystemManager,
62-
preparationUpToDateStatus: IndexUpToDateStatusManager<ConfiguredTarget>,
62+
preparationUpToDateTracker: UpToDateTracker<ConfiguredTarget>,
6363
indexProcessDidProduceResult: @escaping @Sendable (IndexProcessResult) -> Void,
6464
testHooks: IndexTestHooks
6565
) {
6666
self.targetsToPrepare = targetsToPrepare
6767
self.buildSystemManager = buildSystemManager
68-
self.preparationUpToDateStatus = preparationUpToDateStatus
68+
self.preparationUpToDateTracker = preparationUpToDateTracker
6969
self.indexProcessDidProduceResult = indexProcessDidProduceResult
7070
self.testHooks = testHooks
7171
}
@@ -76,7 +76,7 @@ public struct PreparationTaskDescription: IndexTaskDescription {
7676
// The last 2 digits should be sufficient to differentiate between multiple concurrently running preparation operations
7777
await withLoggingSubsystemAndScope(subsystem: indexLoggingSubsystem, scope: "preparation-\(id % 100)") {
7878
let targetsToPrepare = await targetsToPrepare.asyncFilter {
79-
await !preparationUpToDateStatus.isUpToDate($0)
79+
await !preparationUpToDateTracker.isUpToDate($0)
8080
}.sorted(by: {
8181
($0.targetID, $0.runDestinationID) < ($1.targetID, $1.runDestinationID)
8282
})
@@ -114,7 +114,7 @@ public struct PreparationTaskDescription: IndexTaskDescription {
114114
}
115115
await testHooks.preparationTaskDidFinish?(self)
116116
if !Task.isCancelled {
117-
await preparationUpToDateStatus.markUpToDate(targetsToPrepare, updateOperationStartDate: startDate)
117+
await preparationUpToDateTracker.markUpToDate(targetsToPrepare, updateOperationStartDate: startDate)
118118
}
119119
}
120120
}

Sources/SemanticIndex/SemanticIndexManager.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ public final actor SemanticIndexManager {
7979
/// ...). `nil` if no build graph is currently being generated.
8080
private var generateBuildGraphTask: Task<Void, Never>?
8181

82-
private let preparationUpToDateStatus = IndexUpToDateStatusManager<ConfiguredTarget>()
82+
private let preparationUpToDateTracker = UpToDateTracker<ConfiguredTarget>()
8383

84-
private let indexStoreUpToDateStatus = IndexUpToDateStatusManager<DocumentURI>()
84+
private let indexStoreUpToDateTracker = UpToDateTracker<DocumentURI>()
8585

8686
/// The preparation tasks that have been started and are either scheduled in the task scheduler or currently
8787
/// executing.
@@ -273,23 +273,23 @@ public final actor SemanticIndexManager {
273273
// We only re-index the files that were changed and don't re-index any of their dependencies. See the
274274
// `Documentation/Files_To_Reindex.md` file.
275275
let changedFiles = events.map(\.uri)
276-
await indexStoreUpToDateStatus.markOutOfDate(changedFiles)
276+
await indexStoreUpToDateTracker.markOutOfDate(changedFiles)
277277

278278
// Note that configured targets are the right abstraction layer here (instead of a non-configured target) because a
279279
// build system might have targets that include different source files. Hence a source file might be in target T
280280
// configured for macOS but not in target T configured for iOS.
281281
let targets = await changedFiles.asyncMap { await buildSystemManager.configuredTargets(for: $0) }.flatMap { $0 }
282282
if let dependentTargets = await buildSystemManager.targets(dependingOn: targets) {
283-
await preparationUpToDateStatus.markOutOfDate(dependentTargets)
283+
await preparationUpToDateTracker.markOutOfDate(dependentTargets)
284284
} else {
285-
await preparationUpToDateStatus.markAllOutOfDate()
285+
await preparationUpToDateTracker.markAllKnownOutOfDate()
286286
// `markAllOutOfDate` only marks targets out-of-date that have been indexed before. Also mark all targets with
287287
// in-progress preparation out of date. So we don't get into the following situation, which would result in an
288288
// incorrect up-to-date status of a target
289289
// - Target preparation starts for the first time
290290
// - Files changed
291291
// - Target preparation finishes.
292-
await preparationUpToDateStatus.markOutOfDate(inProgressPreparationTasks.keys)
292+
await preparationUpToDateTracker.markOutOfDate(inProgressPreparationTasks.keys)
293293
}
294294

295295
await scheduleBackgroundIndex(files: changedFiles)
@@ -367,7 +367,7 @@ public final actor SemanticIndexManager {
367367
// schedule two preparations of the same target in quick succession, only the first one actually performs a prepare
368368
// and the second one will be a no-op once it runs.
369369
let targetsToPrepare = await targets.asyncFilter {
370-
await !preparationUpToDateStatus.isUpToDate($0)
370+
await !preparationUpToDateTracker.isUpToDate($0)
371371
}
372372

373373
guard !targetsToPrepare.isEmpty else {
@@ -378,7 +378,7 @@ public final actor SemanticIndexManager {
378378
PreparationTaskDescription(
379379
targetsToPrepare: targetsToPrepare,
380380
buildSystemManager: self.buildSystemManager,
381-
preparationUpToDateStatus: preparationUpToDateStatus,
381+
preparationUpToDateTracker: preparationUpToDateTracker,
382382
indexProcessDidProduceResult: indexProcessDidProduceResult,
383383
testHooks: testHooks
384384
)
@@ -425,7 +425,7 @@ public final actor SemanticIndexManager {
425425
filesToIndex: filesAndTargets,
426426
buildSystemManager: self.buildSystemManager,
427427
index: index,
428-
indexStoreUpToDateStatus: indexStoreUpToDateStatus,
428+
indexStoreUpToDateTracker: indexStoreUpToDateTracker,
429429
indexProcessDidProduceResult: indexProcessDidProduceResult,
430430
testHooks: testHooks
431431
)
@@ -470,7 +470,7 @@ public final actor SemanticIndexManager {
470470
// schedule two indexing jobs for the same file in quick succession, only the first one actually updates the index
471471
// store and the second one will be a no-op once it runs.
472472
let outOfDateFiles = await filesToIndex(toCover: files).asyncFilter {
473-
if await indexStoreUpToDateStatus.isUpToDate($0.sourceFile) {
473+
if await indexStoreUpToDateTracker.isUpToDate($0.sourceFile) {
474474
return false
475475
}
476476
guard let language = await buildSystemManager.defaultLanguage(for: $0.mainFile),

Sources/SemanticIndex/IndexStatusManager.swift renamed to Sources/SemanticIndex/UpToDateTracker.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Foundation
1414
import SKCore
1515

1616
/// Keeps track of whether an item (a target or file to index) is up-to-date.
17-
actor IndexUpToDateStatusManager<Item: Hashable> {
17+
actor UpToDateTracker<Item: Hashable> {
1818
private enum Status {
1919
/// The item is up-to-date.
2020
case upToDate
@@ -57,7 +57,7 @@ actor IndexUpToDateStatusManager<Item: Hashable> {
5757
}
5858
}
5959

60-
func markAllOutOfDate() {
60+
func markAllKnownOutOfDate() {
6161
markOutOfDate(status.keys)
6262
}
6363

Sources/SemanticIndex/UpdateIndexStoreTaskDescription.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public struct UpdateIndexStoreTaskDescription: IndexTaskDescription {
105105
/// The build system manager that is used to get the toolchain and build settings for the files to index.
106106
private let buildSystemManager: BuildSystemManager
107107

108-
private let indexStoreUpToDateStatus: IndexUpToDateStatusManager<DocumentURI>
108+
private let indexStoreUpToDateTracker: UpToDateTracker<DocumentURI>
109109

110110
/// A reference to the underlying index store. Used to check if the index is already up-to-date for a file, in which
111111
/// case we don't need to index it again.
@@ -138,14 +138,14 @@ public struct UpdateIndexStoreTaskDescription: IndexTaskDescription {
138138
filesToIndex: [FileAndTarget],
139139
buildSystemManager: BuildSystemManager,
140140
index: UncheckedIndex,
141-
indexStoreUpToDateStatus: IndexUpToDateStatusManager<DocumentURI>,
141+
indexStoreUpToDateTracker: UpToDateTracker<DocumentURI>,
142142
indexProcessDidProduceResult: @escaping @Sendable (IndexProcessResult) -> Void,
143143
testHooks: IndexTestHooks
144144
) {
145145
self.filesToIndex = filesToIndex
146146
self.buildSystemManager = buildSystemManager
147147
self.index = index
148-
self.indexStoreUpToDateStatus = indexStoreUpToDateStatus
148+
self.indexStoreUpToDateTracker = indexStoreUpToDateTracker
149149
self.indexProcessDidProduceResult = indexProcessDidProduceResult
150150
self.testHooks = testHooks
151151
}
@@ -202,7 +202,7 @@ public struct UpdateIndexStoreTaskDescription: IndexTaskDescription {
202202
}
203203

204204
private func updateIndexStore(forSingleFile file: FileToIndex, in target: ConfiguredTarget) async {
205-
guard await !indexStoreUpToDateStatus.isUpToDate(file.sourceFile) else {
205+
guard await !indexStoreUpToDateTracker.isUpToDate(file.sourceFile) else {
206206
// If we know that the file is up-to-date without having ot hit the index, do that because it's fastest.
207207
return
208208
}
@@ -264,7 +264,7 @@ public struct UpdateIndexStoreTaskDescription: IndexTaskDescription {
264264
"Not updating index store for \(file) because it is a language that is not supported by background indexing"
265265
)
266266
}
267-
await indexStoreUpToDateStatus.markUpToDate([file.sourceFile], updateOperationStartDate: startDate)
267+
await indexStoreUpToDateTracker.markUpToDate([file.sourceFile], updateOperationStartDate: startDate)
268268
}
269269

270270
private func updateIndexStore(

0 commit comments

Comments
 (0)