Skip to content
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

Unsafe task-local binding #2222

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

ktoso
Copy link
Member

@ktoso ktoso commented Dec 1, 2023

This provides building blocks necessary to build tracing macros (or similar) which use body "preamble" macros.

Copy link
Contributor

@slashmo slashmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, the naming looks like it's enough of a barrier to keep folks from using it unless absolutely necessary 👍

proposals/NNNN-unsafe-task-locals.md Outdated Show resolved Hide resolved
```swift
func order() async {
$wasabiPreference.unsafePushValue(.with)
defer { TL.$number.unsafePopValue() }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is TL.$number coming from? Shouldn't this be $wasabiPreference.unsafePopValue()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, thanks will fix

@WasabiPreference(.with)
func order() async {
// $wasabiPreference.unsafePushValue(.with)
// defer { TL.$number.unsafePopValue() }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, I'm confused about the TL.$number.

/// - SeeAlso: ``withValue(_:file:line:)``
/// - SeeAlso: ``unsafePushValue(_:file:line:)``
@inlinable
public func unsafePopValue(file: String = #fileID, line: UInt = #line)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you also want to include the body of this method?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, we're not showing implementation details -- it is swift runtime builtins

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Co-authored-by: Moritz Lang <hi@slashmo.codes>

```swift
func order() async {
$wasabiPreference.withValue(.with) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, what is .with here? It is not mentioned anywhere in the text or declared in the examples—is this some existing concurrency API?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the value set for the wasabiPreference task-local within the closure scope. I suppose there are .with and .without, but I think this should be written down as part of the proposal. CC @ktoso

The $taskLocal.withValue API is the existing (safe) API to bind task-local values.

@rjmccall
Copy link
Member

The Language Steering Group is going to sit on this until we figure out in the function-body macros proposal whether this sort of thing really has to be necessary. I think we're hoping that it doesn't.

@ktoso
Copy link
Member Author

ktoso commented Dec 13, 2023

Sounds good, agreed!

I've put it into "draft" to signal that this isn't going to be reviewed for the time being.

@ktoso ktoso marked this pull request as draft December 13, 2023 03:48
@rjmccall rjmccall added the workgroup: blocked This proposal is blocked on some other consideration label Dec 14, 2023
@rjmccall rjmccall added the LSG Contains topics under the domain of the Language Steering Group label Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LSG Contains topics under the domain of the Language Steering Group workgroup: blocked This proposal is blocked on some other consideration
Projects
None yet
4 participants