Skip to content

Commit 41e2c85

Browse files
committed
NCGenerics: handle legacy definition of Sendable
This should be a temporary measure while bootstrapping the feature.
1 parent 0f03136 commit 41e2c85

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1586,7 +1586,9 @@ void PrintAST::printInheritedFromRequirementSignature(ProtocolDecl *proto,
15861586

15871587
// The invertible protocols themselves do not need to state inverses in their
15881588
// inheritance clause, because they do not gain any default requirements.
1589-
if (!proto->getInvertibleProtocolKind())
1589+
// HACK: also exclude Sendable from getting inverses printed.
1590+
if (!proto->getInvertibleProtocolKind()
1591+
&& !proto->isSpecificProtocol(KnownProtocolKind::Sendable))
15901592
flags |= PrintInverseRequirements;
15911593

15921594
printRequirementSignature(

lib/AST/Decl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6634,6 +6634,11 @@ bool ProtocolDecl::requiresInvertible(InvertibleProtocolKind ip) const {
66346634
if (proto->getInvertibleProtocolKind())
66356635
return TypeWalker::Action::Continue;
66366636

6637+
// HACK: claim that Sendable also doesn't implicitly inherit Copyable, etc.
6638+
// This shouldn't be needed after Swift 6.0
6639+
if (proto->isSpecificProtocol(KnownProtocolKind::Sendable))
6640+
return TypeWalker::Action::Continue;
6641+
66376642
// Otherwise, check to see if there's an inverse on this protocol.
66386643
switch (proto->getMarking(ip).getInverse().getKind()) {
66396644
case InverseMarking::Kind::None:

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,10 @@ StructuralRequirementsRequest::evaluate(Evaluator &evaluator,
987987

988988
SmallVector<StructuralRequirement, 2> defaults;
989989
// We do not expand defaults for invertible protocols themselves.
990-
if (!proto->getInvertibleProtocolKind())
990+
// HACK: We don't expand for Sendable either. This shouldn't be needed after
991+
// Swift 6.0
992+
if (!proto->getInvertibleProtocolKind()
993+
&& !proto->isSpecificProtocol(KnownProtocolKind::Sendable))
991994
InverseRequirement::expandDefaults(ctx, needsDefaultRequirements, defaults);
992995

993996
applyInverses(ctx, needsDefaultRequirements, inverses, defaults, errors);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-typecheck-verify-swift \
2+
// RUN: -parse-stdlib -module-name Swift \
3+
// RUN: -enable-experimental-feature NoncopyableGenerics
4+
5+
@_marker protocol Copyable {}
6+
7+
// This is how Sendable was defined prior to NoncopyableGenerics.
8+
// Notice that there is no ~Copyable or ~Escapable on it. That would normally
9+
// imply that it requires Copyable & Escapable. We don't want that.
10+
//
11+
// In order to allow bootstrapping with hostlibs and various mix-and-matched
12+
// compilers and stdlibs this test ensures that we still treat this legacy
13+
// definition of Sendable as if it does _not_ require Copyable and Escapable.
14+
@_marker protocol Sendable {}
15+
16+
enum E: ~Copyable, Sendable {}
17+
@_moveOnly struct S: Sendable {}
18+
19+
// expected-note@+2 3{{add}}
20+
// expected-error@+1 {{parameter of noncopyable type 'T' must specify ownership}}
21+
func checkGeneric<T>(_ t: T) where T: ~Copyable, T: Sendable {}

0 commit comments

Comments
 (0)