Skip to content

[6.2][Concurrency] Add underscore prefixes for not yet official API. #81532

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

Closed
Closed
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: 1 addition & 1 deletion include/swift/AST/KnownProtocols.def
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ PROTOCOL(Executor)
PROTOCOL(SerialExecutor)
PROTOCOL(TaskExecutor)
PROTOCOL(GlobalActor)
PROTOCOL(ExecutorFactory)
PROTOCOL_(ExecutorFactory)

PROTOCOL_(BridgedNSError)
PROTOCOL_(BridgedStoredNSError)
Expand Down
4 changes: 2 additions & 2 deletions lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ Type SILGenModule::getConfiguredExecutorFactory() {
auto &ctx = getASTContext();

// Look in the main module for a typealias
Type factory = ctx.getNamedSwiftType(ctx.MainModule, "DefaultExecutorFactory");
Type factory = ctx.getNamedSwiftType(ctx.MainModule, "_DefaultExecutorFactory");

// If we don't find it, fall back to _Concurrency.PlatformExecutorFactory
if (!factory)
Expand All @@ -531,7 +531,7 @@ Type SILGenModule::getDefaultExecutorFactory() {
if (!module)
return Type();

return ctx.getNamedSwiftType(module, "DefaultExecutorFactory");
return ctx.getNamedSwiftType(module, "_DefaultExecutorFactory");
}

ProtocolConformance *SILGenModule::getNSErrorConformanceToError() {
Expand Down
10 changes: 5 additions & 5 deletions stdlib/public/Concurrency/CFExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ enum CoreFoundation {
// .. Main Executor ............................................................

@available(SwiftStdlib 6.2, *)
public final class CFMainExecutor: DispatchMainExecutor, @unchecked Sendable {
public final class _CFMainExecutor: _DispatchMainExecutor, @unchecked Sendable {

override public func run() throws {
override public func _run() throws {
CoreFoundation.CFRunLoopRun()
}

override public func stop() {
override public func _stop() {
unsafe CoreFoundation.CFRunLoopStop(CoreFoundation.CFRunLoopGetMain())
}

Expand All @@ -59,8 +59,8 @@ public final class CFMainExecutor: DispatchMainExecutor, @unchecked Sendable {
// .. Task Executor ............................................................

@available(SwiftStdlib 6.2, *)
public final class CFTaskExecutor: DispatchGlobalTaskExecutor,
@unchecked Sendable {
public final class _CFTaskExecutor: _DispatchGlobalTaskExecutor,
@unchecked Sendable {

}

Expand Down
34 changes: 17 additions & 17 deletions stdlib/public/Concurrency/Clock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public protocol Clock<Duration>: Sendable {

/// The traits associated with this clock instance.
@available(SwiftStdlib 6.2, *)
var traits: ClockTraits { get }
var _traits: _ClockTraits { get }

/// Convert a Clock-specific Duration to a Swift Duration
///
Expand All @@ -60,7 +60,7 @@ public protocol Clock<Duration>: Sendable {
/// Returns: A `Swift.Duration` representing the equivalent duration, or
/// `nil` if this function is not supported.
@available(SwiftStdlib 6.2, *)
func convert(from duration: Duration) -> Swift.Duration?
func _convert(from duration: Duration) -> Swift.Duration?

/// Convert a Swift Duration to a Clock-specific Duration
///
Expand All @@ -71,7 +71,7 @@ public protocol Clock<Duration>: Sendable {
/// Returns: A `Duration` representing the equivalent duration, or
/// `nil` if this function is not supported.
@available(SwiftStdlib 6.2, *)
func convert(from duration: Swift.Duration) -> Duration?
func _convert(from duration: Swift.Duration) -> Duration?

/// Convert an `Instant` from some other clock's `Instant`
///
Expand All @@ -83,8 +83,8 @@ public protocol Clock<Duration>: Sendable {
/// Returns: An `Instant` representing the equivalent instant, or
/// `nil` if this function is not supported.
@available(SwiftStdlib 6.2, *)
func convert<OtherClock: Clock>(instant: OtherClock.Instant,
from clock: OtherClock) -> Instant?
func _convert<OtherClock: Clock>(instant: OtherClock.Instant,
from clock: OtherClock) -> Instant?
}

@available(SwiftStdlib 5.7, *)
Expand Down Expand Up @@ -143,27 +143,27 @@ extension Clock {
@available(SwiftStdlib 6.2, *)
extension Clock {
// For compatibility, return `nil` if this is not implemented
public func convert(from duration: Duration) -> Swift.Duration? {
public func _convert(from duration: Duration) -> Swift.Duration? {
return nil
}

public func convert(from duration: Swift.Duration) -> Duration? {
public func _convert(from duration: Swift.Duration) -> Duration? {
return nil
}

public func convert<OtherClock: Clock>(instant: OtherClock.Instant,
from clock: OtherClock) -> Instant? {
public func _convert<OtherClock: Clock>(instant: OtherClock.Instant,
from clock: OtherClock) -> Instant? {
let ourNow = now
let otherNow = clock.now
let otherDuration = otherNow.duration(to: instant)

// Convert to `Swift.Duration`
guard let duration = clock.convert(from: otherDuration) else {
guard let duration = clock._convert(from: otherDuration) else {
return nil
}

// Convert from `Swift.Duration`
guard let ourDuration = convert(from: duration) else {
guard let ourDuration = _convert(from: duration) else {
return nil
}

Expand All @@ -173,7 +173,7 @@ extension Clock {

@available(SwiftStdlib 6.2, *)
extension Clock where Duration == Swift.Duration {
public func convert(from duration: Duration) -> Duration? {
public func _convert(from duration: Duration) -> Duration? {
return duration
}
}
Expand Down Expand Up @@ -208,28 +208,28 @@ extension Clock {
/// time or delay in. Executors are expected to do this on a best effort
/// basis.
@available(SwiftStdlib 6.2, *)
public struct ClockTraits: OptionSet {
public struct _ClockTraits: OptionSet {
public let rawValue: UInt32

public init(rawValue: UInt32) {
self.rawValue = rawValue
}

/// Clocks with this trait continue running while the machine is asleep.
public static let continuous = ClockTraits(rawValue: 1 << 0)
public static let continuous = _ClockTraits(rawValue: 1 << 0)

/// Indicates that a clock's time will only ever increase.
public static let monotonic = ClockTraits(rawValue: 1 << 1)
public static let monotonic = _ClockTraits(rawValue: 1 << 1)

/// Clocks with this trait are tied to "wall time".
public static let wallTime = ClockTraits(rawValue: 1 << 2)
public static let wallTime = _ClockTraits(rawValue: 1 << 2)
}

@available(SwiftStdlib 6.2, *)
extension Clock {
/// The traits associated with this clock instance.
@available(SwiftStdlib 6.2, *)
public var traits: ClockTraits {
public var _traits: _ClockTraits {
return []
}
}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/Concurrency/ContinuousClock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ extension ContinuousClock: Clock {

/// The continuous clock is continuous and monotonic
@available(SwiftStdlib 6.2, *)
public var traits: ClockTraits {
public var _traits: _ClockTraits {
return [.continuous, .monotonic]
}

Expand Down
60 changes: 30 additions & 30 deletions stdlib/public/Concurrency/CooperativeExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,37 @@ import Swift
extension ExecutorJob {
fileprivate var cooperativeExecutorTimestampIsIndirect: Bool {
return MemoryLayout<(Int, Int)>.size
< MemoryLayout<CooperativeExecutor.Timestamp>.size
< MemoryLayout<_CooperativeExecutor.Timestamp>.size
}

fileprivate var cooperativeExecutorTimestampPointer: UnsafeMutablePointer<CooperativeExecutor.Timestamp> {
fileprivate var cooperativeExecutorTimestampPointer: UnsafeMutablePointer<_CooperativeExecutor.Timestamp> {
get {
assert(cooperativeExecutorTimestampIsIndirect)
return unsafe withUnsafeExecutorPrivateData {
unsafe $0.withMemoryRebound(to: UnsafeMutablePointer<CooperativeExecutor.Timestamp>.self) {
return unsafe _withUnsafeExecutorPrivateData {
unsafe $0.withMemoryRebound(to: UnsafeMutablePointer<_CooperativeExecutor.Timestamp>.self) {
return unsafe $0[0]
}
}
}
set {
assert(cooperativeExecutorTimestampIsIndirect)
unsafe withUnsafeExecutorPrivateData {
unsafe $0.withMemoryRebound(to: UnsafeMutablePointer<CooperativeExecutor.Timestamp>.self) {
unsafe _withUnsafeExecutorPrivateData {
unsafe $0.withMemoryRebound(to: UnsafeMutablePointer<_CooperativeExecutor.Timestamp>.self) {
unsafe $0[0] = newValue
}
}
}
}

fileprivate var cooperativeExecutorTimestamp: CooperativeExecutor.Timestamp {
fileprivate var cooperativeExecutorTimestamp: _CooperativeExecutor.Timestamp {
get {
if cooperativeExecutorTimestampIsIndirect {
let ptr = unsafe cooperativeExecutorTimestampPointer
return unsafe ptr.pointee
} else {
return unsafe withUnsafeExecutorPrivateData {
return unsafe _withUnsafeExecutorPrivateData {
return unsafe $0.assumingMemoryBound(
to: CooperativeExecutor.Timestamp.self
to: _CooperativeExecutor.Timestamp.self
)[0]
}
}
Expand All @@ -61,8 +61,8 @@ extension ExecutorJob {
let ptr = unsafe cooperativeExecutorTimestampPointer
unsafe ptr.pointee = newValue
} else {
unsafe withUnsafeExecutorPrivateData {
unsafe $0.withMemoryRebound(to: CooperativeExecutor.Timestamp.self) {
unsafe _withUnsafeExecutorPrivateData {
unsafe $0.withMemoryRebound(to: _CooperativeExecutor.Timestamp.self) {
unsafe $0[0] = newValue
}
}
Expand All @@ -73,10 +73,10 @@ extension ExecutorJob {
fileprivate mutating func setupCooperativeExecutorTimestamp() {
// If a Timestamp won't fit, allocate
if cooperativeExecutorTimestampIsIndirect {
let ptr: UnsafeMutablePointer<CooperativeExecutor.Timestamp>
let ptr: UnsafeMutablePointer<_CooperativeExecutor.Timestamp>
// Try to use the task allocator if it has one
if let allocator {
unsafe ptr = allocator.allocate(as: CooperativeExecutor.Timestamp.self)
unsafe ptr = allocator.allocate(as: _CooperativeExecutor.Timestamp.self)
} else {
unsafe ptr = .allocate(capacity: 1)
}
Expand All @@ -100,7 +100,7 @@ extension ExecutorJob {
/// A co-operative executor that can be used as the main executor or as a
/// task executor.
@available(SwiftStdlib 6.2, *)
class CooperativeExecutor: Executor, @unchecked Sendable {
class _CooperativeExecutor: Executor, @unchecked Sendable {
var runQueue: PriorityQueue<UnownedJob>
var waitQueue: PriorityQueue<UnownedJob>
var shouldStop: Bool = false
Expand Down Expand Up @@ -174,13 +174,13 @@ class CooperativeExecutor: Executor, @unchecked Sendable {
runQueue.push(UnownedJob(job))
}

public var isMainExecutor: Bool { true }
public var _isMainExecutor: Bool { true }

public var asSchedulable: any SchedulableExecutor { self }
public var _asSchedulable: any _SchedulableExecutor { self }
}

@available(SwiftStdlib 6.2, *)
extension CooperativeExecutor: SchedulableExecutor {
extension _CooperativeExecutor: _SchedulableExecutor {
var currentTime: Timestamp {
var now: Timestamp = .zero
unsafe _getTime(seconds: &now.seconds,
Expand All @@ -189,11 +189,11 @@ extension CooperativeExecutor: SchedulableExecutor {
return now
}

public func enqueue<C: Clock>(_ job: consuming ExecutorJob,
after delay: C.Duration,
tolerance: C.Duration? = nil,
clock: C) {
let duration = Duration(from: clock.convert(from: delay)!)
public func _enqueue<C: Clock>(_ job: consuming ExecutorJob,
after delay: C.Duration,
tolerance: C.Duration? = nil,
clock: C) {
let duration = Duration(from: clock._convert(from: delay)!)
let deadline = self.currentTime + duration

job.setupCooperativeExecutorTimestamp()
Expand All @@ -203,12 +203,12 @@ extension CooperativeExecutor: SchedulableExecutor {
}

@available(SwiftStdlib 6.2, *)
extension CooperativeExecutor: RunLoopExecutor {
public func run() throws {
try runUntil { false }
extension _CooperativeExecutor: _RunLoopExecutor {
public func _run() throws {
try _runUntil { false }
}

public func runUntil(_ condition: () -> Bool) throws {
public func _runUntil(_ condition: () -> Bool) throws {
shouldStop = false
while !shouldStop && !condition() {
// Process the timer queue
Expand Down Expand Up @@ -244,18 +244,18 @@ extension CooperativeExecutor: RunLoopExecutor {
}
}

public func stop() {
public func _stop() {
shouldStop = true
}
}

@available(SwiftStdlib 6.2, *)
extension CooperativeExecutor: SerialExecutor {}
extension _CooperativeExecutor: SerialExecutor {}

@available(SwiftStdlib 6.2, *)
extension CooperativeExecutor: TaskExecutor {}
extension _CooperativeExecutor: TaskExecutor {}

@available(SwiftStdlib 6.2, *)
extension CooperativeExecutor: MainExecutor {}
extension _CooperativeExecutor: _MainExecutor {}

#endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
Loading