Skip to content

Suppress compiler warnings about Errors with non-Sendable members #727

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 2 commits into from
Mar 5, 2024

Conversation

tshortli
Copy link
Contributor

@tshortli tshortli commented Mar 4, 2024

A type conforming to Error must be Sendable, but DelimiterLexError and CompilerLexError carry source locations represented by UnsafeRawPointer, which is inherently non-Sendable. The compiler diagnoses the failure to meet Sendable requirements on these error types, which will prevent Swift 6 adoption in _RegexParser and also generates build log spam every time the compiler and standard library are built. There are a couple ways to resolve this problem:

  1. Refactor so that the errors do not need to carry source locations.
  2. Refactor to avoid using Error (the code using these errors would not require Sendable if it were not for Error's inherent Sendable requirement).
  3. Suppress the warnings with an @unchecked Sendable wrapper.

Option 1 probably requires significant refactoring and option 2 seems undesirable since it means that the implementation must forgo the convenience of Swift's error handling model. Therefore this PR implements option 3 as the most expedient way to stop the diagnostic spam, leaving improvement on the status quo as a future exercise.

Also includes a drive-by fix for a trivial, unrelated warning.

A type conforming to `Error` must be `Sendable`, but `DelimiterLexError` and
`CompilerLexError` carry source locations represented by `UnsafeRawPointer`,
which is inherently non-`Sendable`. The compiler diagnoses the failure to meet
`Sendable` requirements on these error types, which will prevent Swift 6 adoption
in `_RegexParser` and also generates build log spam every time the compiler and
standard library are built. There are a couple ways to resolve this problem:

1. Refactor so that the errors to not need to carry source locations.
2. Refactor to avoid using `Error` (the code using these errors would not
   require `Sendable` if it were not for `Error`'s inherent `Sendable`
   requirement).
3. Suppress the warnings with a `@uncheck Sendable` wrapper.

Option 1 probably requires significant refactoring and option 2 seems
undesirable since it means that the implementation must forgo the convenience
of Swift's error handling model. Therefore this PR implements option 3 as the
most expedient way to stop the diagnostic spam, leaving improvement on the
status quo as a future exercise.
@tshortli
Copy link
Contributor Author

tshortli commented Mar 4, 2024

@swift-ci please test

Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

Thanks!

@tshortli
Copy link
Contributor Author

tshortli commented Mar 4, 2024

@swift-ci please test Windows

@tshortli tshortli merged commit ef0ae64 into swiftlang:swift/main Mar 5, 2024
@tshortli tshortli deleted the sendable-errors branch March 5, 2024 02:48
natecook1000 pushed a commit that referenced this pull request Mar 8, 2024
Suppress compiler warnings about Errors with non-Sendable members
@natecook1000
Copy link
Member

Unless there are exceptional circumstances, please make changes on main before/at the same time as landing them on swift/main. Thanks!

Updating main in #729.

@tshortli
Copy link
Contributor Author

tshortli commented Mar 8, 2024

Unless there are exceptional circumstances, please make changes on main before/at the same time as landing them on swift/main. Thanks!

Sorry, I think I'm just very confused about how this is supposed to work in this repo. It looked to me like main was very out of date and therefore was abandoned or something but I must have been looking at the wrong thing.

natecook1000 pushed a commit that referenced this pull request Mar 9, 2024
Suppress compiler warnings about Errors with non-Sendable members
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.

3 participants