Skip to content

Commit 7b79431

Browse files
committed
Address review comments from swiftlang#1322
1 parent 65dfba6 commit 7b79431

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

Sources/SemanticIndex/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_library(SemanticIndex STATIC
88
SemanticIndexManager.swift
99
TestHooks.swift
1010
UpdateIndexStoreTaskDescription.swift
11+
UpToDateTracker.swift
1112
)
1213
set_target_properties(SemanticIndex PROPERTIES
1314
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
}
@@ -79,7 +79,7 @@ public struct PreparationTaskDescription: IndexTaskDescription {
7979
scope: "preparation-\(id % 100)"
8080
) {
8181
let targetsToPrepare = await targetsToPrepare.asyncFilter {
82-
await !preparationUpToDateStatus.isUpToDate($0)
82+
await !preparationUpToDateTracker.isUpToDate($0)
8383
}.sorted(by: {
8484
($0.targetID, $0.runDestinationID) < ($1.targetID, $1.runDestinationID)
8585
})
@@ -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
logger.log(
120120
"Finished preparation in \(Date().timeIntervalSince(startDate) * 1000, privacy: .public)ms: \(targetsToPrepareDescription)"

Sources/SemanticIndex/SemanticIndexManager.swift

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

79-
private let preparationUpToDateStatus = IndexUpToDateStatusManager<ConfiguredTarget>()
79+
private let preparationUpToDateTracker = UpToDateTracker<ConfiguredTarget>()
8080

81-
private let indexStoreUpToDateStatus = IndexUpToDateStatusManager<DocumentURI>()
81+
private let indexStoreUpToDateTracker = UpToDateTracker<DocumentURI>()
8282

8383
/// The preparation tasks that have been started and are either scheduled in the task scheduler or currently
8484
/// executing.
@@ -258,23 +258,23 @@ public final actor SemanticIndexManager {
258258
// We only re-index the files that were changed and don't re-index any of their dependencies. See the
259259
// `Documentation/Files_To_Reindex.md` file.
260260
let changedFiles = events.map(\.uri)
261-
await indexStoreUpToDateStatus.markOutOfDate(changedFiles)
261+
await indexStoreUpToDateTracker.markOutOfDate(changedFiles)
262262

263263
// Note that configured targets are the right abstraction layer here (instead of a non-configured target) because a
264264
// build system might have targets that include different source files. Hence a source file might be in target T
265265
// configured for macOS but not in target T configured for iOS.
266266
let targets = await changedFiles.asyncMap { await buildSystemManager.configuredTargets(for: $0) }.flatMap { $0 }
267267
if let dependentTargets = await buildSystemManager.targets(dependingOn: targets) {
268-
await preparationUpToDateStatus.markOutOfDate(dependentTargets)
268+
await preparationUpToDateTracker.markOutOfDate(dependentTargets)
269269
} else {
270-
await preparationUpToDateStatus.markAllOutOfDate()
270+
await preparationUpToDateTracker.markAllKnownOutOfDate()
271271
// `markAllOutOfDate` only marks targets out-of-date that have been indexed before. Also mark all targets with
272272
// in-progress preparation out of date. So we don't get into the following situation, which would result in an
273273
// incorrect up-to-date status of a target
274274
// - Target preparation starts for the first time
275275
// - Files changed
276276
// - Target preparation finishes.
277-
await preparationUpToDateStatus.markOutOfDate(inProgressPreparationTasks.keys)
277+
await preparationUpToDateTracker.markOutOfDate(inProgressPreparationTasks.keys)
278278
}
279279

280280
await scheduleBackgroundIndex(files: changedFiles)
@@ -352,7 +352,7 @@ public final actor SemanticIndexManager {
352352
// schedule two preparations of the same target in quick succession, only the first one actually performs a prepare
353353
// and the second one will be a no-op once it runs.
354354
let targetsToPrepare = await targets.asyncFilter {
355-
await !preparationUpToDateStatus.isUpToDate($0)
355+
await !preparationUpToDateTracker.isUpToDate($0)
356356
}
357357

358358
guard !targetsToPrepare.isEmpty else {
@@ -363,7 +363,7 @@ public final actor SemanticIndexManager {
363363
PreparationTaskDescription(
364364
targetsToPrepare: targetsToPrepare,
365365
buildSystemManager: self.buildSystemManager,
366-
preparationUpToDateStatus: preparationUpToDateStatus,
366+
preparationUpToDateTracker: preparationUpToDateTracker,
367367
indexProcessDidProduceResult: indexProcessDidProduceResult,
368368
testHooks: testHooks
369369
)
@@ -410,7 +410,7 @@ public final actor SemanticIndexManager {
410410
filesToIndex: filesAndTargets,
411411
buildSystemManager: self.buildSystemManager,
412412
index: index,
413-
indexStoreUpToDateStatus: indexStoreUpToDateStatus,
413+
indexStoreUpToDateTracker: indexStoreUpToDateTracker,
414414
indexProcessDidProduceResult: indexProcessDidProduceResult,
415415
testHooks: testHooks
416416
)
@@ -455,7 +455,7 @@ public final actor SemanticIndexManager {
455455
// schedule two indexing jobs for the same file in quick succession, only the first one actually updates the index
456456
// store and the second one will be a no-op once it runs.
457457
let outOfDateFiles = await filesToIndex(toCover: files).asyncFilter {
458-
return await !indexStoreUpToDateStatus.isUpToDate($0.sourceFile)
458+
return await !indexStoreUpToDateTracker.isUpToDate($0.sourceFile)
459459
}
460460
// sort files to get deterministic indexing order
461461
.sorted(by: { $0.sourceFile.stringValue < $1.sourceFile.stringValue })

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
@@ -89,7 +89,7 @@ public struct UpdateIndexStoreTaskDescription: IndexTaskDescription {
8989
/// The build system manager that is used to get the toolchain and build settings for the files to index.
9090
private let buildSystemManager: BuildSystemManager
9191

92-
private let indexStoreUpToDateStatus: IndexUpToDateStatusManager<DocumentURI>
92+
private let indexStoreUpToDateTracker: UpToDateTracker<DocumentURI>
9393

9494
/// A reference to the underlying index store. Used to check if the index is already up-to-date for a file, in which
9595
/// case we don't need to index it again.
@@ -118,14 +118,14 @@ public struct UpdateIndexStoreTaskDescription: IndexTaskDescription {
118118
filesToIndex: [FileAndTarget],
119119
buildSystemManager: BuildSystemManager,
120120
index: UncheckedIndex,
121-
indexStoreUpToDateStatus: IndexUpToDateStatusManager<DocumentURI>,
121+
indexStoreUpToDateTracker: UpToDateTracker<DocumentURI>,
122122
indexProcessDidProduceResult: @escaping @Sendable (IndexProcessResult) -> Void,
123123
testHooks: IndexTestHooks
124124
) {
125125
self.filesToIndex = filesToIndex
126126
self.buildSystemManager = buildSystemManager
127127
self.index = index
128-
self.indexStoreUpToDateStatus = indexStoreUpToDateStatus
128+
self.indexStoreUpToDateTracker = indexStoreUpToDateTracker
129129
self.indexProcessDidProduceResult = indexProcessDidProduceResult
130130
self.testHooks = testHooks
131131
}
@@ -185,7 +185,7 @@ public struct UpdateIndexStoreTaskDescription: IndexTaskDescription {
185185
}
186186

187187
private func updateIndexStore(forSingleFile file: FileToIndex, in target: ConfiguredTarget) async {
188-
guard await !indexStoreUpToDateStatus.isUpToDate(file.sourceFile) else {
188+
guard await !indexStoreUpToDateTracker.isUpToDate(file.sourceFile) else {
189189
// If we know that the file is up-to-date without having ot hit the index, do that because it's fastest.
190190
return
191191
}
@@ -247,7 +247,7 @@ public struct UpdateIndexStoreTaskDescription: IndexTaskDescription {
247247
"Not updating index store for \(file) because it is a language that is not supported by background indexing"
248248
)
249249
}
250-
await indexStoreUpToDateStatus.markUpToDate([file.sourceFile], updateOperationStartDate: startDate)
250+
await indexStoreUpToDateTracker.markUpToDate([file.sourceFile], updateOperationStartDate: startDate)
251251
}
252252

253253
private func updateIndexStore(

0 commit comments

Comments
 (0)