Skip to content

Commit 361d49a

Browse files
committed
AST: Remove DeclContext::getSelfProtocolType()
1 parent f374813 commit 361d49a

15 files changed

+31
-51
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5128,6 +5128,10 @@ class ProtocolDecl final : public NominalTypeDecl {
51285128
/// view of the generic system; see RequirementSignature.h for details.
51295129
RequirementSignature getRequirementSignature() const;
51305130

5131+
/// Sometimes we want to make a fake generic signature from the requirements
5132+
/// of a requirement signature.
5133+
GenericSignature getRequirementSignatureAsGenericSignature() const;
5134+
51315135
/// Is the requirement signature currently being computed?
51325136
bool isComputingRequirementSignature() const;
51335137

include/swift/AST/DeclContext.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,6 @@ class alignas(1 << DeclContextAlignInBits) DeclContext
392392
LLVM_READONLY
393393
VarDecl *getNonLocalVarDecl() const;
394394

395-
/// Retrieve the generic parameter 'Self' from a protocol or
396-
/// protocol extension.
397-
///
398-
/// Only valid if \c getSelfProtocolDecl().
399-
GenericTypeParamType *getProtocolSelfType() const;
400-
401395
/// Gets the type being declared by this context.
402396
///
403397
/// - Generic types return a bound generic type using archetypes.

lib/AST/ASTDumper.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -679,9 +679,8 @@ namespace {
679679

680680
OS << " requirement signature=";
681681
if (PD->isRequirementSignatureComputed()) {
682-
auto requirements = PD->getRequirementSignature().getRequirements();
683-
OS << GenericSignature::get({PD->getProtocolSelfType()}, requirements)
684-
->getAsString();
682+
auto requirements = PD->getRequirementSignatureAsGenericSignature();
683+
OS << requirements->getAsString();
685684
} else {
686685
OS << "<null>";
687686
}

lib/AST/ASTMangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3649,7 +3649,7 @@ void ASTMangler::appendDependentProtocolConformance(
36493649

36503650
// Inherited conformance.
36513651
bool isInheritedConformance =
3652-
entry.first->isEqual(currentProtocol->getProtocolSelfType());
3652+
entry.first->isEqual(currentProtocol->getSelfInterfaceType());
36533653
if (isInheritedConformance) {
36543654
appendProtocolName(entry.second);
36553655
// For now, this is never an unknown index and so must be adjusted by 2.

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,7 @@ struct RequirementPrintLocation {
14441444
/// callers check if the location is the ATD.
14451445
static RequirementPrintLocation
14461446
bestRequirementPrintLocation(ProtocolDecl *proto, const Requirement &req) {
1447-
auto protoSelf = proto->getProtocolSelfType();
1447+
auto protoSelf = proto->getSelfInterfaceType();
14481448
// Returns the most relevant decl within proto connected to outerType (or null
14491449
// if one doesn't exist), and whether the type is an "direct use",
14501450
// i.e. outerType itself is Self or Self.T, but not, say, Self.T.U, or
@@ -1535,14 +1535,13 @@ bestRequirementPrintLocation(ProtocolDecl *proto, const Requirement &req) {
15351535
void PrintAST::printInheritedFromRequirementSignature(ProtocolDecl *proto,
15361536
Decl *attachingTo) {
15371537
printGenericSignature(
1538-
GenericSignature::get({proto->getProtocolSelfType()} ,
1539-
proto->getRequirementSignature().getRequirements()),
1538+
proto->getRequirementSignatureAsGenericSignature(),
15401539
PrintInherited,
15411540
[&](const Requirement &req) {
15421541
// Skip the inferred 'Self : AnyObject' constraint if this is an
15431542
// @objc protocol.
15441543
if ((req.getKind() == RequirementKind::Layout) &&
1545-
req.getFirstType()->isEqual(proto->getProtocolSelfType()) &&
1544+
req.getFirstType()->isEqual(proto->getSelfInterfaceType()) &&
15461545
req.getLayoutConstraint()->getKind() ==
15471546
LayoutConstraintKind::Class &&
15481547
proto->isObjC()) {
@@ -1560,8 +1559,7 @@ void PrintAST::printWhereClauseFromRequirementSignature(ProtocolDecl *proto,
15601559
if (isa<AssociatedTypeDecl>(attachingTo))
15611560
flags |= SwapSelfAndDependentMemberType;
15621561
printGenericSignature(
1563-
GenericSignature::get({proto->getProtocolSelfType()} ,
1564-
proto->getRequirementSignature().getRequirements()),
1562+
proto->getRequirementSignatureAsGenericSignature(),
15651563
flags,
15661564
[&](const Requirement &req) {
15671565
auto location = bestRequirementPrintLocation(proto, req);

lib/AST/Decl.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6331,6 +6331,12 @@ RequirementSignature ProtocolDecl::getRequirementSignature() const {
63316331
RequirementSignature());
63326332
}
63336333

6334+
GenericSignature ProtocolDecl::getRequirementSignatureAsGenericSignature() const {
6335+
return GenericSignature::get(
6336+
{getSelfInterfaceType()->castTo<GenericTypeParamType>()},
6337+
getRequirementSignature().getRequirements());
6338+
}
6339+
63346340
bool ProtocolDecl::isComputingRequirementSignature() const {
63356341
return getASTContext().evaluator.hasActiveRequest(
63366342
RequirementSignatureRequest{const_cast<ProtocolDecl*>(this)});
@@ -7895,16 +7901,16 @@ Type DeclContext::getSelfInterfaceType() const {
78957901
if (auto *builtinTupleDecl = dyn_cast<BuiltinTupleDecl>(nominalDecl))
78967902
return builtinTupleDecl->getTupleSelfType();
78977903

7898-
// For a protocol or extension thereof, the type is 'Self'.
78997904
if (isa<ProtocolDecl>(nominalDecl)) {
7900-
auto selfType = getProtocolSelfType();
7901-
if (!selfType)
7902-
return ErrorType::get(getASTContext());
7903-
return selfType;
7905+
auto *genericParams = nominalDecl->getGenericParams();
7906+
return genericParams->getParams().front()
7907+
->getDeclaredInterfaceType();
79047908
}
7909+
7910+
return getDeclaredInterfaceType();
79057911
}
79067912

7907-
return getDeclaredInterfaceType();
7913+
return ErrorType::get(getASTContext());
79087914
}
79097915

79107916
/// Return the full source range of this parameter.

lib/AST/DeclContext.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,6 @@ VarDecl *DeclContext::getNonLocalVarDecl() const {
9595
return nullptr;
9696
}
9797

98-
GenericTypeParamType *DeclContext::getProtocolSelfType() const {
99-
assert(getSelfProtocolDecl() && "not a protocol");
100-
101-
GenericParamList *genericParams;
102-
if (auto proto = dyn_cast<ProtocolDecl>(this)) {
103-
genericParams = proto->getGenericParams();
104-
} else {
105-
genericParams = cast<ExtensionDecl>(this)->getGenericParams();
106-
}
107-
108-
if (genericParams == nullptr)
109-
return nullptr;
110-
111-
return genericParams->getParams().front()
112-
->getDeclaredInterfaceType()
113-
->castTo<GenericTypeParamType>();
114-
}
115-
11698
Type DeclContext::getDeclaredTypeInContext() const {
11799
if (auto declaredType = getDeclaredInterfaceType())
118100
return mapTypeIntoContext(declaredType);

lib/IRGen/GenProto.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,7 @@ void ResilientWitnessTableBuilder::collectResilientWitnesses(
18321832
const auto &witness = entry.getBaseProtocolWitness();
18331833
auto baseProto = witness.Requirement;
18341834
auto proto = SILWT->getProtocol();
1835-
CanType selfType = proto->getProtocolSelfType()->getCanonicalType();
1835+
CanType selfType = proto->getSelfInterfaceType()->getCanonicalType();
18361836
AssociatedConformance requirement(proto, selfType, baseProto);
18371837
ProtocolConformanceRef inheritedConformance =
18381838
ConformanceInContext.getAssociatedConformance(selfType, baseProto);

lib/SILGen/SILGenPoly.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6065,7 +6065,7 @@ getWitnessFunctionType(TypeExpansionContext context, SILGenModule &SGM,
60656065
static std::pair<CanType, ProtocolConformanceRef>
60666066
getSelfTypeAndConformanceForWitness(SILDeclRef witness, SubstitutionMap subs) {
60676067
auto protocol = cast<ProtocolDecl>(witness.getDecl()->getDeclContext());
6068-
auto selfParam = protocol->getProtocolSelfType()->getCanonicalType();
6068+
auto selfParam = protocol->getSelfInterfaceType()->getCanonicalType();
60696069
auto type = subs.getReplacementTypes()[0];
60706070
auto conf = subs.lookupConformance(selfParam, protocol);
60716071
return {type->getCanonicalType(), conf};

lib/SILOptimizer/Utils/Devirtualize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ static bool canDevirtualizeWitnessMethod(ApplySite applySite, bool isMandatory)
12011201
if (!interfaceTy->hasTypeParameter())
12021202
return true;
12031203

1204-
auto *const selfGP = wmi->getLookupProtocol()->getProtocolSelfType();
1204+
auto selfGP = wmi->getLookupProtocol()->getSelfInterfaceType();
12051205
auto isSelfRootedTypeParameter = [selfGP](Type T) -> bool {
12061206
if (!T->hasTypeParameter())
12071207
return false;

0 commit comments

Comments
 (0)