Skip to content

more Sendable conformances & Sendable Context #381

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
merged 1 commit into from
Feb 8, 2023

Conversation

weissi
Copy link
Contributor

@weissi weissi commented Jan 17, 2023

Technically API breaking:

  • switches public typealias Context = Dictionary<...> for public struct Context
  • requires HashingAlgorithm and TracingEvent(Collection) to be Sendable

@neonichu
Copy link
Contributor

@swift-ci please test

@neonichu
Copy link
Contributor

We don't promise a stable API at this point, so API breakage is acceptable. We'd need to adopt any potential clients in the toolchain, of course.

@weissi
Copy link
Contributor Author

weissi commented Jan 17, 2023

We don't promise a stable API at this point, so API breakage is acceptable. We'd need to adopt any potential clients in the toolchain, of course.

Yes, I'd tag it as 0.5.0 too in which case public API breakage is almost expected for 0.x packages.

@neonichu
Copy link
Contributor

@swift-ci please test

}

@available(*, deprecated, message: "Values should be Sendable")
@_disfavoredOverload
Copy link
Contributor

Choose a reason for hiding this comment

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

one of my favorite tricks :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jakepetroules at some point we'll need @_overloadFavouriteness(10) if we have need more than one level ;)

@@ -135,8 +135,24 @@ public struct TracingEvent: TracingEventProtocol, Codable {
#endif
}

public class TracingCollection: TracingCollectionProtocol {
public var events: [TracingEventProtocol] = []
public final class TracingCollection: TracingCollectionProtocol, @unchecked Sendable {
Copy link
Contributor

@jakepetroules jakepetroules Jan 18, 2023

Choose a reason for hiding this comment

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

@​unchecked because of NSLock? (if so, can add a comment?) Do we have a Lock implementation in TSC which is sendable, that we could use instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's unchecked because it's manually synchronised with the lock. Even if the lock itself is sendable, the compiler can't check that you've used it correctly.

The only way to get that is to use something like NIOLockedValueBox<[TracingEventProtocol>] but that's not available here.

@neonichu
Copy link
Contributor

Looks like the macOS failures are all about the changes?

@neonichu
Copy link
Contributor

@swift-ci please test

@weissi
Copy link
Contributor Author

weissi commented Jan 18, 2023

@neonichu Yes, that's an old Foundation SDK which doesn't have enough Sendable annotations. Which SDK is this using?

@neonichu
Copy link
Contributor

@weissi I believe the Xcode installed on Swift CI is still 13A5201i, so that would mean macOS 12.0 (21A5294d). @shahmishal to double check.

@weissi
Copy link
Contributor Author

weissi commented Jan 18, 2023

@neonichu thanks, yeah, that's old. I removed the Sendables that are currently problematic because that Xcode also doesn't understand @preconcurrency :P

@neonichu
Copy link
Contributor

@swift-ci please test

@weissi
Copy link
Contributor Author

weissi commented Jan 23, 2023

@neonichu / @jakepetroules Could we upgrade the CI? It seems ridiculously old:

/Users/ec2-user/jenkins/workspace/pr-swift-tools-support-core-macos/branch-main/swift-tools-support-core/Sources/TSCUtility/Context.swift:13:79: error: unknown attribute 'unchecked'
public struct Context: /* until we can remove the support for 'Any' values */ @unchecked Sendable {
                                                                              ^

it doesn't know about @unchecked??

@MaxDesiatov
Copy link
Contributor

MaxDesiatov commented Jan 23, 2023

So far I've used UnsafeSendable instead of @unchecked Sendable, conditional on #if swift(<5.6) as in PR #382: https://github.com/apple/swift-tools-support-core/pull/382/files#diff-c659355a0fbeab4d2e87c402f625dfcd9d014493b2c5f28a0d45ea722de362ddR13

@weissi
Copy link
Contributor Author

weissi commented Jan 23, 2023

So far I've used UnsafeSendable instead of @unchecked Sendable, conditional on #if swift(<5.6) as in PR #382: https://github.com/apple/swift-tools-support-core/pull/382/files#diff-c659355a0fbeab4d2e87c402f625dfcd9d014493b2c5f28a0d45ea722de362ddR13

Sure, but @unchecked Sendable got introduced with Swift 5.7 (-> https://github.com/apple/swift-evolution/blob/main/proposals/0302-concurrent-value-and-concurrent-closures.md#sendable-and-sendable-closures) and given that SwiftPM is part of the Swift toolchain it should be targeting >= 5.8 by now and not < 5.7.

So yes, I know I could put in hacks to work around this, this really shouldn't be necessary, right?

@MaxDesiatov
Copy link
Contributor

MaxDesiatov commented Jan 23, 2023

AFAIR we're keeping SwiftPM compatible with older Swift versions on purpose, since libSwiftPM clients may use those. @neonichu would be able to clarify this.

Thanks for linking to that proposal, based on that swift(<5.6) check in our codebase should really look like swift(<5.7), right?

@neonichu
Copy link
Contributor

AFAIR we're keeping SwiftPM compatible with older Swift versions on purpose, since libSwiftPM clients may use those. @neonichu would be able to clarify this.

Yes, we can definitely not target 5.8 only. It's also not just about libSwiftPM clients, but we want to enable people to contribute with just the stable version of Xcode.

There's also the practical issue that Swift CI has 13A5201i installed, so we have to stay compatible with that for the time being. If that gets upgraded to a 14.x era Xcode, we could discuss requiring 5.7

@jakepetroules
Copy link
Contributor

@neonichu / @jakepetroules Could we upgrade the CI? It seems ridiculously old:

/Users/ec2-user/jenkins/workspace/pr-swift-tools-support-core-macos/branch-main/swift-tools-support-core/Sources/TSCUtility/Context.swift:13:79: error: unknown attribute 'unchecked'
public struct Context: /* until we can remove the support for 'Any' values */ @unchecked Sendable {
                                                                              ^

it doesn't know about @unchecked??

Based on @neonichu's comments just above, can you add #if swift(...) as needed to get this past CI checks?

@weissi
Copy link
Contributor Author

weissi commented Jan 25, 2023

@swift-ci please test

@weissi
Copy link
Contributor Author

weissi commented Jan 27, 2023

@neonichu I'm hitting this linker error (CC @jakepetroules / @MaxDesiatov )

[82/84] Merging module TSCBasicTests
[83/84] Merging module TSCUtilityTests
Undefined symbols for architecture x86_64:
  "_$ss8SendableMp", referenced from:
      _$ss8Sendable_pMa in Context.swift.o
ld: symbol(s) not found for architecture x86_64
[83/84] Linking swift-tools-support-corePackageTests
error: fatalError

which is

$ pbpaste | swift demangle
Undefined symbols for architecture x86_64:
  "protocol descriptor for Swift.Sendable", referenced from:
      type metadata accessor for Swift.Sendable in Context.swift.o
ld: symbol(s) not found for architecture x86_64
[83/84] Linking swift-tools-support-corePackageTests

a bug in either Swift or SwiftPM not managing to link libswift_Concurrency.dylib on macOS :|. Not sure how to proceed without upgrading the buiders here...

@weissi
Copy link
Contributor Author

weissi commented Jan 30, 2023

@swift-ci please test

@weissi
Copy link
Contributor Author

weissi commented Jan 31, 2023

@swift-ci please test

@weissi
Copy link
Contributor Author

weissi commented Feb 2, 2023

@swift-ci please test

@weissi
Copy link
Contributor Author

weissi commented Feb 7, 2023

@swift-ci please test

@weissi
Copy link
Contributor Author

weissi commented Feb 7, 2023

@swift-ci please test

@weissi
Copy link
Contributor Author

weissi commented Feb 7, 2023

@swift-ci please test

@weissi
Copy link
Contributor Author

weissi commented Feb 7, 2023

@swift-ci please test

@weissi
Copy link
Contributor Author

weissi commented Feb 7, 2023

@swift-ci please test

3 similar comments
@weissi
Copy link
Contributor Author

weissi commented Feb 7, 2023

@swift-ci please test

@weissi
Copy link
Contributor Author

weissi commented Feb 7, 2023

@swift-ci please test

@weissi
Copy link
Contributor Author

weissi commented Feb 7, 2023

@swift-ci please test

@weissi
Copy link
Contributor Author

weissi commented Feb 7, 2023

@swift-ci please test

1 similar comment
@weissi
Copy link
Contributor Author

weissi commented Feb 8, 2023

@swift-ci please test

@weissi
Copy link
Contributor Author

weissi commented Feb 8, 2023

@swift-ci please test

@weissi
Copy link
Contributor Author

weissi commented Feb 8, 2023

@swift-ci please test

@weissi weissi merged commit add9e15 into swiftlang:main Feb 8, 2023
@weissi weissi deleted the jw-sendable-moar branch February 8, 2023 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants