Skip to content

Parse @unsafe nonisolated conformance #3112

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

Conversation

DougGregor
Copy link
Member

A protocol conformance can have a conformance attribute (like @unsafe) along with nonisolated. Extend the syntax tree to allow type specifiers after the type attributes, and parse nonisolated in that position.

Fixes #3109.

This is needed to account for 'nonisolated' occuring after type
attributes within a protocol conformance.
The only "late" specifier at the moment is `nonisolated`, used by
protocol conformances.

Fixes issue swiftlang#3109.
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test Windows

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test Windows

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Thank you. It’s a little sad that we are not consistent with the ordering of attributes and specifiers in front of types but I assume we can’t do anything about that anymore, can we? That’s probably also why I’m not a huge fan of the name lateSpecifiers but I don’t have a better suggestion, it’s about as clear as it gets.

Would like to hear @rintaro’s feedback as well.

Comment on lines +179 to +180
case .collection(_, collectionElementName: let childElt?, _, _, generateDeprecatedAddFunction: true) = child
.kind
Copy link
Member

Choose a reason for hiding this comment

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

Interesting formatting choice by swift-format here. swift-format seems to be happy with the following as well, which I’d prefer

Suggested change
case .collection(_, collectionElementName: let childElt?, _, _, generateDeprecatedAddFunction: true) = child
.kind
case .collection(_, collectionElementName: let childElt?, _, _, generateDeprecatedAddFunction: true) =
child.kind

Copy link
Member Author

Choose a reason for hiding this comment

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

Formatting fix in #3114 because I too eagerly pushed "merge"

@DougGregor DougGregor merged commit 7eca32c into swiftlang:main Jun 24, 2025
28 checks passed
@DougGregor DougGregor deleted the parse-unsafe-nonisolated-conformance branch June 24, 2025 13:33
@DougGregor
Copy link
Member Author

Thank you. It’s a little sad that we are not consistent with the ordering of attributes and specifiers in front of types but I assume we can’t do anything about that anymore, can we? That’s probably also why I’m not a huge fan of the name lateSpecifiers but I don’t have a better suggestion, it’s about as clear as it gets.

Would like to hear @rintaro’s feedback as well.

An alternative approach here would be to handle the specifiers different for the places where we can have modifiers, i.e. parameters (where things like inout go before the type) and conformances (where nonisolated goes after the attributes). I suppose we could revisit the language design here to force specifiers like this to be first, i.e., nonisolated @preconcurrency. Parameters are inconsistent with declarations, so conformances could choose which one to align with.

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.

@attr nonisolated P inheritance clause entry rejected
2 participants