-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Concurrency] TaskLocal.withValue closure should produce no warnings inside Actor #62239
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
Conversation
resolves rdar://102638772 |
@swift-ci please smoke test |
@swift-ci please smoke test |
@swift-ci please smoke test |
I think the right fix here is that this ought to inherit the caller's executor. |
Seems it is not ABI compatible to add
|
07709fd
to
a64598a
Compare
@swift-ci please smoke test |
336f364
to
9b82170
Compare
@swift-ci please smoke test |
I think it's correct in the abstract to make this inherit the executor. However, marking the function as inheriting the executor makes a semantic guarantee that the function won't switch, and unfortunately the existing implementations of this function (ever since 5.6 / SE-0338) do switch (to the generic executor) (unless that switch has been optimized out in the release builds). I think it's okay for existing compilations to call a function that doesn't switch (the function doesn't rely on being on the generic executor, and you can think of turning off the switches as manually optimizing them away, which is permitted). However, it's not okay for new compilations that will rely on the absence of switching to potentially call a function that does switch. So we need to have a way to back-deploy this fix for it to be correct. It looks like everything these functions call is back-deployable — they're either already You may have to wait until |
Thank you for the analysis and guidance, John! We'll need to wait for |
Depends on #62309 |
Hmmm, tried to make use of backDeploy bot getting into all kinds of crashes, I'll ask @tshortli for some assistance. Doing
we get:
and removing the defer we get another crash:
so, not quite sure what to do here; If I'm holding it wrong or we're still missing edge-cases etc. |
Great, thank you! |
Ok those got merged, so I'll try to revive this 👍 |
9b82170
to
d122fd6
Compare
@swift-ci please smoke test |
@@ -102,6 +102,7 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible | |||
self.defaultValue = defaultValue | |||
} | |||
|
|||
@usableFromInline |
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.
@usableFromInline
adds a public symbol that won't be available on older platforms. Can you make this @alwaysEmitIntoClient
?
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.
Ok will do, I hope backdeploy will understand that hmm.
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.
Okey cool it does :)
@@ -135,6 +136,9 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible | |||
/// If the value is a reference type, it will be retained for the duration of | |||
/// the operation closure. | |||
@discardableResult | |||
@_unsafeInheritExecutor | |||
@available(SwiftStdlib 5.1, *) // back deploy requires we declare the availability explicitly on this method | |||
@_backDeploy(before: macOS 9999, iOS 9999, watchOS 9999, tvOS 9999) // SwiftStdlib 5.8 but it doesn't work with _backDeploy |
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.
How sad. @tshortli can @backDeploy
support SwiftStdlib 5.8
here?
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.
@_backDeploy
supports availability macros in general (they're heavily used in some of the tests). If there's an edge case exposed here, though, let me know @ktoso
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.
Yeah it didn’t work with the SwiftStdlib and I tried looking into it but didn’t quite see how those get applied. Help very welcome on this @tshortli !
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.
Okey, I was too tired last evening and did a dumb "before: 5.8", confirmed that before: SwiftStdlib 5.8
works fine, thanks @tshortli
3ce1ec3
to
224a400
Compare
@swift-ci please smoke test |
224a400
to
342ce7e
Compare
@swift-ci please smoke test |
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.
Looks great now!
Co-authored-by: Doug Gregor <[email protected]>
@swift-ci please smoke test and merge |
Thank you, Doug! I'll fix a few similar issues while at it 👍 |
Without the @sendable, using a task-local's
withValue
results with unexpected warnings which scared developers into thinking they might be misusing the API.This PR adds the missing annotation; I believe this is ABI compatible, but would like to make sure.
Resolves #62220
rdar://102638772