Skip to content
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

Replace DispatchTimeInterval with Duration #8105

Draft
wants to merge 2 commits into
base: maxd/async-evaluate-manifest
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/Basics/DispatchTimeInterval+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ extension DispatchTimeInterval {
return nil
}
}
}

extension Duration {
public var descriptionInSeconds: String {
switch self {
case .seconds(let value):
Expand Down
2 changes: 1 addition & 1 deletion Sources/Basics/SendableTimeInterval.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ extension DispatchTimeInterval: @unchecked Sendable {}

/// This typealias hides `DispatchTimeInterval` as an implementation detail until we can use `Swift.Duration`, as the
/// latter requires macOS 13.
public typealias SendableTimeInterval = DispatchTimeInterval
public typealias SendableTimeInterval = Duration
14 changes: 9 additions & 5 deletions Sources/Commands/CommandWorkspaceDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ final class CommandWorkspaceDelegate: WorkspaceDelegate {
self.outputHandler("Fetching \(packageLocation ?? package.description)\(fetchDetails.fromCache ? " from cache" : "")", false)
}

func didFetchPackage(package: PackageIdentity, packageLocation: String?, result: Result<PackageFetchDetails, Error>, duration: DispatchTimeInterval) {
func didFetchPackage(package: PackageIdentity, packageLocation: String?, result: Result<PackageFetchDetails, Error>, duration: Duration) {
guard case .success = result, !self.observabilityScope.errorsReported else {
return
}
Expand Down Expand Up @@ -103,7 +103,7 @@ final class CommandWorkspaceDelegate: WorkspaceDelegate {
self.outputHandler("Updating \(url)", false)
}

func didUpdateRepository(package: PackageIdentity, repository url: String, duration: DispatchTimeInterval) {
func didUpdateRepository(package: PackageIdentity, repository url: String, duration: Duration) {
self.outputHandler("Updated \(url) (\(duration.descriptionInSeconds))", false)
}

Expand All @@ -115,7 +115,7 @@ final class CommandWorkspaceDelegate: WorkspaceDelegate {
self.outputHandler("Creating working copy for \(url)", false)
}

func didCheckOut(package: PackageIdentity, repository url: String, revision: String, at path: AbsolutePath, duration: DispatchTimeInterval) {
func didCheckOut(package: PackageIdentity, repository url: String, revision: String, at path: AbsolutePath, duration: Duration) {
self.outputHandler("Working copy of \(url) resolved at \(revision)", false)
}

Expand All @@ -131,7 +131,7 @@ final class CommandWorkspaceDelegate: WorkspaceDelegate {
self.outputHandler("Computing version for \(location)", false)
}

func didComputeVersion(package: PackageIdentity, location: String, version: String, duration: DispatchTimeInterval) {
func didComputeVersion(package: PackageIdentity, location: String, version: String, duration: Duration) {
self.outputHandler("Computed \(location) at \(version) (\(duration.descriptionInSeconds))", false)
}

Expand All @@ -143,7 +143,11 @@ final class CommandWorkspaceDelegate: WorkspaceDelegate {
}
}

func didDownloadBinaryArtifact(from url: String, result: Result<(path: AbsolutePath, fromCache: Bool), Error>, duration: DispatchTimeInterval) {
func didDownloadBinaryArtifact(
from url: String,
result: Result<(path: AbsolutePath, fromCache: Bool), Error>,
duration: Duration
) {
guard case .success(let fetchDetails) = result, !self.observabilityScope.errorsReported else {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import struct TSCUtility.Version

public protocol DependencyResolverDelegate {
func willResolve(term: Term)
func didResolve(term: Term, version: Version, duration: DispatchTimeInterval)
func didResolve(term: Term, version: Version, duration: Duration)

func derived(term: Term)
func conflict(conflict: Incompatibility)
Expand All @@ -39,7 +39,7 @@ public struct ObservabilityDependencyResolverDelegate: DependencyResolverDelegat
self.debug("resolving '\(term.node.package.identity)'")
}

public func didResolve(term: Term, version: Version, duration: DispatchTimeInterval) {
public func didResolve(term: Term, version: Version, duration: Duration) {
self.debug("resolved '\(term.node.package.identity)' @ '\(version)'")
}

Expand Down Expand Up @@ -86,7 +86,7 @@ public struct MultiplexResolverDelegate: DependencyResolverDelegate {
underlying.forEach { $0.willResolve(term: term) }
}

public func didResolve(term: Term, version: Version, duration: DispatchTimeInterval) {
public func didResolve(term: Term, version: Version, duration: Duration) {
underlying.forEach { $0.didResolve(term: term, version: version, duration: duration) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ public struct PubGrubDependencyResolver {

// Prefer packages with least number of versions that fit the current requirements so we
// get conflicts (if any) sooner.
let start = DispatchTime.now()
let start = ContinuousClock.now
let counts = try await self.computeCounts(for: undecided)
// forced unwraps safe since we are testing for count and errors above
let pkgTerm = undecided.min {
Expand Down Expand Up @@ -758,7 +758,7 @@ public struct PubGrubDependencyResolver {

// Decide this version if there was no conflict with its dependencies.
if !haveConflict {
self.delegate?.didResolve(term: pkgTerm, version: version, duration: start.distance(to: .now()))
self.delegate?.didResolve(term: pkgTerm, version: version, duration: .now - start)
state.decide(pkgTerm.node, at: version)
}

Expand Down
Loading