Skip to content

[Concurrency] Disallow Sendable annotation on methods of non-Sendable types #69177

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
Oct 17, 2023

Conversation

angela-laar
Copy link
Contributor

Disallow Sendable annotation on methods of non-Sendable types.

@angela-laar
Copy link
Contributor Author

@swift-ci please smoke test

// Prevent Sendable Attr from being added to methods of non-sendable types
if (auto *funcDecl = dyn_cast<AbstractFunctionDecl>(D)) {
if (auto baseType = funcDecl->getImplicitSelfDecl()->getTypeInContext()) {
if (!isSendableType(dc->getParentModule(), baseType)) {
Copy link
Member

Choose a reason for hiding this comment

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

How does this behave for conditional conformances? e.g.

struct S<T> {
  let t: T

  @Sendable func test() {}
}

extension S: Sendable where T: Sendable {
  @Sendable func test2() {}
}

It seems like the first @Sendable should be diagnosed but the second should not.

Copy link
Contributor

Choose a reason for hiding this comment

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

It should work out. isSendableType() calls TypeChecker::conformsToProtocol() which checks conditional requirements, and getSelfTypeInContext() maps the interface type of self into the function's own generic environment, so the generic parameters become archetypes that satisfy those conditional requirements. Worth adding a test though!

@angela-laar angela-laar force-pushed the prevent-sendable-attribute branch 5 times, most recently from bfeed03 to 11aaebc Compare October 15, 2023 21:33
@angela-laar
Copy link
Contributor Author

@swift-ci please smoke test

@angela-laar angela-laar force-pushed the prevent-sendable-attribute branch from 0efd4df to 558b5dd Compare October 16, 2023 19:34
@angela-laar angela-laar force-pushed the prevent-sendable-attribute branch from 558b5dd to e779b05 Compare October 16, 2023 21:22
@angela-laar
Copy link
Contributor Author

@swift-ci please smoke test

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