Skip to content

Strict safety improvements toolchain workaround #78340

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

DougGregor
Copy link
Member

This is #78332, but with #78327 temporarily reverted because it looks like it caused this build failure:

/Users/ec2-user/jenkins/workspace/swift-PR-toolchain-macos/branch-main/buildbot_osx/swift-macosx-x86_64/lib/swift/xros/Swift.swiftmodule/arm64-apple-xros.private.swiftinterface:2371:2: error: '@backDeployed' requires that global function '_diagnoseUnavailableCodeReached()' have a body
 2369 | @usableFromInline
 2370 | @inline(never) internal func _diagnoseUnexpectedEnumCase<SwitchedValue>(type: SwitchedValue.Type) -> Swift.Never
 2371 | @backDeployed(before: macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0)
      |  `- error: '@backDeployed' requires that global function '_diagnoseUnavailableCodeReached()' have a body
 2372 | @usableFromInline
 2373 | @inline(never) @_semantics("unavailable_code_reached") internal func _diagnoseUnavailableCodeReached() -> Swift.Never

Under strict concurrency and memory safety, uses of `@unchecked
Sendable` conformances are considered unsafe. Diagnose the use sites,
not the declaration site.
@preconcurrency imports disable Sendable checking, which can lead to
data races that undermine memory safety. Diagnose such imports, and
require `@safe(unchecked)` to suppress the diagnostic.
Aligns with the current proposal and fixes rdar://127128995
…orporate @unsafe

Protocol conformances have a handful attributes that can apply to them
directly, including @unchecked (for Sendable), @preconcurrency, and
@retroactive. Generalize this into an option set that we carry around,
so it's a bit easier to add them, as well as reworking the
serialization logic to deal with an arbitrary number of such options.

Use this generality to add support for @unsafe conformances, which are
needed when unsafe witnesses are used to conform to safe requirements.
Implement general support for @unsafe conformances, including
producing a single diagnostic per missing @unsafe that provides a
Fix-It and collects together all of the unsafe witnesses as notes.
…n't need to be @unsafe

What we should actually do with SerialExecutor conformances is not yet clear, though.
The `@unchecked` conformance is effectively the same as
`@safe(unchecked)`, in that it asserts memory safety in a place where
it cannot be automatically checked. But once that has been asserted,
there is no reason to diagnose anywhere else.

While here, drop the "unsafe declaration here" note, which isn't
adding value but did add noise.

Thanks, Alex!
@DougGregor
Copy link
Member Author

@swift-ci please build toolchain macOS

@DougGregor DougGregor closed this Jan 8, 2025
@DougGregor DougGregor deleted the strict-safety-improvements-toolchain-workaround branch January 8, 2025 19:08
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.

1 participant