Skip to content

Commit ad33889

Browse files
authored
Merge pull request #35564 from apple/revert-35549-wip-task-canceled-spelling
2 parents 1e039cc + 80ee936 commit ad33889

13 files changed

+48
-48
lines changed

include/swift/ABI/Task.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ static_assert(alignof(Job) == 2 * alignof(void*),
9393
/// The current state of a task's status records.
9494
class ActiveTaskStatus {
9595
enum : uintptr_t {
96-
IsCanceled = 0x1,
96+
IsCancelled = 0x1,
9797
IsLocked = 0x2,
98-
RecordMask = ~uintptr_t(IsCanceled | IsLocked)
98+
RecordMask = ~uintptr_t(IsCancelled | IsLocked)
9999
};
100100

101101
uintptr_t Value;
@@ -106,10 +106,10 @@ class ActiveTaskStatus {
106106
bool cancelled, bool locked)
107107
: Value(reinterpret_cast<uintptr_t>(innermostRecord)
108108
+ (locked ? IsLocked : 0)
109-
+ (cancelled ? IsCanceled : 0)) {}
109+
+ (cancelled ? IsCancelled : 0)) {}
110110

111111
/// Is the task currently cancelled?
112-
bool isCanceled() const { return Value & IsCanceled; }
112+
bool isCancelled() const { return Value & IsCancelled; }
113113

114114
/// Is there an active lock on the cancellation information?
115115
bool isLocked() const { return Value & IsLocked; }
@@ -178,8 +178,8 @@ class AsyncTask : public HeapObject, public Job {
178178

179179
/// Check whether this task has been cancelled.
180180
/// Checking this is, of course, inherently race-prone on its own.
181-
bool isCanceled() const {
182-
return Status.load(std::memory_order_relaxed).isCanceled();
181+
bool isCancelled() const {
182+
return Status.load(std::memory_order_relaxed).isCancelled();
183183
}
184184

185185
/// A fragment of an async task structure that happens to be a child task.

include/swift/Runtime/Concurrency.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
223223
size_t swift_task_getJobFlags(AsyncTask* task);
224224

225225
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
226-
bool swift_task_isCanceled(AsyncTask* task);
226+
bool swift_task_isCancelled(AsyncTask* task);
227227

228228
/// This should have the same representation as an enum like this:
229229
/// enum NearestTaskDeadline {

stdlib/public/Concurrency/Task.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,8 @@ void swift::swift_continuation_throwingResumeWithError(/* +1 */ SwiftError *erro
526526
resumeTaskAfterContinuation(task, context);
527527
}
528528

529-
bool swift::swift_task_isCanceled(AsyncTask *task) {
530-
return task->isCanceled();
529+
bool swift::swift_task_isCancelled(AsyncTask *task) {
530+
return task->isCancelled();
531531
}
532532

533533
SWIFT_CC(swift)

stdlib/public/Concurrency/Task.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func getJobFlags(_ task: Builtin.NativeObject) -> Task.JobFlags
317317
@usableFromInline
318318
func _enqueueJobGlobal(_ task: Builtin.Job)
319319

320-
@_silgen_name("swift_task_isCanceled")
320+
@_silgen_name("swift_task_isCancelled")
321321
func isTaskCancelled(_ task: Builtin.NativeObject) -> Bool
322322

323323
@_silgen_name("swift_task_runAndBlockThread")
@@ -415,8 +415,8 @@ public func _runGroupChildTask<T>(
415415
@_silgen_name("swift_task_cancel")
416416
func _taskCancel(_ task: Builtin.NativeObject)
417417

418-
@_silgen_name("swift_task_isCanceled")
419-
func _taskIsCanceled(_ task: Builtin.NativeObject) -> Bool
418+
@_silgen_name("swift_task_isCancelled")
419+
func _taskIsCancelled(_ task: Builtin.NativeObject) -> Bool
420420

421421
#if _runtime(_ObjC)
422422

stdlib/public/Concurrency/TaskCancellation.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ extension Task {
2424
///
2525
/// - SeeAlso: `checkCancellation()`
2626
/* @instantaneous */
27-
public static func isCanceled() async -> Bool {
28-
_taskIsCanceled(Builtin.getCurrentAsyncTask())
27+
public static func isCancelled() async -> Bool {
28+
_taskIsCancelled(Builtin.getCurrentAsyncTask())
2929
}
3030

3131
/// Check if the task is cancelled and throw an `CancellationError` if it was.
@@ -41,10 +41,10 @@ extension Task {
4141
/// ### Suspension
4242
/// This function returns instantly and will never suspend.
4343
///
44-
/// - SeeAlso: `isCanceled()`
44+
/// - SeeAlso: `isCancelled()`
4545
/* @instantaneous */
4646
public static func checkCancellation() async throws {
47-
if await Task.isCanceled() {
47+
if await Task.isCancelled() {
4848
throw CancellationError()
4949
}
5050
}
@@ -108,7 +108,7 @@ extension Task {
108108
/// regardless of the inner deadlines of the specific child tasks.
109109
///
110110
/// Cancellation is co-operative and must be checked for by the operation, e.g.
111-
/// by invoking `Task.checkCancellation`, or `Task.isCanceled`.
111+
/// by invoking `Task.checkCancellation`, or `Task.isCancelled`.
112112
///
113113
/// ### Suspension
114114
/// This function returns instantly and will never suspend.
@@ -135,7 +135,7 @@ extension Task {
135135
/// regardless of the inner deadlines of the specific child tasks.
136136
///
137137
/// Cancellation is co-operative and must be checked for by the operation, e.g.
138-
/// by invoking `Task.checkCancellation` or `Task.isCanceled`.
138+
/// by invoking `Task.checkCancellation` or `Task.isCancelled`.
139139
///
140140
/// ### Suspension
141141
/// This function returns instantly and will never suspend.

stdlib/public/Concurrency/TaskGroup.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ extension Task {
226226
///
227227
/// - SeeAlso: `Task.addCancellationHandler`
228228
/// - SeeAlso: `Task.checkCancelled`
229-
/// - SeeAlso: `Task.isCanceled`
229+
/// - SeeAlso: `Task.isCancelled`
230230
public mutating func cancelAll() {
231231
_taskCancel(self.task) // TODO: do we also have to go over all child tasks and cancel there?
232232
}

stdlib/public/Concurrency/TaskStatus.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ static void waitForStatusRecordUnlock(AsyncTask *task,
184184
/// If `forCancellation` is true, the cancelled bit will be set in the
185185
/// state, and the lock will not be acquired if the task is already
186186
/// cancelled or can be cancelled without the lock. If this occurs,
187-
/// `isCanceled()` will be true for the return value.
187+
/// `isCancelled()` will be true for the return value.
188188
static ActiveTaskStatus
189189
acquireStatusRecordLock(AsyncTask *task,
190190
Optional<StatusRecordLockRecord> &recordLockRecord,
@@ -204,7 +204,7 @@ acquireStatusRecordLock(AsyncTask *task,
204204
// Cancellation should be idempotent: if the task has already
205205
// been cancelled (or is being cancelled concurrently), there
206206
// shouldn't be any need to do this work again.
207-
if (oldStatus.isCanceled() && forCancellation)
207+
if (oldStatus.isCancelled() && forCancellation)
208208
return oldStatus;
209209

210210
// If the old info says we're locked, wait for the lock to clear.
@@ -238,9 +238,9 @@ acquireStatusRecordLock(AsyncTask *task,
238238

239239
// Install the lock record as the active cancellation info, or
240240
// restart if that fails.
241-
bool newIsCanceled = forCancellation || oldStatus.isCanceled();
241+
bool newIsCancelled = forCancellation || oldStatus.isCancelled();
242242
ActiveTaskStatus newStatus(&*recordLockRecord,
243-
/*cancelled*/ newIsCanceled,
243+
/*cancelled*/ newIsCancelled,
244244
/*locked*/ true);
245245
if (task->Status.compare_exchange_weak(oldStatus, newStatus,
246246
/*success*/ std::memory_order_release,
@@ -288,12 +288,12 @@ bool swift::swift_task_addStatusRecord(AsyncTask *task,
288288
// We have to use a release on success to make the initialization of
289289
// the new record visible to the cancelling thread.
290290
ActiveTaskStatus newStatus(newRecord,
291-
oldStatus.isCanceled(),
291+
oldStatus.isCancelled(),
292292
/*locked*/ false);
293293
if (task->Status.compare_exchange_weak(oldStatus, newStatus,
294294
/*success*/ std::memory_order_release,
295295
/*failure*/ std::memory_order_relaxed))
296-
return !oldStatus.isCanceled();
296+
return !oldStatus.isCancelled();
297297
}
298298
}
299299

@@ -305,14 +305,14 @@ bool swift::swift_task_tryAddStatusRecord(AsyncTask *task,
305305

306306
while (true) {
307307
// If the old info is already cancelled, do nothing.
308-
if (oldStatus.isCanceled())
308+
if (oldStatus.isCancelled())
309309
return false;
310310

311311
// Wait for any active lock to be released.
312312
if (oldStatus.isLocked()) {
313313
waitForStatusRecordUnlock(task, oldStatus);
314314

315-
if (oldStatus.isCanceled())
315+
if (oldStatus.isCancelled())
316316
return false;
317317
}
318318

@@ -345,12 +345,12 @@ bool swift::swift_task_removeStatusRecord(AsyncTask *task,
345345
// If the record is the innermost record, try to just pop it off.
346346
if (oldStatus.getInnermostRecord() == record) {
347347
ActiveTaskStatus newStatus(record->getParent(),
348-
oldStatus.isCanceled(),
348+
oldStatus.isCancelled(),
349349
/*locked*/ false);
350350
if (task->Status.compare_exchange_weak(oldStatus, newStatus,
351351
/*success*/ std::memory_order_release,
352352
/*failure*/ std::memory_order_relaxed))
353-
return !oldStatus.isCanceled();
353+
return !oldStatus.isCancelled();
354354

355355
// Otherwise, restart.
356356
continue;
@@ -389,7 +389,7 @@ bool swift::swift_task_removeStatusRecord(AsyncTask *task,
389389
// exactly what we want to restore.
390390
releaseStatusRecordLock(task, oldStatus, recordLockRecord);
391391

392-
return !oldStatus.isCanceled();
392+
return !oldStatus.isCancelled();
393393
}
394394

395395
/**************************************************************************/
@@ -443,7 +443,7 @@ void swift::swift_task_cancel(AsyncTask *task) {
443443

444444
// If we were already cancelled or were able to cancel without acquiring
445445
// the lock, there's nothing else to do.
446-
if (oldStatus.isCanceled())
446+
if (oldStatus.isCancelled())
447447
return;
448448

449449
// Otherwise, we've installed the lock record and are now the
@@ -561,7 +561,7 @@ NearestTaskDeadline swift::swift_task_getNearestDeadline(AsyncTask *task) {
561561
NearestTaskDeadline result;
562562

563563
// If it's already cancelled, we're done.
564-
if (oldStatus.isCanceled()) {
564+
if (oldStatus.isCancelled()) {
565565
result.ValueKind = NearestTaskDeadline::AlreadyCancelled;
566566
return result;
567567
}

test/Concurrency/Runtime/async_taskgroup_next_not_invoked_cancelAll.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func test_skipCallingNext_butInvokeCancelAll() async {
1515
await group.add { () async -> Int in
1616
sleep(1)
1717
print(" inside group.add { \(n) }")
18-
let cancelled = await Task.isCanceled()
18+
let cancelled = await Task.isCancelled()
1919
print(" inside group.add { \(n) } (canceled: \(cancelled))")
2020
return n
2121
}
@@ -24,7 +24,7 @@ func test_skipCallingNext_butInvokeCancelAll() async {
2424
group.cancelAll()
2525

2626
// return immediately; the group should wait on the tasks anyway
27-
print("return immediately 0 (canceled: \(await Task.isCanceled()))")
27+
print("return immediately 0 (canceled: \(await Task.isCancelled()))")
2828
return 0
2929
}
3030

test/Concurrency/Runtime/async_taskgroup_next_not_invoked_without_cancelAll.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ func test_skipCallingNext() async {
1414
print("group.add { \(n) }")
1515
await group.add { () async -> Int in
1616
sleep(1)
17-
print(" inside group.add { \(n) } (canceled: \(await Task.isCanceled()))")
17+
print(" inside group.add { \(n) } (canceled: \(await Task.isCancelled()))")
1818
return n
1919
}
2020
}
2121

2222
// return immediately; the group should wait on the tasks anyway
23-
print("return immediately 0 (canceled: \(await Task.isCanceled()))")
23+
print("return immediately 0 (canceled: \(await Task.isCancelled()))")
2424
return 0
2525
}
2626

test/Concurrency/Runtime/async_taskgroup_throw_recover.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func test_taskGroup_throws() async {
3939
print("error caught in group: \(error)")
4040

4141
await group.add { () async -> Int in
42-
print("task 3 (cancelled: \(await Task.isCanceled()))")
42+
print("task 3 (cancelled: \(await Task.isCancelled()))")
4343
return 3
4444
}
4545

test/Concurrency/async_cancellation.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ func test_cancellation_checkCancellation() async throws {
1010
try await Task.checkCancellation()
1111
}
1212

13-
func test_cancellation_guard_isCanceled(_ any: Any) async -> PictureData {
14-
guard await !Task.isCanceled() else {
13+
func test_cancellation_guard_isCancelled(_ any: Any) async -> PictureData {
14+
guard await !Task.isCancelled() else {
1515
return PictureData.failedToLoadImagePlaceholder
1616
}
1717

@@ -29,7 +29,7 @@ func test_cancellation_withCancellationHandler(_ anything: Any) async -> Picture
2929
return try await Task.withCancellationHandler(
3030
handler: { file.close() },
3131
operation: {
32-
await test_cancellation_guard_isCanceled(file)
32+
await test_cancellation_guard_isCancelled(file)
3333
})
3434
}
3535

@@ -41,7 +41,7 @@ func test_cancellation_loop() async -> Int {
4141

4242
let tasks = [SampleTask(), SampleTask()]
4343
var processed = 0
44-
for t in tasks where await !Task.isCanceled() {
44+
for t in tasks where await !Task.isCancelled() {
4545
await t.process()
4646
processed += 1
4747
}

test/Concurrency/async_task_groups.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ func asyncThrowsFunc() async throws -> Int { 42 }
66
func asyncThrowsOnCancel() async throws -> Int {
77
// terrible suspend-spin-loop -- do not do this
88
// only for purposes of demonstration
9-
while await !Task.isCanceled() {
9+
while await !Task.isCancelled() {
1010
await Task.sleep(until: Task.Deadline.in(.seconds(1)))
1111
}
1212

unittests/runtime/TaskStatus.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ TEST(TaskStatusTest, cancellation_simple) {
127127
withSimpleTask(Storage{47},
128128
[&](AsyncTask *task, ExecutorRef executor,
129129
ValueContext<Storage> *context) {
130-
EXPECT_FALSE(task->isCanceled());
130+
EXPECT_FALSE(task->isCancelled());
131131
swift_task_cancel(task);
132-
EXPECT_TRUE(task->isCanceled());
132+
EXPECT_TRUE(task->isCancelled());
133133
swift_task_cancel(task);
134-
EXPECT_TRUE(task->isCanceled());
134+
EXPECT_TRUE(task->isCancelled());
135135
}, [&](AsyncTask *task) {
136136
task->run(createFakeExecutor(1234));
137137
});
@@ -145,7 +145,7 @@ TEST(TaskStatusTest, deadline) {
145145
withSimpleTask(Storage{47},
146146
[&](AsyncTask *task, ExecutorRef executor,
147147
ValueContext<Storage> *context) {
148-
EXPECT_FALSE(task->isCanceled());
148+
EXPECT_FALSE(task->isCancelled());
149149

150150
TaskDeadline deadlineOne = { 1234 };
151151
TaskDeadline deadlineTwo = { 2345 };
@@ -252,7 +252,7 @@ TEST(TaskStatusTest, deadline) {
252252

253253
// Cancel.
254254
swift_task_cancel(task);
255-
EXPECT_TRUE(task->isCanceled());
255+
EXPECT_TRUE(task->isCancelled());
256256

257257
// We should report already cancelled now.
258258
nearest = swift_task_getNearestDeadline(task);
@@ -277,7 +277,7 @@ TEST(TaskStatusTest, deadline) {
277277
nearest = swift_task_getNearestDeadline(task);
278278
EXPECT_EQ(NearestTaskDeadline::AlreadyCancelled, nearest.ValueKind);
279279

280-
EXPECT_TRUE(task->isCanceled());
280+
EXPECT_TRUE(task->isCancelled());
281281
}, [&](AsyncTask *task) {
282282
task->run(createFakeExecutor(1234));
283283
});

0 commit comments

Comments
 (0)