Skip to content

Commit bd289dc

Browse files
committed
[Concurrency] Remove custom global executors from 6.2.
The custom global executors work is not landing in 6.2, so make sure it isn't public there. rdar://151147606
1 parent 07bb587 commit bd289dc

25 files changed

+75
-1633
lines changed

lib/SILGen/SILGenFunction.cpp

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,28 +1387,6 @@ void SILGenFunction::emitArtificialTopLevel(Decl *mainDecl) {
13871387
}
13881388
}
13891389

1390-
static bool isCreateExecutorsFunctionAvailable(SILGenModule &SGM) {
1391-
FuncDecl *createExecutorsFuncDecl = SGM.getCreateExecutors();
1392-
if (!createExecutorsFuncDecl)
1393-
return false;
1394-
1395-
auto &ctx = createExecutorsFuncDecl->getASTContext();
1396-
1397-
if (ctx.LangOpts.hasFeature(Feature::Embedded))
1398-
return true;
1399-
1400-
if (!ctx.LangOpts.DisableAvailabilityChecking) {
1401-
auto deploymentAvailability = AvailabilityRange::forDeploymentTarget(ctx);
1402-
auto runtimeAvailability = AvailabilityRange::forRuntimeTarget(ctx);
1403-
auto declAvailability = ctx.getCustomGlobalExecutorsAvailability();
1404-
auto declRtAvailability = ctx.getCustomGlobalExecutorsRuntimeAvailability();
1405-
return deploymentAvailability.isContainedIn(declAvailability)
1406-
&& runtimeAvailability.isContainedIn(declRtAvailability);
1407-
}
1408-
1409-
return true;
1410-
}
1411-
14121390
void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
14131391
auto moduleLoc = entryPoint.getAsRegularLocation();
14141392
auto *entryBlock = B.getInsertionBB();
@@ -1424,46 +1402,6 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
14241402

14251403
B.setInsertionPoint(entryBlock);
14261404

1427-
// If we're using a new enough deployment target, and we can find a
1428-
// DefaultExecutorFactory type, call swift_createExecutors()
1429-
Type factoryNonCanTy = SGM.getConfiguredExecutorFactory();
1430-
1431-
if (isCreateExecutorsFunctionAvailable(SGM) && factoryNonCanTy) {
1432-
CanType factoryTy = factoryNonCanTy->getCanonicalType();
1433-
1434-
ProtocolDecl *executorFactoryProtocol
1435-
= ctx.getProtocol(KnownProtocolKind::ExecutorFactory);
1436-
auto conformance = lookupConformance(factoryTy, executorFactoryProtocol);
1437-
1438-
if (conformance.isInvalid()) {
1439-
// If this type doesn't conform, ignore it and use the default factory
1440-
SourceLoc loc = extractNearestSourceLoc(factoryTy);
1441-
1442-
ctx.Diags.diagnose(loc, diag::executor_factory_must_conform);
1443-
1444-
factoryTy = SGM.getDefaultExecutorFactory()->getCanonicalType();
1445-
conformance = lookupConformance(factoryTy, executorFactoryProtocol);
1446-
1447-
assert(!conformance.isInvalid());
1448-
}
1449-
1450-
FuncDecl *createExecutorsFuncDecl = SGM.getCreateExecutors();
1451-
assert(createExecutorsFuncDecl
1452-
&& "Failed to find swift_createExecutors function decl");
1453-
SILFunction *createExecutorsSILFunc =
1454-
SGM.getFunction(SILDeclRef(createExecutorsFuncDecl, SILDeclRef::Kind::Func),
1455-
NotForDefinition);
1456-
SILValue createExecutorsFunc =
1457-
B.createFunctionRefFor(moduleLoc, createExecutorsSILFunc);
1458-
MetatypeType *factoryThickMetaTy
1459-
= MetatypeType::get(factoryTy, MetatypeRepresentation::Thick);
1460-
SILValue factorySILMetaTy
1461-
= B.createMetatype(moduleLoc, getLoweredType(factoryThickMetaTy));
1462-
auto ceSubs = SubstitutionMap::getProtocolSubstitutions(
1463-
conformance.getProtocol(), factoryTy, conformance);
1464-
B.createApply(moduleLoc, createExecutorsFunc, ceSubs, { factorySILMetaTy });
1465-
}
1466-
14671405
auto wrapCallArgs = [this, &moduleLoc](SILValue originalValue, FuncDecl *fd,
14681406
uint32_t paramIndex) -> SILValue {
14691407
Type parameterType = fd->getParameters()->get(paramIndex)->getTypeInContext();

stdlib/public/Concurrency/CFExecutor.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ enum CoreFoundation {
4444
// .. Main Executor ............................................................
4545

4646
@available(StdlibDeploymentTarget 6.2, *)
47-
public final class CFMainExecutor: DispatchMainExecutor, @unchecked Sendable {
47+
final class CFMainExecutor: DispatchMainExecutor, @unchecked Sendable {
4848

4949
override public func run() throws {
5050
CoreFoundation.CFRunLoopRun()
@@ -59,8 +59,8 @@ public final class CFMainExecutor: DispatchMainExecutor, @unchecked Sendable {
5959
// .. Task Executor ............................................................
6060

6161
@available(StdlibDeploymentTarget 6.2, *)
62-
public final class CFTaskExecutor: DispatchGlobalTaskExecutor,
63-
@unchecked Sendable {
62+
final class CFTaskExecutor: DispatchGlobalTaskExecutor,
63+
@unchecked Sendable {
6464

6565
}
6666

stdlib/public/Concurrency/Clock.swift

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -41,50 +41,6 @@ public protocol Clock<Duration>: Sendable {
4141
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
4242
func sleep(until deadline: Instant, tolerance: Instant.Duration?) async throws
4343
#endif
44-
45-
/// The traits associated with this clock instance.
46-
@available(StdlibDeploymentTarget 6.2, *)
47-
var traits: ClockTraits { get }
48-
49-
/// Convert a Clock-specific Duration to a Swift Duration
50-
///
51-
/// Some clocks may define `C.Duration` to be something other than a
52-
/// `Swift.Duration`, but that makes it tricky to convert timestamps
53-
/// between clocks, which is something we want to be able to support.
54-
/// This method will convert whatever `C.Duration` is to a `Swift.Duration`.
55-
///
56-
/// Parameters:
57-
///
58-
/// - from duration: The `Duration` to convert
59-
///
60-
/// Returns: A `Swift.Duration` representing the equivalent duration, or
61-
/// `nil` if this function is not supported.
62-
@available(StdlibDeploymentTarget 6.2, *)
63-
func convert(from duration: Duration) -> Swift.Duration?
64-
65-
/// Convert a Swift Duration to a Clock-specific Duration
66-
///
67-
/// Parameters:
68-
///
69-
/// - from duration: The `Swift.Duration` to convert.
70-
///
71-
/// Returns: A `Duration` representing the equivalent duration, or
72-
/// `nil` if this function is not supported.
73-
@available(StdlibDeploymentTarget 6.2, *)
74-
func convert(from duration: Swift.Duration) -> Duration?
75-
76-
/// Convert an `Instant` from some other clock's `Instant`
77-
///
78-
/// Parameters:
79-
///
80-
/// - instant: The instant to convert.
81-
// - from clock: The clock to convert from.
82-
///
83-
/// Returns: An `Instant` representing the equivalent instant, or
84-
/// `nil` if this function is not supported.
85-
@available(StdlibDeploymentTarget 6.2, *)
86-
func convert<OtherClock: Clock>(instant: OtherClock.Instant,
87-
from clock: OtherClock) -> Instant?
8844
}
8945

9046
@available(StdlibDeploymentTarget 5.7, *)
@@ -140,44 +96,6 @@ extension Clock {
14096
}
14197
}
14298

143-
@available(StdlibDeploymentTarget 6.2, *)
144-
extension Clock {
145-
// For compatibility, return `nil` if this is not implemented
146-
public func convert(from duration: Duration) -> Swift.Duration? {
147-
return nil
148-
}
149-
150-
public func convert(from duration: Swift.Duration) -> Duration? {
151-
return nil
152-
}
153-
154-
public func convert<OtherClock: Clock>(instant: OtherClock.Instant,
155-
from clock: OtherClock) -> Instant? {
156-
let ourNow = now
157-
let otherNow = clock.now
158-
let otherDuration = otherNow.duration(to: instant)
159-
160-
// Convert to `Swift.Duration`
161-
guard let duration = clock.convert(from: otherDuration) else {
162-
return nil
163-
}
164-
165-
// Convert from `Swift.Duration`
166-
guard let ourDuration = convert(from: duration) else {
167-
return nil
168-
}
169-
170-
return ourNow.advanced(by: ourDuration)
171-
}
172-
}
173-
174-
@available(StdlibDeploymentTarget 6.2, *)
175-
extension Clock where Duration == Swift.Duration {
176-
public func convert(from duration: Duration) -> Duration? {
177-
return duration
178-
}
179-
}
180-
18199
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
182100
@available(StdlibDeploymentTarget 5.7, *)
183101
extension Clock {
@@ -196,44 +114,6 @@ extension Clock {
196114
}
197115
#endif
198116

199-
/// Represents traits of a particular Clock implementation.
200-
///
201-
/// Clocks may be of a number of different varieties; executors will likely
202-
/// have specific clocks that they can use to schedule jobs, and will
203-
/// therefore need to be able to convert timestamps to an appropriate clock
204-
/// when asked to enqueue a job with a delay or deadline.
205-
///
206-
/// Choosing a clock in general requires the ability to tell which of their
207-
/// clocks best matches the clock that the user is trying to specify a
208-
/// time or delay in. Executors are expected to do this on a best effort
209-
/// basis.
210-
@available(StdlibDeploymentTarget 6.2, *)
211-
public struct ClockTraits: OptionSet {
212-
public let rawValue: UInt32
213-
214-
public init(rawValue: UInt32) {
215-
self.rawValue = rawValue
216-
}
217-
218-
/// Clocks with this trait continue running while the machine is asleep.
219-
public static let continuous = ClockTraits(rawValue: 1 << 0)
220-
221-
/// Indicates that a clock's time will only ever increase.
222-
public static let monotonic = ClockTraits(rawValue: 1 << 1)
223-
224-
/// Clocks with this trait are tied to "wall time".
225-
public static let wallTime = ClockTraits(rawValue: 1 << 2)
226-
}
227-
228-
@available(StdlibDeploymentTarget 6.2, *)
229-
extension Clock {
230-
/// The traits associated with this clock instance.
231-
@available(StdlibDeploymentTarget 6.2, *)
232-
public var traits: ClockTraits {
233-
return []
234-
}
235-
}
236-
237117
enum _ClockID: Int32 {
238118
case continuous = 1
239119
case suspending = 2

stdlib/public/Concurrency/ContinuousClock.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,6 @@ extension ContinuousClock: Clock {
100100
)
101101
}
102102

103-
/// The continuous clock is continuous and monotonic
104-
@available(StdlibDeploymentTarget 6.2, *)
105-
public var traits: ClockTraits {
106-
return [.continuous, .monotonic]
107-
}
108-
109103
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
110104
/// Suspend task execution until a given deadline within a tolerance.
111105
/// If no tolerance is specified then the system may adjust the deadline

stdlib/public/Concurrency/CooperativeExecutor.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@ extension CooperativeExecutor: SchedulableExecutor {
193193
after delay: C.Duration,
194194
tolerance: C.Duration? = nil,
195195
clock: C) {
196-
let duration = Duration(from: clock.convert(from: delay)!)
196+
guard let swiftDuration = delay as? Swift.Duration else {
197+
fatalError("Unsupported clock")
198+
}
199+
200+
let duration = Duration(from: swiftDuration)
197201
let deadline = self.currentTime + duration
198202

199203
job.setupCooperativeExecutorTimestamp()

stdlib/public/Concurrency/DispatchExecutor.swift

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import Swift
2424
// .. Main Executor ............................................................
2525

2626
@available(StdlibDeploymentTarget 6.2, *)
27-
public class DispatchMainExecutor: RunLoopExecutor, @unchecked Sendable {
27+
class DispatchMainExecutor: RunLoopExecutor, @unchecked Sendable {
2828
var threaded = false
2929

3030
public init() {}
@@ -91,8 +91,8 @@ extension DispatchMainExecutor: MainExecutor {}
9191
// .. Task Executor ............................................................
9292

9393
@available(StdlibDeploymentTarget 6.2, *)
94-
public class DispatchGlobalTaskExecutor: TaskExecutor, SchedulableExecutor,
95-
@unchecked Sendable {
94+
class DispatchGlobalTaskExecutor: TaskExecutor, SchedulableExecutor,
95+
@unchecked Sendable {
9696
public init() {}
9797

9898
public func enqueue(_ job: consuming ExecutorJob) {
@@ -172,28 +172,30 @@ extension DispatchExecutorProtocol {
172172

173173
func timestamp<C: Clock>(for instant: C.Instant, clock: C)
174174
-> (clockID: DispatchClockID, seconds: Int64, nanoseconds: Int64) {
175-
if clock.traits.contains(.continuous) {
176-
let dispatchClock: ContinuousClock = .continuous
177-
let instant = dispatchClock.convert(instant: instant, from: clock)!
178-
let (seconds, attoseconds) = clamp(instant._value.components)
179-
let nanoseconds = attoseconds / 1_000_000_000
180-
return (clockID: .continuous,
181-
seconds: Int64(seconds),
182-
nanoseconds: Int64(nanoseconds))
175+
if clock is ContinuousClock {
176+
let instant = instant as! ContinuousClock.Instant
177+
let (seconds, attoseconds) = clamp(instant._value.components)
178+
let nanoseconds = attoseconds / 1_000_000_000
179+
return (clockID: .continuous,
180+
seconds: Int64(seconds),
181+
nanoseconds: Int64(nanoseconds))
182+
} else if clock is SuspendingClock {
183+
let instant = instant as! SuspendingClock.Instant
184+
let (seconds, attoseconds) = clamp(instant._value.components)
185+
let nanoseconds = attoseconds / 1_000_000_000
186+
return (clockID: .suspending,
187+
seconds: Int64(seconds),
188+
nanoseconds: Int64(nanoseconds))
183189
} else {
184-
let dispatchClock: SuspendingClock = .suspending
185-
let instant = dispatchClock.convert(instant: instant, from: clock)!
186-
let (seconds, attoseconds) = clamp(instant._value.components)
187-
let nanoseconds = attoseconds / 1_000_000_000
188-
return (clockID: .suspending,
189-
seconds: Int64(seconds),
190-
nanoseconds: Int64(nanoseconds))
190+
fatalError("Unknown clock")
191191
}
192192
}
193193

194194
func delay<C: Clock>(from duration: C.Duration, clock: C)
195195
-> (seconds: Int64, nanoseconds: Int64) {
196-
let swiftDuration = clock.convert(from: duration)!
196+
guard let swiftDuration = duration as? Swift.Duration else {
197+
fatalError("Unsupported clock")
198+
}
197199
let (seconds, attoseconds) = clamp(swiftDuration.components)
198200
let nanoseconds = attoseconds / 1_000_000_000
199201
return (seconds: seconds, nanoseconds: nanoseconds)

0 commit comments

Comments
 (0)