Skip to content

Commit 2a4c8dc

Browse files
authored
Merge pull request #7581 from DougGregor/generic-sig-builder-inheritance-cleanup
[GenericSigBuilder] Clean up handling of "inheritance" clauses.
2 parents be3f74e + d017fe3 commit 2a4c8dc

File tree

5 files changed

+153
-109
lines changed

5 files changed

+153
-109
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,8 +1563,8 @@ ERROR(requires_generic_param_made_equal_to_concrete,none,
15631563
"same-type requirement makes generic parameter %0 non-generic",
15641564
(Type))
15651565
ERROR(requires_superclass_conflict,none,
1566-
"generic parameter %0 cannot be a subclass of both %1 and %2",
1567-
(Type, Type, Type))
1566+
"%select{generic parameter |protocol |}0%1 cannot be a subclass of both "
1567+
"%2 and %3", (unsigned, Type, Type, Type))
15681568
ERROR(recursive_type_reference,none,
15691569
"%0 %1 references itself", (DescriptiveDeclKind, Identifier))
15701570
ERROR(recursive_requirement_reference,none,

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class RequirementSource : public llvm::FoldingSetNode {
139139
/// The actual storage, described by \c storageKind.
140140
union {
141141
/// The type representation descibing where the requirement came from.
142-
TypeRepr *typeRepr;
142+
const TypeRepr *typeRepr;
143143

144144
/// Where a requirement came from.
145145
const RequirementRepr *requirementRepr;
@@ -194,7 +194,7 @@ class RequirementSource : public llvm::FoldingSetNode {
194194
}
195195

196196
RequirementSource(Kind kind, const RequirementSource *parent,
197-
TypeRepr *typeRepr)
197+
const TypeRepr *typeRepr)
198198
: kind(kind), storageKind(StorageKind::TypeRepr), parent(parent) {
199199
assert((static_cast<bool>(parent) != isRootKind(kind)) &&
200200
"Root RequirementSource should not have parent (or vice versa)");
@@ -245,7 +245,7 @@ class RequirementSource : public llvm::FoldingSetNode {
245245
/// Retrieve a requirement source representing an explicit requirement
246246
/// stated in an 'inheritance' clause.
247247
static const RequirementSource *forExplicit(GenericSignatureBuilder &builder,
248-
TypeRepr *typeRepr);
248+
const TypeRepr *typeRepr);
249249

250250
/// Retrieve a requirement source representing an explicit requirement
251251
/// stated in an 'where' clause.
@@ -256,7 +256,7 @@ class RequirementSource : public llvm::FoldingSetNode {
256256
/// inferred from some part of a generic declaration's signature, e.g., the
257257
/// parameter or result type of a generic function.
258258
static const RequirementSource *forInferred(GenericSignatureBuilder &builder,
259-
TypeRepr *typeRepr);
259+
const TypeRepr *typeRepr);
260260

261261
/// Retrieve a requirement source representing the requirement signature
262262
/// computation for a protocol.
@@ -307,7 +307,7 @@ class RequirementSource : public llvm::FoldingSetNode {
307307
int compare(const RequirementSource *other) const;
308308

309309
/// Retrieve the type representation for this requirement, if there is one.
310-
TypeRepr *getTypeRepr() const {
310+
const TypeRepr *getTypeRepr() const {
311311
if (storageKind != StorageKind::TypeRepr) return nullptr;
312312
return storage.typeRepr;
313313
}
@@ -447,20 +447,11 @@ class GenericSignatureBuilder {
447447
Type T1, Type T2, const RequirementSource *Source,
448448
llvm::function_ref<void(Type, Type)> diagnoseMismatch);
449449

450-
/// Add the requirements placed on the given abstract type parameter
450+
/// Add the requirements placed on the given type parameter
451451
/// to the given potential archetype.
452-
bool addAbstractTypeParamRequirements(
453-
AbstractTypeParamDecl *decl,
454-
PotentialArchetype *pa,
455-
const RequirementSource *source,
456-
llvm::SmallPtrSetImpl<ProtocolDecl *> &visited);
457-
458-
/// Visit all of the types that show up in the list of inherited
459-
/// types.
460-
///
461-
/// \returns true if any of the invocations of \c visitor returned true.
462-
bool visitInherited(ArrayRef<TypeLoc> inheritedTypes,
463-
llvm::function_ref<bool(Type, SourceLoc)> visitor);
452+
bool addInheritedRequirements(TypeDecl *decl, PotentialArchetype *pa,
453+
const RequirementSource *parentSource,
454+
llvm::SmallPtrSetImpl<ProtocolDecl *> &visited);
464455

465456
/// Visit all of the potential archetypes.
466457
template<typename F>

0 commit comments

Comments
 (0)