Skip to content

Commit dec05e1

Browse files
committed
Sema: Simplify substMemberTypeWithBase()
The isTypeReference parameter is now always true, so change the function to just take a TypeDecl.
1 parent 0bc3dec commit dec05e1

File tree

4 files changed

+20
-28
lines changed

4 files changed

+20
-28
lines changed

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ Type CompleteGenericTypeResolver::resolveDependentMemberType(
206206
// concrete type, or resolve its components down to another dependent member.
207207
if (auto alias = nestedPA->getTypeAliasDecl()) {
208208
return TC.substMemberTypeWithBase(DC->getParentModule(), alias,
209-
baseTy, true);
209+
baseTy);
210210
}
211211

212212
Identifier name = ref->getIdentifier();

lib/Sema/TypeCheckNameLookup.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,7 @@ LookupTypeResult TypeChecker::lookupMemberType(DeclContext *dc,
369369

370370
// Substitute the base into the member's type.
371371
auto memberType = substMemberTypeWithBase(dc->getParentModule(),
372-
typeDecl, type,
373-
/*isTypeReference=*/true);
372+
typeDecl, type);
374373

375374
// FIXME: It is not clear why this substitution can fail, but the
376375
// standard library won't build without this check.

lib/Sema/TypeCheckType.cpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ Type TypeChecker::resolveTypeInContext(
337337
}
338338

339339
return substMemberTypeWithBase(parentDC->getParentModule(), typeDecl,
340-
fromType, /*isTypeReference=*/true);
340+
fromType);
341341
}
342342
}
343343

@@ -378,7 +378,7 @@ Type TypeChecker::resolveTypeInContext(
378378
}
379379

380380
return substMemberTypeWithBase(parentDC->getParentModule(), typeDecl,
381-
fromType, /*isTypeReference=*/true);
381+
fromType);
382382
}
383383

384384
if (auto superclassTy = getSuperClassOf(fromType))
@@ -1142,8 +1142,7 @@ static Type resolveNestedIdentTypeComponent(
11421142

11431143
// Otherwise, simply substitute the parent type into the member.
11441144
memberType = TC.substMemberTypeWithBase(DC->getParentModule(), typeDecl,
1145-
parentTy,
1146-
/*isTypeReference=*/true);
1145+
parentTy);
11471146

11481147
// Propagate failure.
11491148
if (!memberType || memberType->hasError()) return memberType;
@@ -2797,21 +2796,18 @@ Type TypeResolver::buildProtocolType(
27972796
}
27982797

27992798
Type TypeChecker::substMemberTypeWithBase(Module *module,
2800-
const ValueDecl *member,
2801-
Type baseTy, bool isTypeReference) {
2802-
Type memberType = isTypeReference
2803-
? cast<TypeDecl>(member)->getDeclaredInterfaceType()
2804-
: member->getInterfaceType();
2805-
if (isTypeReference) {
2806-
// The declared interface type for a generic type will have the type
2807-
// arguments; strip them off.
2808-
if (auto nominalTypeDecl = dyn_cast<NominalTypeDecl>(member)) {
2809-
if (auto boundGenericTy = memberType->getAs<BoundGenericType>()) {
2810-
memberType = UnboundGenericType::get(
2811-
const_cast<NominalTypeDecl *>(nominalTypeDecl),
2812-
boundGenericTy->getParent(),
2813-
Context);
2814-
}
2799+
const TypeDecl *member,
2800+
Type baseTy) {
2801+
Type memberType = member->getDeclaredInterfaceType();
2802+
2803+
// The declared interface type for a generic type will have the type
2804+
// arguments; strip them off.
2805+
if (auto nominalTypeDecl = dyn_cast<NominalTypeDecl>(member)) {
2806+
if (auto boundGenericTy = memberType->getAs<BoundGenericType>()) {
2807+
memberType = UnboundGenericType::get(
2808+
const_cast<NominalTypeDecl *>(nominalTypeDecl),
2809+
boundGenericTy->getParent(),
2810+
Context);
28152811
}
28162812
}
28172813

lib/Sema/TypeChecker.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -855,17 +855,14 @@ class TypeChecker final : public LazyResolver {
855855
bool isGenericSignature,
856856
GenericTypeResolver *resolver);
857857

858-
/// \brief Substitute the given base type into the type of the given member,
859-
/// producing the effective type that the member will have.
858+
/// \brief Substitute the given base type into the type of the given nested type,
859+
/// producing the effective type that the nested type will have.
860860
///
861861
/// \param module The module in which the substitution will be performed.
862862
/// \param member The member whose type projection is being computed.
863863
/// \param baseTy The base type that will be substituted for the 'Self' of the
864864
/// member.
865-
/// \param isTypeReference Whether this is a reference to a type declaration
866-
/// within a type context.
867-
Type substMemberTypeWithBase(Module *module, const ValueDecl *member,
868-
Type baseTy, bool isTypeReference);
865+
Type substMemberTypeWithBase(Module *module, const TypeDecl *member, Type baseTy);
869866

870867
/// \brief Retrieve the superclass type of the given type, or a null type if
871868
/// the type has no supertype.

0 commit comments

Comments
 (0)