@@ -98,10 +98,6 @@ class GenericSignatureBuilder {
98
98
using RequirementRHS =
99
99
llvm::PointerUnion<Type, ProtocolDecl *, LayoutConstraint>;
100
100
101
- // / The location of a requirement as written somewhere in the source.
102
- typedef llvm::PointerUnion<const TypeRepr *, const RequirementRepr *>
103
- WrittenRequirementLoc;
104
-
105
101
class RequirementSource ;
106
102
107
103
class FloatingRequirementSource ;
@@ -342,10 +338,8 @@ class GenericSignatureBuilder {
342
338
UnresolvedHandlingKind unresolvedHandling);
343
339
344
340
// / Add any conditional requirements from the given conformance.
345
- // /
346
- // / \returns \c true if an error occurred, \c false if not.
347
- bool addConditionalRequirements (ProtocolConformanceRef conformance,
348
- ModuleDecl *inferForModule, SourceLoc loc);
341
+ void addConditionalRequirements (ProtocolConformanceRef conformance,
342
+ ModuleDecl *inferForModule);
349
343
350
344
// / Resolve the conformance of the given type to the given protocol when the
351
345
// / potential archetype is known to be equivalent to a concrete type.
@@ -630,8 +624,7 @@ class GenericSignatureBuilder {
630
624
// / generic signature builder no longer has valid state.
631
625
GenericSignature computeGenericSignature (
632
626
bool allowConcreteGenericParams = false ,
633
- const ProtocolDecl *requirementSignatureSelfProto = nullptr ,
634
- bool rebuildingWithoutRedundantConformances = false ) &&;
627
+ const ProtocolDecl *requirementSignatureSelfProto = nullptr ) &&;
635
628
636
629
// / Compute the requirement signature for the given protocol.
637
630
static GenericSignature computeRequirementSignature (ProtocolDecl *proto);
@@ -692,7 +685,8 @@ class GenericSignatureBuilder {
692
685
void diagnoseProtocolRefinement (
693
686
const ProtocolDecl *requirementSignatureSelfProto);
694
687
695
- void diagnoseRedundantRequirements () const ;
688
+ void diagnoseRedundantRequirements (
689
+ bool onlyDiagnoseExplicitConformancesImpliedByConcrete=false ) const ;
696
690
697
691
void diagnoseConflictingConcreteTypeRequirements (
698
692
const ProtocolDecl *requirementSignatureSelfProto);
@@ -845,7 +839,7 @@ class GenericSignatureBuilder {
845
839
class GenericSignatureBuilder ::RequirementSource final
846
840
: public llvm::FoldingSetNode,
847
841
private llvm::TrailingObjects<RequirementSource, ProtocolDecl *,
848
- WrittenRequirementLoc > {
842
+ SourceLoc > {
849
843
850
844
friend class FloatingRequirementSource ;
851
845
friend class GenericSignature ;
@@ -947,7 +941,7 @@ class GenericSignatureBuilder::RequirementSource final
947
941
const StorageKind storageKind;
948
942
949
943
// / Whether there is a trailing written requirement location.
950
- const bool hasTrailingWrittenRequirementLoc ;
944
+ const bool hasTrailingSourceLoc ;
951
945
952
946
private:
953
947
// / The actual storage, described by \c storageKind.
@@ -987,8 +981,8 @@ class GenericSignatureBuilder::RequirementSource final
987
981
}
988
982
989
983
// / The trailing written requirement location, if there is one.
990
- size_t numTrailingObjects (OverloadToken<WrittenRequirementLoc >) const {
991
- return hasTrailingWrittenRequirementLoc ? 1 : 0 ;
984
+ size_t numTrailingObjects (OverloadToken<SourceLoc >) const {
985
+ return hasTrailingSourceLoc ? 1 : 0 ;
992
986
}
993
987
994
988
#ifndef NDEBUG
@@ -1039,25 +1033,25 @@ class GenericSignatureBuilder::RequirementSource final
1039
1033
1040
1034
RequirementSource (Kind kind, Type rootType,
1041
1035
ProtocolDecl *protocol,
1042
- WrittenRequirementLoc writtenReqLoc)
1036
+ SourceLoc writtenReqLoc)
1043
1037
: kind(kind), storageKind(StorageKind::StoredType),
1044
- hasTrailingWrittenRequirementLoc (! writtenReqLoc.isNull ()),
1038
+ hasTrailingSourceLoc ( writtenReqLoc.isValid ()),
1045
1039
parent(nullptr ) {
1046
1040
assert (isAcceptableStorageKind (kind, storageKind) &&
1047
1041
" RequirementSource kind/storageKind mismatch" );
1048
1042
1049
1043
storage.type = rootType.getPointer ();
1050
1044
if (kind == RequirementSignatureSelf)
1051
1045
getTrailingObjects<ProtocolDecl *>()[0 ] = protocol;
1052
- if (hasTrailingWrittenRequirementLoc )
1053
- getTrailingObjects<WrittenRequirementLoc >()[0 ] = writtenReqLoc;
1046
+ if (hasTrailingSourceLoc )
1047
+ getTrailingObjects<SourceLoc >()[0 ] = writtenReqLoc;
1054
1048
}
1055
1049
1056
1050
RequirementSource (Kind kind, const RequirementSource *parent,
1057
1051
Type type, ProtocolDecl *protocol,
1058
- WrittenRequirementLoc writtenReqLoc)
1052
+ SourceLoc writtenReqLoc)
1059
1053
: kind(kind), storageKind(StorageKind::StoredType),
1060
- hasTrailingWrittenRequirementLoc(! writtenReqLoc.isNull ()),
1054
+ hasTrailingSourceLoc( writtenReqLoc.isValid ()),
1061
1055
parent(parent) {
1062
1056
assert ((static_cast <bool >(parent) != isRootKind (kind)) &&
1063
1057
" Root RequirementSource should not have parent (or vice versa)" );
@@ -1067,14 +1061,14 @@ class GenericSignatureBuilder::RequirementSource final
1067
1061
storage.type = type.getPointer ();
1068
1062
if (isProtocolRequirement ())
1069
1063
getTrailingObjects<ProtocolDecl *>()[0 ] = protocol;
1070
- if (hasTrailingWrittenRequirementLoc )
1071
- getTrailingObjects<WrittenRequirementLoc >()[0 ] = writtenReqLoc;
1064
+ if (hasTrailingSourceLoc )
1065
+ getTrailingObjects<SourceLoc >()[0 ] = writtenReqLoc;
1072
1066
}
1073
1067
1074
1068
RequirementSource (Kind kind, const RequirementSource *parent,
1075
1069
ProtocolConformanceRef conformance)
1076
1070
: kind(kind), storageKind(StorageKind::ProtocolConformance),
1077
- hasTrailingWrittenRequirementLoc (false ), parent(parent) {
1071
+ hasTrailingSourceLoc (false ), parent(parent) {
1078
1072
assert ((static_cast <bool >(parent) != isRootKind (kind)) &&
1079
1073
" Root RequirementSource should not have parent (or vice versa)" );
1080
1074
assert (isAcceptableStorageKind (kind, storageKind) &&
@@ -1086,7 +1080,7 @@ class GenericSignatureBuilder::RequirementSource final
1086
1080
RequirementSource (Kind kind, const RequirementSource *parent,
1087
1081
AssociatedTypeDecl *assocType)
1088
1082
: kind(kind), storageKind(StorageKind::AssociatedTypeDecl),
1089
- hasTrailingWrittenRequirementLoc (false ), parent(parent) {
1083
+ hasTrailingSourceLoc (false ), parent(parent) {
1090
1084
assert ((static_cast <bool >(parent) != isRootKind (kind)) &&
1091
1085
" Root RequirementSource should not have parent (or vice versa)" );
1092
1086
assert (isAcceptableStorageKind (kind, storageKind) &&
@@ -1097,7 +1091,7 @@ class GenericSignatureBuilder::RequirementSource final
1097
1091
1098
1092
RequirementSource (Kind kind, const RequirementSource *parent)
1099
1093
: kind(kind), storageKind(StorageKind::None),
1100
- hasTrailingWrittenRequirementLoc (false ), parent(parent) {
1094
+ hasTrailingSourceLoc (false ), parent(parent) {
1101
1095
assert ((static_cast <bool >(parent) != isRootKind (kind)) &&
1102
1096
" Root RequirementSource should not have parent (or vice versa)" );
1103
1097
assert (isAcceptableStorageKind (kind, storageKind) &&
@@ -1107,7 +1101,7 @@ class GenericSignatureBuilder::RequirementSource final
1107
1101
RequirementSource (Kind kind, const RequirementSource *parent,
1108
1102
Type newType)
1109
1103
: kind(kind), storageKind(StorageKind::StoredType),
1110
- hasTrailingWrittenRequirementLoc (false ), parent(parent) {
1104
+ hasTrailingSourceLoc (false ), parent(parent) {
1111
1105
assert ((static_cast <bool >(parent) != isRootKind (kind)) &&
1112
1106
" Root RequirementSource should not have parent (or vice versa)" );
1113
1107
assert (isAcceptableStorageKind (kind, storageKind) &&
@@ -1124,14 +1118,14 @@ class GenericSignatureBuilder::RequirementSource final
1124
1118
// / stated in an 'inheritance' or 'where' clause.
1125
1119
static const RequirementSource *forExplicit (GenericSignatureBuilder &builder,
1126
1120
Type rootType,
1127
- WrittenRequirementLoc writtenLoc);
1121
+ SourceLoc writtenLoc);
1128
1122
1129
1123
// / Retrieve a requirement source representing a requirement that is
1130
1124
// / inferred from some part of a generic declaration's signature, e.g., the
1131
1125
// / parameter or result type of a generic function.
1132
1126
static const RequirementSource *forInferred (GenericSignatureBuilder &builder,
1133
1127
Type rootType,
1134
- const TypeRepr *typeRepr );
1128
+ SourceLoc writtenLoc );
1135
1129
1136
1130
// / Retrieve a requirement source representing the requirement signature
1137
1131
// / computation for a protocol.
@@ -1153,8 +1147,8 @@ class GenericSignatureBuilder::RequirementSource final
1153
1147
Type dependentType,
1154
1148
ProtocolDecl *protocol,
1155
1149
bool inferred,
1156
- WrittenRequirementLoc writtenLoc =
1157
- WrittenRequirementLoc ()) const ;
1150
+ SourceLoc writtenLoc =
1151
+ SourceLoc ()) const ;
1158
1152
public:
1159
1153
// / A requirement source that describes a conformance requirement resolved
1160
1154
// / via a superclass requirement.
@@ -1287,20 +1281,9 @@ class GenericSignatureBuilder::RequirementSource final
1287
1281
int compare (const RequirementSource *other) const ;
1288
1282
1289
1283
// / Retrieve the written requirement location, if there is one.
1290
- WrittenRequirementLoc getWrittenRequirementLoc () const {
1291
- if (!hasTrailingWrittenRequirementLoc) return WrittenRequirementLoc ();
1292
- return getTrailingObjects<WrittenRequirementLoc>()[0 ];
1293
- }
1294
-
1295
- // / Retrieve the type representation for this requirement, if there is one.
1296
- const TypeRepr *getTypeRepr () const {
1297
- return getWrittenRequirementLoc ().dyn_cast <const TypeRepr *>();
1298
- }
1299
-
1300
- // / Retrieve the requirement representation for this requirement, if there is
1301
- // / one.
1302
- const RequirementRepr *getRequirementRepr () const {
1303
- return getWrittenRequirementLoc ().dyn_cast <const RequirementRepr *>();
1284
+ SourceLoc getSourceLoc () const {
1285
+ if (!hasTrailingSourceLoc) return SourceLoc ();
1286
+ return getTrailingObjects<SourceLoc>()[0 ];
1304
1287
}
1305
1288
1306
1289
// / Retrieve the type stored in this requirement.
@@ -1354,88 +1337,82 @@ class GenericSignatureBuilder::RequirementSource final
1354
1337
// / The root will be supplied as soon as the appropriate dependent type is
1355
1338
// / resolved.
1356
1339
class GenericSignatureBuilder ::FloatingRequirementSource {
1357
- enum Kind {
1340
+ enum Kind : uint8_t {
1358
1341
// / A fully-resolved requirement source, which does not need a root.
1359
1342
Resolved,
1360
- // / An explicit requirement source lacking a root .
1343
+ // / An explicit requirement in a generic signature .
1361
1344
Explicit,
1362
- // / An inferred requirement source lacking a root.
1345
+ // / A requirement inferred from a concrete type application in a
1346
+ // / generic signature.
1363
1347
Inferred,
1364
- // / A requirement source augmented by an abstract protocol requirement
1365
- AbstractProtocol,
1348
+ // / An explicit requirement written inside a protocol.
1349
+ ProtocolRequirement,
1350
+ // / A requirement inferred from a concrete type application inside a
1351
+ // / protocol.
1352
+ InferredProtocolRequirement,
1366
1353
// / A requirement source for a nested-type-name match introduced by
1367
1354
// / the given source.
1368
1355
NestedTypeNameMatch,
1369
1356
} kind;
1370
1357
1371
- using Storage =
1372
- llvm::PointerUnion<const RequirementSource *, const TypeRepr *,
1373
- const RequirementRepr *>;
1374
-
1375
- Storage storage;
1358
+ const RequirementSource *source;
1359
+ SourceLoc loc;
1376
1360
1377
1361
// Additional storage for an abstract protocol requirement.
1378
1362
union {
1379
- struct {
1380
- ProtocolDecl *protocol = nullptr ;
1381
- WrittenRequirementLoc written;
1382
- bool inferred = false ;
1383
- } protocolReq;
1384
-
1363
+ ProtocolDecl *protocol = nullptr ;
1385
1364
Identifier nestedName;
1386
1365
};
1387
1366
1388
- FloatingRequirementSource (Kind kind, Storage storage )
1389
- : kind(kind), storage(storage ) { }
1367
+ FloatingRequirementSource (Kind kind, const RequirementSource *source )
1368
+ : kind(kind), source(source ) { }
1390
1369
1391
1370
public:
1392
1371
// / Implicit conversion from a resolved requirement source.
1393
1372
FloatingRequirementSource (const RequirementSource *source)
1394
1373
: FloatingRequirementSource(Resolved, source) { }
1395
1374
1396
1375
static FloatingRequirementSource forAbstract () {
1397
- return { Explicit, Storage () };
1398
- }
1399
-
1400
- static FloatingRequirementSource forExplicit (const TypeRepr *typeRepr) {
1401
- return { Explicit, typeRepr };
1376
+ return { Explicit, nullptr };
1402
1377
}
1403
1378
1404
- static FloatingRequirementSource forExplicit (
1405
- const RequirementRepr *requirementRepr) {
1406
- return { Explicit, requirementRepr };
1379
+ static FloatingRequirementSource forExplicit (SourceLoc loc) {
1380
+ FloatingRequirementSource result{ Explicit, nullptr };
1381
+ result.loc = loc;
1382
+ return result;
1407
1383
}
1408
1384
1409
- static FloatingRequirementSource forInferred (const TypeRepr *typeRepr) {
1410
- return { Inferred, typeRepr };
1385
+ static FloatingRequirementSource forInferred (SourceLoc loc) {
1386
+ FloatingRequirementSource result{ Inferred, nullptr };
1387
+ result.loc = loc;
1388
+ return result;
1411
1389
}
1412
1390
1413
1391
static FloatingRequirementSource viaProtocolRequirement (
1414
1392
const RequirementSource *base,
1415
1393
ProtocolDecl *inProtocol,
1416
1394
bool inferred) {
1417
- FloatingRequirementSource result{ AbstractProtocol, base };
1418
- result.protocolReq .protocol = inProtocol;
1419
- result.protocolReq .written = WrittenRequirementLoc ();
1420
- result.protocolReq .inferred = inferred;
1395
+ auto kind = (inferred ? InferredProtocolRequirement : ProtocolRequirement);
1396
+ FloatingRequirementSource result{ kind, base };
1397
+ result.protocol = inProtocol;
1421
1398
return result;
1422
1399
}
1423
1400
1424
1401
static FloatingRequirementSource viaProtocolRequirement (
1425
1402
const RequirementSource *base,
1426
1403
ProtocolDecl *inProtocol,
1427
- WrittenRequirementLoc written,
1404
+ SourceLoc written,
1428
1405
bool inferred) {
1429
- FloatingRequirementSource result{ AbstractProtocol, base } ;
1430
- result. protocolReq . protocol = inProtocol ;
1431
- result.protocolReq . written = written ;
1432
- result.protocolReq . inferred = inferred ;
1406
+ auto kind = (inferred ? InferredProtocolRequirement : ProtocolRequirement) ;
1407
+ FloatingRequirementSource result{ kind, base } ;
1408
+ result.protocol = inProtocol ;
1409
+ result.loc = written ;
1433
1410
return result;
1434
1411
}
1435
1412
1436
1413
static FloatingRequirementSource forNestedTypeNameMatch (
1437
1414
Identifier nestedName) {
1438
- FloatingRequirementSource result{ NestedTypeNameMatch, Storage () };
1415
+ FloatingRequirementSource result{ NestedTypeNameMatch, nullptr };
1439
1416
result.nestedName = nestedName;
1440
1417
return result;
1441
1418
};
0 commit comments