Skip to content

[6.2][Concurrency] Correct memory effect attributes of task_create #82180

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

Merged
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/Runtime/RuntimeFunctions.def
Original file line number Diff line number Diff line change
Expand Up @@ -2376,7 +2376,7 @@ FUNCTION(TaskCreate,
RefCountedPtrTy),
ATTRS(NoUnwind),
EFFECT(RuntimeEffect::Concurrency),
MEMEFFECTS(ArgMemOnly))
MEMEFFECTS(ReadOnly))

// void swift_task_switch(AsyncContext *resumeContext,
// TaskContinuationFunction *resumeFunction,
Expand Down
2 changes: 0 additions & 2 deletions stdlib/public/Concurrency/Task+immediate.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ extension Task where Failure == ${FAILURE_TYPE} {
public static func immediate(
name: String? = nil,
priority: TaskPriority? = nil,
% # NOTE: This closure cannot be 'sending' because we'll trigger ' pattern that the region based isolation checker does not understand how to check'
% # In this case: `func syncOnMyGlobalActor() { Task.immediate { @MyGlobalActor in } }`
@_implicitSelfCapture @_inheritActorContext(always) operation: sending @isolated(any) @escaping () async throws -> Success
) -> Task<Success, ${FAILURE_TYPE}> {

Expand Down
52 changes: 30 additions & 22 deletions test/Concurrency/Runtime/startImmediately.swift
Original file line number Diff line number Diff line change
Expand Up @@ -392,28 +392,6 @@ print("callActorFromStartSynchronousTask() - actor in custom executor with its o
let actorQueue = DispatchQueue(label: "recipient-actor-queue")
callActorFromStartSynchronousTask(recipient: .recipientOnQueue(RecipientOnQueue(queue: actorQueue)))


// 50: callActorFromStartSynchronousTask()
// 51: before immediate [thread:0x00007000054f5000] @ :366
// 52: inside immediate [thread:0x00007000054f5000] @ :372
// 53: inside immediate, call rec.sync() [thread:0x00007000054f5000] @ :380
// 54: Recipient/sync(syncTaskThreadID:) Current actor thread id = 0x000070000567e000 @ :336
// 55: inside immediate, call rec.sync() done [thread:0x000070000567e000] @ :385
// 56: Inner thread id = 0x00007000054f5000
// 57: Current thread id = 0x000070000567e000
// 60: after immediate [thread:0x00007000054f5000] @ :418
// 61: - async work on queue
// 62: - async work on queue
// 63: - async work on queue
// 64: - async work on queue
// 65: - async work on queue
// 67: - async work on queue
// 68: - async work on queue
// 69: - async work on queue
// 71: Inner thread id = 0x00007000054f5000
// 72: Current thread id = 0x000070000567e000
// 73: inside immediate, done [thread:0x000070000567e000] @ :414

// CHECK-LABEL: callActorFromStartSynchronousTask() - actor in custom executor with its own queue
// No interleaving allowed between "before" and "inside":
// CHECK: before immediate [thread:[[CALLING_THREAD4:.*]]]
Expand Down Expand Up @@ -452,3 +430,33 @@ actor RecipientOnQueue: RecipientProtocol {
try? await Task.sleep(for: .milliseconds(100))
}
}

print("\n\n==== ------------------------------------------------------------------")
print("call_startSynchronously_insideActor()")

actor A {
func f() {
Task.startSynchronously(name: "hello") { print("Task.startSynchronously (\(Task.name!))") }
Task.startSynchronously() { print("Task.startSynchronously") }
}

func f2() {
Task.immediate(name: "hello") { print("Task.immediate (\(Task.name!))") }
Task.immediate() { print("Task.immediate") }

Task.immediate(name: "hello") { @MainActor in print("Task.immediate { @MainActor } (\(Task.name!))") }
Task.immediate() { @MainActor in print("Task.immediate { @MainActor }") }
}
}

func call_startSynchronously_insideActor() async {
await A().f()
await A().f2()
}

await call_startSynchronously_insideActor()

// CHECK-LABEL: call_startSynchronously_insideActor()
// Those two definitely in this order, however the startSynchronously is not determinate
// CHECK: Task.immediate
// CHECK: Task.immediate { @MainActor }