Skip to content

Commit 4fb90d3

Browse files
authored
Merge pull request #71654 from kavon/ncgenerics-test-fixes-kavon-v14
Ncgenerics test fixes kavon v14
2 parents 35187d2 + 63ed8ec commit 4fb90d3

File tree

6 files changed

+67
-21
lines changed

6 files changed

+67
-21
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
@@ -6636,6 +6636,11 @@ bool ProtocolDecl::requiresInvertible(InvertibleProtocolKind ip) const {
66366636
if (proto->getInvertibleProtocolKind())
66376637
return TypeWalker::Action::Continue;
66386638

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

lib/AST/GenericSignature.cpp

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,11 @@ void GenericSignature::verify() const {
883883
}
884884

885885
void GenericSignature::verify(ArrayRef<Requirement> reqts) const {
886+
auto dumpAndAbort = [&]() {
887+
getPointer()->getRequirementMachine()->dump(llvm::errs());
888+
abort();
889+
};
890+
886891
auto canSig = getCanonicalSignature();
887892

888893
PrettyStackTraceGenericSignature debugStack("checking", canSig);
@@ -903,14 +908,14 @@ void GenericSignature::verify(ArrayRef<Requirement> reqts) const {
903908
llvm::errs() << "Left-hand side must be a type parameter: ";
904909
reqt.dump(llvm::errs());
905910
llvm::errs() << "\n";
906-
abort();
911+
dumpAndAbort();
907912
}
908913

909914
if (!canSig->isReducedType(reqt.getFirstType())) {
910915
llvm::errs() << "Left-hand side is not reduced: ";
911916
reqt.dump(llvm::errs());
912917
llvm::errs() << "\n";
913-
abort();
918+
dumpAndAbort();
914919
}
915920
}
916921

@@ -921,28 +926,28 @@ void GenericSignature::verify(ArrayRef<Requirement> reqts) const {
921926
llvm::errs() << "Left hand side is not a generic parameter: ";
922927
reqt.dump(llvm::errs());
923928
llvm::errs() << "\n";
924-
abort();
929+
dumpAndAbort();
925930
}
926931

927932
if (!reqt.getFirstType()->isRootParameterPack()) {
928933
llvm::errs() << "Left hand side is not a parameter pack: ";
929934
reqt.dump(llvm::errs());
930935
llvm::errs() << "\n";
931-
abort();
936+
dumpAndAbort();
932937
}
933938

934939
if (!reqt.getSecondType()->is<GenericTypeParamType>()) {
935940
llvm::errs() << "Right hand side is not a generic parameter: ";
936941
reqt.dump(llvm::errs());
937942
llvm::errs() << "\n";
938-
abort();
943+
dumpAndAbort();
939944
}
940945

941946
if (!reqt.getSecondType()->isRootParameterPack()) {
942947
llvm::errs() << "Right hand side is not a parameter pack: ";
943948
reqt.dump(llvm::errs());
944949
llvm::errs() << "\n";
945-
abort();
950+
dumpAndAbort();
946951
}
947952

948953
break;
@@ -951,7 +956,7 @@ void GenericSignature::verify(ArrayRef<Requirement> reqts) const {
951956
llvm::errs() << "Right-hand side is not reduced: ";
952957
reqt.dump(llvm::errs());
953958
llvm::errs() << "\n";
954-
abort();
959+
dumpAndAbort();
955960
}
956961
break;
957962

@@ -977,21 +982,21 @@ void GenericSignature::verify(ArrayRef<Requirement> reqts) const {
977982
llvm::errs() << "Left hand side does not have a reduced parent: ";
978983
reqt.dump(llvm::errs());
979984
llvm::errs() << "\n";
980-
abort();
985+
dumpAndAbort();
981986
}
982987

983988
if (reqt.getSecondType()->isTypeParameter()) {
984989
if (!hasReducedOrConcreteParent(secondType)) {
985990
llvm::errs() << "Right hand side does not have a reduced parent: ";
986991
reqt.dump(llvm::errs());
987992
llvm::errs() << "\n";
988-
abort();
993+
dumpAndAbort();
989994
}
990995
if (compareDependentTypes(firstType, secondType) >= 0) {
991996
llvm::errs() << "Out-of-order type parameters: ";
992997
reqt.dump(llvm::errs());
993998
llvm::errs() << "\n";
994-
abort();
999+
dumpAndAbort();
9951000
}
9961001

9971002
if (component.empty()) {
@@ -1001,7 +1006,7 @@ void GenericSignature::verify(ArrayRef<Requirement> reqts) const {
10011006
<< "is out-of-order: ";
10021007
reqt.dump(llvm::errs());
10031008
llvm::errs() << "\n";
1004-
abort();
1009+
dumpAndAbort();
10051010
}
10061011

10071012
component.push_back(secondType);
@@ -1010,7 +1015,7 @@ void GenericSignature::verify(ArrayRef<Requirement> reqts) const {
10101015
llvm::errs() << "Right hand side is not reduced: ";
10111016
reqt.dump(llvm::errs());
10121017
llvm::errs() << "\n";
1013-
abort();
1018+
dumpAndAbort();
10141019
}
10151020

10161021
if (component.empty()) {
@@ -1019,7 +1024,7 @@ void GenericSignature::verify(ArrayRef<Requirement> reqts) const {
10191024
llvm::errs() << "Inconsistent concrete requirement in equiv. class: ";
10201025
reqt.dump(llvm::errs());
10211026
llvm::errs() << "\n";
1022-
abort();
1027+
dumpAndAbort();
10231028
}
10241029
}
10251030
break;
@@ -1043,7 +1048,7 @@ void GenericSignature::verify(ArrayRef<Requirement> reqts) const {
10431048
llvm::errs() << "Out-of-order left-hand side: ";
10441049
reqt.dump(llvm::errs());
10451050
llvm::errs() << "\n";
1046-
abort();
1051+
dumpAndAbort();
10471052
}
10481053

10491054
// If we have a concrete same-type requirement, we shouldn't have any
@@ -1055,15 +1060,15 @@ void GenericSignature::verify(ArrayRef<Requirement> reqts) const {
10551060
<< "any other requirements: ";
10561061
reqt.dump(llvm::errs());
10571062
llvm::errs() << "\n";
1058-
abort();
1063+
dumpAndAbort();
10591064
}
10601065
}
10611066

10621067
if (prevReqt.compare(reqt) >= 0) {
10631068
llvm::errs() << "Out-of-order requirement: ";
10641069
reqt.dump(llvm::errs());
10651070
llvm::errs() << "\n";
1066-
abort();
1071+
dumpAndAbort();
10671072
}
10681073
}
10691074

@@ -1079,11 +1084,11 @@ void GenericSignature::verify(ArrayRef<Requirement> reqts) const {
10791084

10801085
if (protos.size() != canonicalProtos.size()) {
10811086
llvm::errs() << "Redundant conformance requirements in signature\n";
1082-
abort();
1087+
dumpAndAbort();
10831088
}
10841089
if (!std::equal(protos.begin(), protos.end(), canonicalProtos.begin())) {
10851090
llvm::errs() << "Out-of-order conformance requirements\n";
1086-
abort();
1091+
dumpAndAbort();
10871092
}
10881093
}
10891094

@@ -1095,7 +1100,7 @@ void GenericSignature::verify(ArrayRef<Requirement> reqts) const {
10951100
llvm::errs() << "Reduced type: " << pair.first << "\n";
10961101
llvm::errs() << "Left hand side of first requirement: "
10971102
<< pair.second.front() << "\n";
1098-
abort();
1103+
dumpAndAbort();
10991104
}
11001105
}
11011106
}

lib/AST/NameLookup.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3129,6 +3129,16 @@ DirectlyReferencedTypeDecls InheritedDeclsReferencedRequest::evaluate(
31293129
llvm::PointerUnion<const TypeDecl *, const ExtensionDecl *> decl,
31303130
unsigned index) const {
31313131

3132+
// FIXME: this is an awful hack for NoncopyableGenerics.
3133+
// The correct fix here is to integrate the guts of
3134+
// `ProtocolDecl::requiresInvertible` into this request, so that it works
3135+
// automatically, not only for `ProtocolDecl::inheritsFrom` but for other
3136+
// nominal types too.
3137+
if (auto typeDecl = decl.dyn_cast<const TypeDecl *>())
3138+
if (auto protoDecl = dyn_cast<ProtocolDecl>(typeDecl))
3139+
if (protoDecl->isSpecificProtocol(KnownProtocolKind::Sendable))
3140+
return {};
3141+
31323142
// Prefer syntactic information when we have it.
31333143
const TypeLoc &typeLoc = InheritedTypes(decl).getEntry(index);
31343144
if (auto typeRepr = typeLoc.getTypeRepr()) {

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)