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

adopt sendable #218

Merged
merged 4 commits into from
Jul 1, 2022
Merged

adopt sendable #218

merged 4 commits into from
Jul 1, 2022

Conversation

tomerd
Copy link
Member

@tomerd tomerd commented Mar 15, 2022

motivation: adjust to swift 5.6

changes:

  • define sendable shims for protocols and structs that may be used in async context
  • adjust tests
  • add a test to make sure no warning are emittted

@tomerd tomerd requested a review from ktoso March 15, 2022 02:11
@tomerd tomerd force-pushed the sendable branch 3 times, most recently from 4c4ffa5 to c889e29 Compare March 15, 2022 02:34
@tomerd
Copy link
Member Author

tomerd commented Apr 11, 2022

@swift-server-bot test this please

@tomerd tomerd mentioned this pull request Apr 11, 2022
/// A metadata value which is a `String`.
///
/// Because `MetadataValue` implements `ExpressibleByStringInterpolation`, and `ExpressibleByStringLiteral`,
/// you don't need to type `.string(someType.description)` you can use the string interpolation `"\(someType)"`.
case string(String)

/// A metadata value which is some `CustomStringConvertible`.
#if compiler(>=5.6)
case stringConvertible(CustomStringConvertible & Sendable)
Copy link
Member

@fabianfett fabianfett Apr 12, 2022

Choose a reason for hiding this comment

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

Why does the value need to be Sendable here? Also this might be breaking as is.

I think to make this non breaking we need:

@preconcurrency protocol LogMetadataCustomStringConvertible: CustomStringConvertible & Sendable {}

And then we can go for:

case stringConvertible(LogMetadataCustomStringConvertible)

Copy link
Contributor

Choose a reason for hiding this comment

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

Because otherwise MetadataValue cannot conform to Sendable, which in term means Logger.Metadata cannot conform to Sendable, which in the end means Logger can't conform to Sendable.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think to make this non breaking we need:

@preconcurrency protocol LogMetadataCustomStringConvertible: CustomStringConvertible & Sendable {}

This wouldn't work either, because this would be a new protocol. Currently, it only requires CustomStringConvertible. Maybe a typealias would work:

@preconcurrency typealias LogMetadataCustomStringConvertible = CustomStringConvertible & Sendable

But I'm not sure if @preconcurrency is supported in this case.

Copy link
Member

@fabianfett fabianfett Apr 12, 2022

Choose a reason for hiding this comment

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

Because otherwise MetadataValue cannot conform to Sendable, which in term means Logger.Metadata cannot conform to Sendable, which in the end means Logger can't conform to Sendable.

Yeah, I get that. However we could also transform CustomStringConvertible to a string directly on the call-site. This would allow us to not require Sendable. However a class that might change its string representation at a later point, would always be represented by its original value, if it is added to the metadata.

This wouldn't work either, because this would be a new protocol. Currently, it only requires CustomStringConvertible.

@ffried Very good point. Going directly to string might potentially allow us to work around the semver major here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is more to that... stringConvertible is currently kind of an escape hatch to pass arbitrary objects to the log handlers. We use it to for example control which file a message is logged to in CocoaLumberjack's log handler. Most of these usages are probably fine with adding Sendable, though.

Also, changing the enum case this way will also result in a semver major.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ktoso are you saying that adding the Sendable protocol requirement will only yield warnings until Swift 6?

Copy link
Member

Choose a reason for hiding this comment

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

That's right, I just confirmed with Doug as well. If you were seeing an error in beta-1 (maybe?), then Doug says this could have been a bug and is still just a warning nowadays and will continue to be.

Copy link
Member Author

Choose a reason for hiding this comment

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

in that case I am also comfortable with this soft break.

@ffried @fabianfett @weissi @Lukasa wdyt?

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. A warning is fine. 👍
It's the same as when for example a new deprecation is added. There would also be a warning then.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm ok with a warning here.

@tomerd
Copy link
Member Author

tomerd commented Jun 29, 2022

lets take #222 first

@tomerd tomerd added the 🔨 semver/patch No public API change. label Jun 29, 2022
tomerd added 2 commits June 29, 2022 11:14
motivation: adjust to swift 5.6

changes:
* define sendable shims for protocols and structs that may be used in async context
* adjust tests
* add a test to make sure no warning are emittted
@tomerd tomerd changed the title [wip] adopt sendable adopt sendable Jun 29, 2022
@tomerd
Copy link
Member Author

tomerd commented Jun 29, 2022

@yim-lee @weissi @Lukasa @ktoso @fabianfett this is ready to go. ptal

Tests/LoggingTests/TestSendable.swift Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants