Skip to content

Commit ce70083

Browse files
committed
GSB: Clean up resolveDeclSignature() calls
1 parent 7bab318 commit ce70083

File tree

1 file changed

+19
-46
lines changed

1 file changed

+19
-46
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,13 +2084,6 @@ TypeDecl *EquivalenceClass::lookupNestedType(
20842084
foundMembers);
20852085
for (auto member : foundMembers) {
20862086
if (auto type = dyn_cast<TypeDecl>(member)) {
2087-
// Resolve the signature of this type.
2088-
if (!type->hasInterfaceType()) {
2089-
type->getASTContext().getLazyResolver()->resolveDeclSignature(type);
2090-
if (!type->hasInterfaceType())
2091-
continue;
2092-
}
2093-
20942087
concreteDecls.push_back(type);
20952088
}
20962089
}
@@ -3812,25 +3805,31 @@ PotentialArchetype *GenericSignatureBuilder::realizePotentialArchetype(
38123805
return pa;
38133806
}
38143807

3808+
static Type getStructuralType(TypeDecl *typeDecl, LazyResolver *resolver) {
3809+
if (auto typealias = dyn_cast<TypeAliasDecl>(typeDecl)) {
3810+
// Resolve the underlying type, if we haven't done so yet.
3811+
if (!typealias->hasInterfaceType())
3812+
resolver->resolveDeclSignature(typealias);
3813+
3814+
return typealias->getUnderlyingTypeLoc().getType();
3815+
}
3816+
3817+
return typeDecl->getDeclaredInterfaceType();
3818+
}
3819+
38153820
static Type substituteConcreteType(GenericSignatureBuilder &builder,
38163821
PotentialArchetype *basePA,
38173822
TypeDecl *concreteDecl) {
38183823
assert(concreteDecl);
38193824

38203825
auto *proto = concreteDecl->getDeclContext()->getSelfProtocolDecl();
38213826

3822-
if (!concreteDecl->hasInterfaceType())
3823-
builder.getLazyResolver()->resolveDeclSignature(concreteDecl);
3824-
3825-
if (!concreteDecl->hasInterfaceType())
3827+
// Form an unsubstituted type referring to the given type declaration,
3828+
// for use in an inferred same-type requirement.
3829+
auto type = getStructuralType(concreteDecl, builder.getLazyResolver());
3830+
if (!type)
38263831
return Type();
38273832

3828-
// The protocol concrete type has an underlying type written in terms
3829-
// of the protocol's 'Self' type.
3830-
auto typealias = dyn_cast<TypeAliasDecl>(concreteDecl);
3831-
auto type = typealias ? typealias->getUnderlyingTypeLoc().getType()
3832-
: concreteDecl->getDeclaredInterfaceType();
3833-
38343833
Type parentType;
38353834
SubstitutionMap subMap;
38363835
if (proto) {
@@ -3855,7 +3854,7 @@ static Type substituteConcreteType(GenericSignatureBuilder &builder,
38553854
}
38563855

38573856
// If we had a typealias, form a sugared type.
3858-
if (typealias) {
3857+
if (auto *typealias = dyn_cast<TypeAliasDecl>(concreteDecl)) {
38593858
type = TypeAliasType::get(typealias, parentType, subMap, type);
38603859
}
38613860

@@ -4226,34 +4225,13 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
42264225
return result;
42274226
};
42284227

4229-
// Form an unsubstituted type referring to the given type declaration,
4230-
// for use in an inferred same-type requirement.
4231-
auto formUnsubstitutedType = [&](TypeDecl *typeDecl) -> Type {
4232-
if (auto assocType = dyn_cast<AssociatedTypeDecl>(typeDecl)) {
4233-
return DependentMemberType::get(
4234-
assocType->getProtocol()->getSelfInterfaceType(),
4235-
assocType);
4236-
}
4237-
4238-
// Resolve the underlying type, if we haven't done so yet.
4239-
if (!typeDecl->hasInterfaceType()) {
4240-
getLazyResolver()->resolveDeclSignature(typeDecl);
4241-
}
4242-
4243-
if (auto typealias = dyn_cast<TypeAliasDecl>(typeDecl)) {
4244-
return typealias->getUnderlyingTypeLoc().getType();
4245-
}
4246-
4247-
return typeDecl->getDeclaredInterfaceType();
4248-
};
4249-
42504228
// An inferred same-type requirement between the two type declarations
42514229
// within this protocol or a protocol it inherits.
42524230
auto addInferredSameTypeReq = [&](TypeDecl *first, TypeDecl *second) {
4253-
Type firstType = formUnsubstitutedType(first);
4231+
Type firstType = getStructuralType(first, getLazyResolver());
42544232
if (!firstType) return;
42554233

4256-
Type secondType = formUnsubstitutedType(second);
4234+
Type secondType = getStructuralType(second, getLazyResolver());
42574235
if (!secondType) return;
42584236

42594237
auto inferredSameTypeSource =
@@ -5170,11 +5148,6 @@ ConstraintResult GenericSignatureBuilder::addInheritedRequirements(
51705148
UnresolvedType type,
51715149
const RequirementSource *parentSource,
51725150
ModuleDecl *inferForModule) {
5173-
if (isa<AssociatedTypeDecl>(decl) &&
5174-
decl->hasInterfaceType() &&
5175-
decl->getInterfaceType()->is<ErrorType>())
5176-
return ConstraintResult::Resolved;
5177-
51785151
// Local function to get the source.
51795152
auto getFloatingSource = [&](const TypeRepr *typeRepr, bool forInferred) {
51805153
if (parentSource) {

0 commit comments

Comments
 (0)