Skip to content

Require explicit statement of all Copyable/Escapable requirements for conditional Copyable/Escapable conformances. #78705

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

jckarter
Copy link
Contributor

As specified by the SE-0446 acceptance, extensions that declare a type's conditional Copyable or Escapable ability must reiterate explicitly all of the Copyable and/or Escapable requirements, whether required or not required (by e.g. ~Copyable) that were suppressed in the original type declaration.

@jckarter
Copy link
Contributor Author

@swift-ci Please test

}
// Or it can be implied by a requirement on something that's inherently
// copyable.
if (req.req.getKind() == RequirementKind::Superclass) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about same-type requirements to concrete types like T == Int? Also doesn't T: AnyObject imply Copyable today?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One thing I was hoping to hear from you (or maybe @kavon) was whether there was a preexisting operation to filter out implied requirements. I see that further down, these get fed into a RequirementMachine, but I'm not sure whether I can do that and still figure out which requirements came from implicit defaults or not in the resulting generic signature.

Copy link
Member

@kavon kavon Jan 21, 2025

Choose a reason for hiding this comment

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

I don't think we already have a utility to determine which Copyable/Escapable requirements were explicitly written in source or not. I hadn't built-in state tracking like that, especially since it'd need to survive the RequirementMachine all the way into a GenericSignature. I think you lose that implicit/explicit information after you construct the GenericSignature from the raw StructuralRequirements.

What we do have is a sort of reconstruction of the minimal requirements needed to specify a ProtocolDecl's GenericSignature in this getSyntacticInheritanceClause for the purpose of the ASTPrinter. It filters out all invertible protocols though.

@jckarter jckarter force-pushed the explicit-conditional-invertible-extension-requirements branch from 020782d to f4898f5 Compare January 17, 2025 18:52
@jckarter
Copy link
Contributor Author

@swift-ci Please test

@jckarter jckarter force-pushed the explicit-conditional-invertible-extension-requirements branch from f4898f5 to a22bafc Compare January 17, 2025 22:23
@jckarter
Copy link
Contributor Author

@swift-ci Please test

@jckarter jckarter force-pushed the explicit-conditional-invertible-extension-requirements branch from a22bafc to 4cba8c1 Compare January 18, 2025 01:19
@jckarter
Copy link
Contributor Author

@swift-ci Please test

… for conditional `Copyable`/`Escapable` conformances.

As specified by the SE-0446 acceptance, extensions that declare a type's
conditional `Copyable` or `Escapable` ability must reiterate explicitly all
of the `Copyable` and/or `Escapable` requirements, whether required or not
required (by e.g. `~Copyable`) that were suppressed in the original
type declaration.
@jckarter jckarter force-pushed the explicit-conditional-invertible-extension-requirements branch from 4cba8c1 to a0a26b8 Compare January 21, 2025 17:36
@jckarter
Copy link
Contributor Author

@swift-ci Please test

@@ -11,16 +11,20 @@ struct AttemptImplicitConditionalConformance<T: ~Copyable>: ~Copyable {
}
extension AttemptImplicitConditionalConformance: Copyable {}
// expected-error@-1 {{generic struct 'AttemptImplicitConditionalConformance' required to be 'Copyable' but is marked with '~Copyable'}}
// expected-error@-2 {{must explicitly state whether 'T' is required to conform to 'Copyable'}}
Copy link
Member

Choose a reason for hiding this comment

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

We should find a way to suppress the X is required to be Copyable but marked with ~Copyable error, in cases where this new error you've added would be emitted. The T: Copyable isn't inferred anymore on the extension, so it became unconditional and thus the old error appears.

But people are more likely to think T: Copyable is inferred, like other extensions, and your new message explains things much more clearly.

@jckarter
Copy link
Contributor Author

@swift-ci Please smoke test Linux

1 similar comment
@jckarter
Copy link
Contributor Author

@swift-ci Please smoke test Linux

@jckarter jckarter merged commit 5d0fe0a into swiftlang:main Jan 22, 2025
4 of 5 checks passed
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