Skip to content

Commit d2f1ded

Browse files
authored
Merge pull request swiftlang#68220 from slavapestov/remove-get-protocol-self-type
Remove DeclContext::getSelfProtocolType()
2 parents d38c93f + 8269bde commit d2f1ded

File tree

17 files changed

+36
-61
lines changed

17 files changed

+36
-61
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: 13 additions & 16 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)});
@@ -7852,16 +7858,7 @@ ParamDecl *ParamDecl::createImplicit(ASTContext &Context,
78527858

78537859
/// Retrieve the type of 'self' for the given context.
78547860
Type DeclContext::getSelfTypeInContext() const {
7855-
assert(isTypeContext());
7856-
7857-
// For a protocol or extension thereof, the type is 'Self'.
7858-
if (getSelfProtocolDecl()) {
7859-
auto selfType = getProtocolSelfType();
7860-
if (!selfType)
7861-
return ErrorType::get(getASTContext());
7862-
return mapTypeIntoContext(selfType);
7863-
}
7864-
return getDeclaredTypeInContext();
7861+
return mapTypeIntoContext(getSelfInterfaceType());
78657862
}
78667863

78677864
TupleType *BuiltinTupleDecl::getTupleSelfType() const {
@@ -7895,16 +7892,16 @@ Type DeclContext::getSelfInterfaceType() const {
78957892
if (auto *builtinTupleDecl = dyn_cast<BuiltinTupleDecl>(nominalDecl))
78967893
return builtinTupleDecl->getTupleSelfType();
78977894

7898-
// For a protocol or extension thereof, the type is 'Self'.
78997895
if (isa<ProtocolDecl>(nominalDecl)) {
7900-
auto selfType = getProtocolSelfType();
7901-
if (!selfType)
7902-
return ErrorType::get(getASTContext());
7903-
return selfType;
7896+
auto *genericParams = nominalDecl->getGenericParams();
7897+
return genericParams->getParams().front()
7898+
->getDeclaredInterfaceType();
79047899
}
7900+
7901+
return getDeclaredInterfaceType();
79057902
}
79067903

7907-
return getDeclaredInterfaceType();
7904+
return ErrorType::get(getASTContext());
79087905
}
79097906

79107907
/// 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/AST/RequirementMachine/Symbol.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const StringRef Symbol::Kinds[] = {
3030
"assocty",
3131
"generic",
3232
"name",
33+
"shape",
3334
"layout",
3435
"super",
3536
"concrete"

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
@@ -6298,7 +6298,7 @@ getWitnessFunctionType(TypeExpansionContext context, SILGenModule &SGM,
62986298
static std::pair<CanType, ProtocolConformanceRef>
62996299
getSelfTypeAndConformanceForWitness(SILDeclRef witness, SubstitutionMap subs) {
63006300
auto protocol = cast<ProtocolDecl>(witness.getDecl()->getDeclContext());
6301-
auto selfParam = protocol->getProtocolSelfType()->getCanonicalType();
6301+
auto selfParam = protocol->getSelfInterfaceType()->getCanonicalType();
63026302
auto type = subs.getReplacementTypes()[0];
63036303
auto conf = subs.lookupConformance(selfParam, protocol);
63046304
return {type->getCanonicalType(), conf};

0 commit comments

Comments
 (0)