-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[BitwiseCopyable] Allow suppression via ~. #72646
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
[BitwiseCopyable] Allow suppression via ~. #72646
Conversation
|
||
@available(*, unavailable) | ||
extension MemoryLayout: _BitwiseCopyable {} | ||
public enum MemoryLayout<T: ~Copyable>: ~_BitwiseCopyable, Copyable {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we care that MemoryLayout is not bitwise copyable? It has no cases anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was requested here: swiftlang/swift-evolution#2314 (comment) .
/// Emulates the following enum with associated values: | ||
/// enum InheritedTypeResult { | ||
/// case inherited(Type) | ||
/// case SuppressedInference(KnownProtocolKind) | ||
/// case `default` | ||
/// } | ||
class InheritedTypeResult { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will introduce a second representation for the ~Protocol
syntax in the AST: For the "invertible" protocols like Copyable
, we represent them as a ProtocolCompositionType
, which has its own list of inverses. I think that representation doesn't make sense for this use case, so it's okay to have two.
5943253
to
adf0553
Compare
5e87c57
to
78f3e45
Compare
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want to look at the callers of getDirectlyInheritedNominalTypeDecls() in ConformanceLookupTable.cpp, and put the logic there. getDirectlyInheritedNominalTypeDecls() should be generalized to collect and return these new "repressible" protocols.
@@ -78,13 +81,75 @@ void simple_display( | |||
|
|||
void simple_display(llvm::raw_ostream &out, ASTContext *ctx); | |||
|
|||
/// Emulates the following enum with associated values: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a lot of new code for just the new ~BitwiseCopyable
syntax. Can you instead find a way to generalize the existing logic for ~Copyable
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having a different representation for this case--the case of a protocol that isn't conformed to by all types by default (i.e. unlike Copyable
) but is inferred automatically for some types--makes sense.
lib/Sema/TypeCheckDeclPrimary.cpp
Outdated
/// Check the inheritance clause of a type declaration or extension thereof. | ||
/// | ||
/// This routine performs detailed checking of the inheritance clause of the | ||
/// given type or extension. It need only be called within the primary source | ||
/// file. | ||
static void checkInheritanceClause( | ||
llvm::PointerUnion<const TypeDecl *, const ExtensionDecl *> declUnion) { | ||
ArrayRef<InheritedEntry> InheritanceClauseRequest::evaluate( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the wrong thing to turn into a request. checkInheritanceClause()
only exists to emit diagnostics, and we don't want to emit the diagnostics in a secondary file. TypeCheckDeclPrimary.cpp shouldn't have logic for computing things, it's just diagnostics
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this requestification and moved SuppressesConformanceRequest
into TypeCheckRequestFunctions.cpp
.
78f3e45
to
0e78f7e
Compare
@swift-ci please build toolchain |
This is the subset of suppressible protocols that are not invertible. This commit doesn't add any such protocols.
Add the machinery to support suppression of inference of conformance to protocols that would otherwise be derived automatically. This commit does not enable any conformances to be suppressed.
In addition to the existing language mechanism of `@available(*, unavailable)`.
0e78f7e
to
eb1f0ac
Compare
@swift-ci please test |
1 similar comment
@swift-ci please test |
In addition to the existing language mechanism of
@available(*, unavailable)
on an extension.