1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#if compiler(>=6)
import BuildServerProtocol
package import LanguageServerProtocol
import LanguageServerProtocolExtensions
import SKLogging
package import SwiftExtensions
#else
import BuildServerProtocol
import LanguageServerProtocol
import LanguageServerProtocolExtensions
import SKLogging
import SwiftExtensions
#endif
/// A lightweight way of describing tasks that are created from handling BSP
/// requests or notifications for the purpose of dependency tracking.
package enum BuildSystemMessageDependencyTracker: QueueBasedMessageHandlerDependencyTracker {
/// A task that modifies some state. It is a barrier for all requests that read state.
case stateChange
/// A task that reads state, such as getting all build targets. These tasks can be run concurrently with other tasks
/// that read state but needs to wait for all state changes to be handled first.
case stateRead
/// A task that is responsible for logging information to the client. They can be run concurrently to any state read
/// and changes but logging tasks must be ordered among each other.
case taskProgress
/// Whether this request needs to finish before `other` can start executing.
package func isDependency(of other: BuildSystemMessageDependencyTracker) -> Bool {
switch (self, other) {
case (.stateChange, .stateChange): return true
case (.stateChange, .stateRead): return true
case (.stateRead, .stateChange): return true
case (.stateRead, .stateRead): return false
case (.taskProgress, .taskProgress): return true
case (.taskProgress, _): return false
case (_, .taskProgress): return false
}
}
package init(_ notification: some NotificationType) {
switch notification {
case is FileOptionsChangedNotification:
self = .stateChange
case is OnBuildExitNotification:
self = .stateChange
case is OnBuildInitializedNotification:
self = .stateChange
case is OnBuildLogMessageNotification:
self = .taskProgress
case is OnBuildTargetDidChangeNotification:
self = .stateChange
case is OnWatchedFilesDidChangeNotification:
self = .stateChange
case is TaskFinishNotification:
self = .taskProgress
case is TaskProgressNotification:
self = .taskProgress
case is TaskStartNotification:
self = .taskProgress
default:
logger.error(
"""
Unknown notification \(type(of: notification)). Treating as a stateChange notification. \
This might lead to sub-optimal performance because it inhibits parallelism.
"""
)
self = .stateRead
}
}
package func dependencies(in pendingTasks: [PendingTask<Self>]) -> [PendingTask<Self>] {
return pendingTasks.filter { $0.metadata.isDependency(of: self) }
}
package init(_ request: some RequestType) {
switch request {
case is BuildShutdownRequest:
self = .stateChange
case is BuildTargetPrepareRequest:
self = .stateRead
case is BuildTargetSourcesRequest:
self = .stateRead
case is TaskStartNotification, is TaskProgressNotification, is TaskFinishNotification:
self = .taskProgress
case is InitializeBuildRequest:
self = .stateChange
case is RegisterForChanges:
self = .stateChange
case is TextDocumentSourceKitOptionsRequest:
self = .stateRead
case is WorkspaceBuildTargetsRequest:
self = .stateRead
case is WorkspaceWaitForBuildSystemUpdatesRequest:
self = .stateRead
default:
logger.error(
"""
Unknown request \(type(of: request)). Treating as a stateChange request. \
This might lead to sub-optimal performance because it inhibits parallelism.
"""
)
self = .stateChange
}
}
}
|