Skip to content

Commit 5980b32

Browse files
authored
Merge pull request #36577 from slavapestov/gsb-explicit-requirement-list
GSB: Introduce a list of explicit as-written requirements
2 parents a3f4407 + 1fe4092 commit 5980b32

File tree

5 files changed

+336
-243
lines changed

5 files changed

+336
-243
lines changed

include/swift/AST/GenericSignature.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,6 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
362362
/// Return the canonical version of the given type under this generic
363363
/// signature.
364364
CanType getCanonicalTypeInContext(Type type) const;
365-
CanType getCanonicalTypeInContext(Type type,
366-
GenericSignatureBuilder &builder) const;
367365

368366
bool isCanonicalTypeInContext(Type type) const;
369367
bool isCanonicalTypeInContext(Type type,

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ class GenericSignatureBuilder {
270270
struct CachedNestedType {
271271
unsigned numConformancesPresent;
272272
CanType superclassPresent;
273+
CanType concreteTypePresent;
273274
llvm::TinyPtrVector<TypeDecl *> types;
274275
};
275276

@@ -793,6 +794,13 @@ class GenericSignatureBuilder {
793794
/// Simplify the given dependent type down to its canonical representation.
794795
Type getCanonicalTypeParameter(Type type);
795796

797+
/// Replace any non-canonical dependent types in the given type with their
798+
/// canonical representation. This is not a canonical type in the AST sense;
799+
/// type sugar is preserved. The GenericSignature::getCanonicalTypeInContext()
800+
/// method combines this with a subsequent getCanonicalType() call.
801+
Type getCanonicalTypeInContext(Type type,
802+
TypeArrayView<GenericTypeParamType> genericParams);
803+
796804
/// Verify the correctness of the given generic signature.
797805
///
798806
/// This routine will test that the given generic signature is both minimal

lib/AST/GenericSignature.cpp

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -557,47 +557,6 @@ bool GenericSignatureImpl::isCanonicalTypeInContext(
557557
});
558558
}
559559

560-
CanType GenericSignatureImpl::getCanonicalTypeInContext(
561-
Type type, GenericSignatureBuilder &builder) const {
562-
type = type->getCanonicalType();
563-
564-
// All the contextual canonicality rules apply to type parameters, so if the
565-
// type doesn't involve any type parameters, it's already canonical.
566-
if (!type->hasTypeParameter())
567-
return CanType(type);
568-
569-
// Replace non-canonical type parameters.
570-
type = type.transformRec([&](TypeBase *component) -> Optional<Type> {
571-
if (!isa<GenericTypeParamType>(component) &&
572-
!isa<DependentMemberType>(component))
573-
return None;
574-
575-
// Find the equivalence class for this dependent type.
576-
auto resolved = builder.maybeResolveEquivalenceClass(
577-
Type(component),
578-
ArchetypeResolutionKind::CompleteWellFormed,
579-
/*wantExactPotentialArchetype=*/false);
580-
if (!resolved) return None;
581-
582-
if (auto concrete = resolved.getAsConcreteType())
583-
return getCanonicalTypeInContext(concrete, builder);
584-
585-
auto equivClass = resolved.getEquivalenceClass(builder);
586-
if (!equivClass) return None;
587-
588-
if (equivClass->concreteType) {
589-
return getCanonicalTypeInContext(equivClass->concreteType, builder);
590-
}
591-
592-
return equivClass->getAnchor(builder, getGenericParams());
593-
});
594-
595-
auto result = type->getCanonicalType();
596-
597-
assert(isCanonicalTypeInContext(result, builder));
598-
return result;
599-
}
600-
601560
CanType GenericSignatureImpl::getCanonicalTypeInContext(Type type) const {
602561
type = type->getCanonicalType();
603562

@@ -607,7 +566,7 @@ CanType GenericSignatureImpl::getCanonicalTypeInContext(Type type) const {
607566
return CanType(type);
608567

609568
auto &builder = *getGenericSignatureBuilder();
610-
return getCanonicalTypeInContext(type, builder);
569+
return builder.getCanonicalTypeInContext(type, { })->getCanonicalType();
611570
}
612571

613572
ArrayRef<CanTypeWrapper<GenericTypeParamType>>

0 commit comments

Comments
 (0)