-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[6.0][Concurrency] TaskExecutors may be non-swift objects; dont swift_rele… #75060
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
ktoso
merged 2 commits into
swiftlang:release/6.0
from
ktoso:pick-wip-avoid-wrong-release-on-non-swift-objects
Jul 9, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
test/Concurrency/Runtime/async_task_executor_nsobject.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking %import-libdispatch -parse-as-library ) | ||
|
|
||
| // REQUIRES: executable_test | ||
| // REQUIRES: concurrency | ||
| // REQUIRES: libdispatch | ||
|
|
||
| // REQUIRES: OS=macosx | ||
| // REQUIRES: objc_interop | ||
|
|
||
| // REQUIRES: concurrency_runtime | ||
| // UNSUPPORTED: back_deployment_runtime | ||
|
|
||
| import Dispatch | ||
| import StdlibUnittest | ||
| import _Concurrency | ||
|
|
||
| import Foundation | ||
| import Darwin | ||
|
|
||
| // Sneaky trick to make this type objc reference counted. | ||
| // | ||
| // This test specifically checks that our reference counting accounts for existence of | ||
| // objective-c types as TaskExecutors -- which was a bug where we'd swift_release | ||
| // obj-c excecutors by accident (rdar://131151645). | ||
| final class NSQueueTaskExecutor: NSData, TaskExecutor, @unchecked Sendable { | ||
| public func enqueue(_ _job: consuming ExecutorJob) { | ||
| let job = UnownedJob(_job) | ||
| DispatchQueue.main.async { | ||
| job.runSynchronously(on: self.asUnownedTaskExecutor()) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @main struct Main { | ||
| static func main() async { | ||
| var taskExecutor: (any TaskExecutor)? = NSQueueTaskExecutor() | ||
|
|
||
| let task = Task(executorPreference: taskExecutor) { | ||
| dispatchPrecondition(condition: .onQueue(DispatchQueue.main)) | ||
| try? await Task.sleep(for: .seconds(2)) | ||
| return 12 | ||
| } | ||
|
|
||
| taskExecutor = nil | ||
|
|
||
| let num = await task.value | ||
| assert(num == 12) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Swift refcounting on this class will end up working on the field after the end of the instance, since instances of this object will just contain a single pointer. Presumably this does fail in practice, but it might be good to make it more certain by adding a field with a value that will provoke a crash.
var dummy = 0orvar dummy = -1ought to do it.