-
Notifications
You must be signed in to change notification settings - Fork 314
Split up-to-date status tracking and index progress tracking #1322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
atrick
merged 1 commit into
swiftlang:main
from
ahoppen:split-status-and-progress-tracking
May 21, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Foundation | ||
import SKCore | ||
|
||
/// Keeps track of whether an item (a target or file to index) is up-to-date. | ||
actor IndexUpToDateStatusManager<Item: Hashable> { | ||
private enum Status { | ||
/// The item is up-to-date. | ||
case upToDate | ||
|
||
/// The target or file has been marked out-of-date at the given date. | ||
/// | ||
/// Keeping track of the date is necessary so that we don't mark a target as up-to-date if we have the following | ||
/// ordering of events: | ||
/// - Preparation started | ||
/// - Target marked out of date | ||
/// - Preparation finished | ||
case outOfDate(Date) | ||
} | ||
|
||
private var status: [Item: Status] = [:] | ||
|
||
/// Mark the target or file as up-to-date from a preparation/update-indexstore operation started at | ||
/// `updateOperationStartDate`. | ||
/// | ||
/// See comment on `Status.outOfDate` why `updateOperationStartDate` needs to be passed. | ||
func markUpToDate(_ items: [Item], updateOperationStartDate: Date) { | ||
for item in items { | ||
switch status[item] { | ||
case .upToDate: | ||
break | ||
case .outOfDate(let markedOutOfDate): | ||
if markedOutOfDate < updateOperationStartDate { | ||
status[item] = .upToDate | ||
} | ||
case nil: | ||
status[item] = .upToDate | ||
} | ||
} | ||
} | ||
|
||
func markOutOfDate(_ items: some Collection<Item>) { | ||
let date = Date() | ||
for item in items { | ||
status[item] = .outOfDate(date) | ||
} | ||
} | ||
|
||
func markAllOutOfDate() { | ||
markOutOfDate(status.keys) | ||
} | ||
|
||
func isUpToDate(_ item: Item) -> Bool { | ||
if case .upToDate = status[item] { | ||
return true | ||
} | ||
return false | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could drop the
Index
? Could beOperationStatusManager
? Not a huge fan ofManager
though 🤔.OperationStatusTracker
? 🤷There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I’d like to stick with
UpToDate
in the name because the two states areupToDate
andoutOfDate
. I’ll go withUpToDateTracker
.