Skip to content

Commit ed06965

Browse files
committed
rebase and cleanup
1 parent 670c4c1 commit ed06965

15 files changed

+544
-398
lines changed

lib/AST/Decl.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5261,15 +5261,12 @@ NominalTypeDecl::getExecutorOwnedEnqueueFunction() const {
52615261
if (!isa<ProtocolDecl>(candidate->getDeclContext()))
52625262
continue;
52635263

5264-
fprintf(stderr, "[%s:%d](%s) candidate\n", __FILE_NAME__, __LINE__, __FUNCTION__);
5265-
candidate->dump();
5266-
52675264
if (auto *funcDecl = dyn_cast<AbstractFunctionDecl>(candidate)) {
52685265
if (funcDecl->getParameters()->size() != 1)
52695266
continue;
52705267

52715268
auto params = funcDecl->getParameters();
5272-
if (params->get(0)->getSpecifier() == ParamSpecifier::Owned) {
5269+
if (params->get(0)->getSpecifier() == ParamSpecifier::LegacyOwned) { // TODO: make this Consuming
52735270
return funcDecl;
52745271
}
52755272
}

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1810,7 +1810,7 @@ function(add_swift_target_library name)
18101810
if (SWIFTLIB_IS_STDLIB)
18111811
list(APPEND SWIFTLIB_SWIFT_COMPILE_FLAGS "-warn-implicit-overrides")
18121812
list(APPEND SWIFTLIB_SWIFT_COMPILE_FLAGS "-Xfrontend;-enable-ossa-modules")
1813-
list(APPEND SWIFTLIB_SWIFT_COMPILE_FLAGS "-Xfrontend;-enable-lexical-lifetimes=true") # FIXME: undo this
1813+
list(APPEND SWIFTLIB_SWIFT_COMPILE_FLAGS "-Xfrontend;-enable-lexical-lifetimes=false")
18141814
endif()
18151815

18161816
if(NOT SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER AND NOT BUILD_STANDALONE AND

stdlib/public/BackDeployConcurrency/Actor.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,9 @@ JobPriority swift::swift_task_getCurrentThreadPriority() {
285285
SWIFT_CC(swift)
286286
static bool swift_task_isCurrentExecutorImpl(ExecutorRef executor) {
287287
if (auto currentTracking = ExecutorTrackingInfo::current()) {
288-
fprintf(stderr, "[%s:%d](%s) current executor = %p, main:%s, default:%s\n", __FILE_NAME__, __LINE__, __FUNCTION__,
289-
currentTracking->getActiveExecutor().getIdentity(),
290-
currentTracking->getActiveExecutor().isMainExecutor() ? "y" : "n",
291-
currentTracking->getActiveExecutor().isDefaultActor() ? "y" : "n");
292288
return currentTracking->getActiveExecutor() == executor;
293289
}
294290

295-
fprintf(stderr, "[%s:%d](%s) no executor found in tracking\n", __FILE_NAME__, __LINE__, __FUNCTION__);
296291
return executor.isMainExecutor() && isExecutingOnMainThread();
297292
}
298293

stdlib/public/BackDeployConcurrency/Executor.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public struct UnownedSerialExecutor: Sendable {
7474
@_silgen_name("_swift_task_enqueueOnExecutor")
7575
internal func _enqueueOnExecutor<E>(job: UnownedJob, executor: E)
7676
where E: SerialExecutor {
77-
// TODO: something to do here?
7877
executor.enqueue(job)
7978
}
8079

stdlib/public/Concurrency/Actor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ static bool swift_task_isCurrentExecutorImpl(ExecutorRef executor) {
301301
return currentTracking->getActiveExecutor() == executor;
302302
}
303303

304+
// TODO(ktoso): checking the "is main thread" is not correct, main executor can be not main thread, relates to rdar://106188692
304305
return executor.isMainExecutor() && isExecutingOnMainThread();
305306
}
306307

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
104104
AsyncThrowingFlatMapSequence.swift
105105
AsyncThrowingMapSequence.swift
106106
AsyncThrowingPrefixWhileSequence.swift
107+
UncheckedContinuation.swift
107108
GlobalActor.swift
108109
MainActor.swift
109110
PartialAsyncTask.swift
@@ -149,7 +150,6 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
149150
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
150151
-parse-stdlib
151152
-Xfrontend -enable-experimental-concurrency
152-
-Xfrontend -enable-experimental-move-only # FIXME: REMOVE THIS
153153
-diagnostic-style swift
154154
${SWIFT_RUNTIME_CONCURRENCY_SWIFT_FLAGS}
155155
${swift_concurrency_options}

stdlib/public/Concurrency/Executor.swift

Lines changed: 123 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import Swift
1515
/// A service that can execute jobs.
1616
@available(SwiftStdlib 5.1, *)
1717
public protocol Executor: AnyObject, Sendable {
18+
1819
@available(*, deprecated, message: "Implement 'enqueue(_: __owned Job)' instead")
20+
@available(SwiftStdlib 5.1, *)
1921
func enqueue(_ job: UnownedJob)
2022

2123
@available(SwiftStdlib 5.9, *)
@@ -43,13 +45,14 @@ public protocol SerialExecutor: Executor {
4345

4446
/// Convert this executor value to the optimized form of borrowed
4547
/// executor references.
48+
@available(SwiftStdlib 5.9, *)
4649
func asUnownedSerialExecutor() -> UnownedSerialExecutor
4750
}
4851

4952
@available(SwiftStdlib 5.9, *)
5053
extension Executor {
5154
public func enqueue(_ job: UnownedJob) {
52-
fatalError("Please implement \(Self.self).enqueueJob(_:)")
55+
self.enqueue(Job(job))
5356
}
5457

5558
public func enqueue(_ job: __owned Job) {
@@ -59,6 +62,7 @@ extension Executor {
5962

6063
@available(SwiftStdlib 5.9, *)
6164
extension SerialExecutor {
65+
@available(SwiftStdlib 5.9, *)
6266
public func asUnownedSerialExecutor() -> UnownedSerialExecutor {
6367
UnownedSerialExecutor(ordinary: self)
6468
}
@@ -107,18 +111,6 @@ public struct UnownedSerialExecutor: Sendable {
107111

108112
}
109113

110-
/// Checks if the current task is running on the expected executor.
111-
///
112-
/// Generally, Swift programs should be constructed such that it is statically
113-
/// known that a specific executor is used, for example by using global actors or
114-
/// custom executors. However, in some APIs it may be useful to provide an
115-
/// additional runtime check for this, especially when moving towards Swift
116-
/// concurrency from other runtimes which frequently use such assertions.
117-
/// - Parameter executor: The expected executor.
118-
@available(SwiftStdlib 5.9, *)
119-
@_silgen_name("swift_task_isOnExecutor")
120-
public func _taskIsOnExecutor<Executor: SerialExecutor>(_ executor: Executor) -> Bool
121-
122114
/// Primarily a debug utility.
123115
///
124116
/// If the passed in Job is a Task, returns the complete 64bit TaskId,
@@ -135,28 +127,12 @@ internal func _getJobTaskId(_ job: UnownedJob) -> UInt64
135127
internal func _enqueueOnExecutor<E>(job unownedJob: UnownedJob, executor: E)
136128
where E: SerialExecutor {
137129
if #available(SwiftStdlib 5.9, *) {
138-
executor.enqueue(Job(context: unownedJob.context))
130+
executor.enqueue(Job(context: unownedJob._context))
139131
} else {
140132
executor.enqueue(unownedJob)
141133
}
142134
}
143135

144-
@available(SwiftStdlib 5.1, *)
145-
@_transparent
146-
public // COMPILER_INTRINSIC
147-
func _checkExpectedExecutor(_filenameStart: Builtin.RawPointer,
148-
_filenameLength: Builtin.Word,
149-
_filenameIsASCII: Builtin.Int1,
150-
_line: Builtin.Word,
151-
_executor: Builtin.Executor) {
152-
if _taskIsCurrentExecutor(_executor) {
153-
return
154-
}
155-
156-
_reportUnexpectedExecutor(
157-
_filenameStart, _filenameLength, _filenameIsASCII, _line, _executor)
158-
}
159-
160136
#if !SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
161137
// This must take a DispatchQueueShim, not something like AnyObject,
162138
// or else SILGen will emit a retain/release in unoptimized builds,
@@ -185,3 +161,120 @@ internal final class DispatchQueueShim: @unchecked Sendable, SerialExecutor {
185161
}
186162
}
187163
#endif
164+
165+
// ==== -----------------------------------------------------------------------
166+
// - MARK: Executor assertions
167+
168+
/// Checks if the current task is running on the expected executor.
169+
///
170+
/// Do note that if multiple actors share the same serial executor,
171+
/// this assertion checks for the executor, not specific actor instance.
172+
///
173+
/// Generally, Swift programs should be constructed such that it is statically
174+
/// known that a specific executor is used, for example by using global actors or
175+
/// custom executors. However, in some APIs it may be useful to provide an
176+
/// additional runtime check for this, especially when moving towards Swift
177+
/// concurrency from other runtimes which frequently use such assertions.
178+
@available(SwiftStdlib 5.9, *)
179+
public func preconditionOnSerialExecutor(
180+
_ executor: some SerialExecutor,
181+
_ message: @autoclosure () -> String = "",
182+
file: StaticString = #fileID, line: UInt = #line) {
183+
preconditionOnSerialExecutor(executor.asUnownedSerialExecutor(), file: file, line: line)
184+
}
185+
186+
@available(SwiftStdlib 5.9, *)
187+
public func preconditionOnSerialExecutor(
188+
_ unowned: UnownedSerialExecutor,
189+
_ message: @autoclosure () -> String = "",
190+
file: StaticString = #fileID, line: UInt = #line) {
191+
if _taskIsCurrentExecutor(unowned.executor) {
192+
return
193+
}
194+
195+
// TODO: log on what executor it was instead of the expected one
196+
let message = "Expected executor \(unowned); \(message())"
197+
preconditionFailure(
198+
message,
199+
file: file, line: line)
200+
}
201+
202+
/// Same as ``preconditionOnSerialExecutor(_:_:file:line)`` however only in DEBUG mode.
203+
@available(SwiftStdlib 5.9, *)
204+
public func assertOnSerialExecutor(
205+
_ executor: some SerialExecutor,
206+
_ message: @autoclosure () -> String = "",
207+
file: StaticString = #fileID, line: UInt = #line) {
208+
assertOnSerialExecutor(executor.asUnownedSerialExecutor(), file: file, line: line)
209+
}
210+
211+
@available(SwiftStdlib 5.9, *)
212+
public func assertOnSerialExecutor(
213+
_ unowned: UnownedSerialExecutor,
214+
_ message: @autoclosure () -> String = "",
215+
file: StaticString = #fileID, line: UInt = #line) {
216+
if _isDebugAssertConfiguration() {
217+
if _taskIsCurrentExecutor(unowned.executor) {
218+
return
219+
}
220+
221+
// TODO: log on what executor it was instead of the expected one
222+
// TODO: fixme use assertion here?
223+
fatalError("Expected executor \(unowned); \(message())", file: file, line: line)
224+
}
225+
}
226+
227+
/// Checks if the current task is running on the expected executor.
228+
///
229+
/// Generally, Swift programs should be constructed such that it is statically
230+
/// known that a specific executor is used, for example by using global actors or
231+
/// custom executors. However, in some APIs it may be useful to provide an
232+
/// additional runtime check for this, especially when moving towards Swift
233+
/// concurrency from other runtimes which frequently use such assertions.
234+
/// - Parameter executor: The expected executor.
235+
@available(SwiftStdlib 5.9, *)
236+
@_silgen_name("swift_task_isOnExecutor")
237+
func _taskIsOnExecutor(_ executor: some SerialExecutor) -> Bool
238+
239+
@available(SwiftStdlib 5.1, *)
240+
@_transparent
241+
public // COMPILER_INTRINSIC
242+
func _checkExpectedExecutor(_filenameStart: Builtin.RawPointer,
243+
_filenameLength: Builtin.Word,
244+
_filenameIsASCII: Builtin.Int1,
245+
_line: Builtin.Word,
246+
_executor: Builtin.Executor) {
247+
if _taskIsCurrentExecutor(_executor) {
248+
return
249+
}
250+
251+
_reportUnexpectedExecutor(
252+
_filenameStart, _filenameLength, _filenameIsASCII, _line, _executor)
253+
}
254+
255+
@available(SwiftStdlib 5.9, *)
256+
@_alwaysEmitIntoClient // FIXME: use @backDeploy(before: SwiftStdlib 5.9)
257+
func _checkExpectedExecutor(
258+
_ _executor: Builtin.Executor,
259+
file: String,
260+
line: Int) {
261+
if _taskIsCurrentExecutor(_executor) {
262+
return
263+
}
264+
265+
file.utf8CString.withUnsafeBufferPointer { (_ bufPtr: UnsafeBufferPointer<CChar>) in
266+
let fileBasePtr: Builtin.RawPointer = bufPtr.baseAddress!._rawValue
267+
268+
// string lengths exclude trailing \0 byte, which should be there!
269+
let fileLength: Builtin.Word = (bufPtr.count - 1)._builtinWordValue
270+
271+
// we're handing it UTF-8
272+
let falseByte: Int8 = 0
273+
let fileIsASCII: Builtin.Int1 = Builtin.trunc_Int8_Int1(falseByte._value)
274+
275+
_reportUnexpectedExecutor(
276+
fileBasePtr, fileLength, fileIsASCII,
277+
line._builtinWordValue,
278+
_executor)
279+
}
280+
}

stdlib/public/Concurrency/ExecutorAssertions.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import SwiftShims
3434
/// programming error.
3535
///
3636
/// - Parameter executor: the expected current executor
37-
@available(SwiftStdlib 5.9, *) // FIXME: use @backDeploy(before: SwiftStdlib 5.9)
37+
@available(SwiftStdlib 5.9, *)
3838
public
3939
func preconditionTaskOnExecutor(
4040
_ executor: some SerialExecutor,
@@ -71,7 +71,7 @@ func preconditionTaskOnExecutor(
7171
/// programming error.
7272
///
7373
/// - Parameter actor: the actor whose serial executor we expect to be the current executor
74-
@available(SwiftStdlib 5.9, *) // FIXME: use @backDeploy(before: SwiftStdlib 5.9)
74+
@available(SwiftStdlib 5.9, *)
7575
public
7676
func preconditionTaskOnActorExecutor(
7777
_ actor: some Actor,
@@ -108,7 +108,7 @@ func preconditionTaskOnActorExecutor(
108108
/// assumption is a serious programming error.
109109
///
110110
/// - Parameter executor: the expected current executor
111-
@available(SwiftStdlib 5.9, *) // FIXME: use @backDeploy(before: SwiftStdlib 5.9)
111+
@available(SwiftStdlib 5.9, *)
112112
public
113113
func assertTaskOnExecutor(
114114
_ executor: some SerialExecutor,
@@ -143,7 +143,7 @@ func assertTaskOnExecutor(
143143
///
144144
///
145145
/// - Parameter actor: the actor whose serial executor we expect to be the current executor
146-
@available(SwiftStdlib 5.9, *) // FIXME: use @backDeploy(before: SwiftStdlib 5.9)
146+
@available(SwiftStdlib 5.9, *)
147147
public
148148
func assertTaskOnActorExecutor(
149149
_ actor: some Actor,
@@ -180,7 +180,7 @@ func assertTaskOnActorExecutor(
180180
/// if another actor uses the same serial executor--by using ``MainActor/sharedUnownedExecutor``
181181
/// as its own ``Actor/unownedExecutor``--this check will succeed, as from a concurrency safety
182182
/// perspective, the serial executor guarantees mutual exclusion of those two actors.
183-
@available(SwiftStdlib 5.9, *) // FIXME: use @backDeploy(before: SwiftStdlib 5.9)
183+
@available(SwiftStdlib 5.9, *)
184184
@_unavailableFromAsync(message: "await the call to the @MainActor closure directly")
185185
public
186186
func assumeOnMainActorExecutor<T>(

0 commit comments

Comments
 (0)