Skip to content

Commit 839063c

Browse files
committed
AST: Remove ProtocolDecl::getSuperclass()/setSuperclass()
1 parent 3626fb0 commit 839063c

File tree

5 files changed

+12
-64
lines changed

5 files changed

+12
-64
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5122,10 +5122,6 @@ class ProtocolDecl final : public NominalTypeDecl {
51225122
/// The superclass decl and a bit to indicate whether the
51235123
/// superclass was computed yet or not.
51245124
llvm::PointerIntPair<ClassDecl *, 1, bool> SuperclassDecl;
5125-
5126-
/// The superclass type and a bit to indicate whether the
5127-
/// superclass was computed yet or not.
5128-
llvm::PointerIntPair<Type, 1, bool> SuperclassType;
51295125
} LazySemanticInfo;
51305126

51315127
/// The generic signature representing exactly the new requirements introduced
@@ -5217,16 +5213,10 @@ class ProtocolDecl final : public NominalTypeDecl {
52175213
/// Determine whether this protocol has a superclass.
52185214
bool hasSuperclass() const { return (bool)getSuperclassDecl(); }
52195215

5220-
/// Retrieve the superclass of this protocol, or null if there is no superclass.
5221-
Type getSuperclass() const;
5222-
52235216
/// Retrieve the ClassDecl for the superclass of this protocol, or null if there
52245217
/// is no superclass.
52255218
ClassDecl *getSuperclassDecl() const;
52265219

5227-
/// Set the superclass of this protocol.
5228-
void setSuperclass(Type superclass);
5229-
52305220
/// Retrieve the set of AssociatedTypeDecl members of this protocol; this
52315221
/// saves loading the set of members in cases where there's no possibility of
52325222
/// a protocol having nested types (ObjC protocols).

include/swift/AST/TypeCheckRequests.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class InheritedTypeRequest
113113
/// Request the superclass type for the given class.
114114
class SuperclassTypeRequest
115115
: public SimpleRequest<
116-
SuperclassTypeRequest, Type(NominalTypeDecl *, TypeResolutionStage),
116+
SuperclassTypeRequest, Type(ClassDecl *, TypeResolutionStage),
117117
RequestFlags::SeparatelyCached | RequestFlags::DependencySink> {
118118
public:
119119
using SimpleRequest::SimpleRequest;
@@ -123,7 +123,7 @@ class SuperclassTypeRequest
123123

124124
// Evaluation.
125125
Type
126-
evaluate(Evaluator &evaluator, NominalTypeDecl *classDecl,
126+
evaluate(Evaluator &evaluator, ClassDecl *classDecl,
127127
TypeResolutionStage stage) const;
128128

129129
public:

lib/AST/Decl.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6545,29 +6545,12 @@ AssociatedTypeDecl *ProtocolDecl::getAssociatedType(Identifier name) const {
65456545
return nullptr;
65466546
}
65476547

6548-
Type ProtocolDecl::getSuperclass() const {
6549-
ASTContext &ctx = getASTContext();
6550-
return evaluateOrDefault(ctx.evaluator,
6551-
SuperclassTypeRequest{const_cast<ProtocolDecl *>(this),
6552-
TypeResolutionStage::Interface},
6553-
Type());
6554-
}
6555-
65566548
ClassDecl *ProtocolDecl::getSuperclassDecl() const {
65576549
ASTContext &ctx = getASTContext();
65586550
return evaluateOrDefault(ctx.evaluator,
65596551
SuperclassDeclRequest{const_cast<ProtocolDecl *>(this)}, nullptr);
65606552
}
65616553

6562-
void ProtocolDecl::setSuperclass(Type superclass) {
6563-
assert((!superclass || !superclass->hasArchetype())
6564-
&& "superclass must be interface type");
6565-
LazySemanticInfo.SuperclassType.setPointerAndInt(superclass, true);
6566-
LazySemanticInfo.SuperclassDecl.setPointerAndInt(
6567-
superclass ? superclass->getClassOrBoundGenericClass() : nullptr,
6568-
true);
6569-
}
6570-
65716554
bool ProtocolDecl::walkInheritedProtocols(
65726555
llvm::function_ref<TypeWalker::Action(ProtocolDecl *)> fn) const {
65736556
auto self = const_cast<ProtocolDecl *>(this);

lib/AST/TypeCheckRequests.cpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,27 +143,16 @@ bool SuperclassTypeRequest::isCached() const {
143143
}
144144

145145
std::optional<Type> SuperclassTypeRequest::getCachedResult() const {
146-
auto nominalDecl = std::get<0>(getStorage());
147-
148-
if (auto *classDecl = dyn_cast<ClassDecl>(nominalDecl))
149-
if (classDecl->LazySemanticInfo.SuperclassType.getInt())
150-
return classDecl->LazySemanticInfo.SuperclassType.getPointer();
151-
152-
if (auto *protocolDecl = dyn_cast<ProtocolDecl>(nominalDecl))
153-
if (protocolDecl->LazySemanticInfo.SuperclassType.getInt())
154-
return protocolDecl->LazySemanticInfo.SuperclassType.getPointer();
146+
auto classDecl = std::get<0>(getStorage());
147+
if (classDecl->LazySemanticInfo.SuperclassType.getInt())
148+
return classDecl->LazySemanticInfo.SuperclassType.getPointer();
155149

156150
return std::nullopt;
157151
}
158152

159153
void SuperclassTypeRequest::cacheResult(Type value) const {
160-
auto nominalDecl = std::get<0>(getStorage());
161-
162-
if (auto *classDecl = dyn_cast<ClassDecl>(nominalDecl))
163-
classDecl->LazySemanticInfo.SuperclassType.setPointerAndInt(value, true);
164-
165-
if (auto *protocolDecl = dyn_cast<ProtocolDecl>(nominalDecl))
166-
protocolDecl->LazySemanticInfo.SuperclassType.setPointerAndInt(value, true);
154+
auto classDecl = std::get<0>(getStorage());
155+
classDecl->LazySemanticInfo.SuperclassType.setPointerAndInt(value, true);
167156
}
168157

169158
void SuperclassTypeRequest::writeDependencySink(

lib/Sema/TypeCheckRequestFunctions.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,28 +84,14 @@ Type InheritedTypeRequest::evaluate(
8484

8585
Type
8686
SuperclassTypeRequest::evaluate(Evaluator &evaluator,
87-
NominalTypeDecl *nominalDecl,
87+
ClassDecl *classDecl,
8888
TypeResolutionStage stage) const {
89-
assert(isa<ClassDecl>(nominalDecl) || isa<ProtocolDecl>(nominalDecl));
90-
91-
// If this is a protocol that came from a serialized module, compute the
92-
// superclass via its generic signature.
93-
if (auto *proto = dyn_cast<ProtocolDecl>(nominalDecl)) {
94-
if (proto->wasDeserialized()) {
95-
return proto->getGenericSignature()
96-
->getSuperclassBound(proto->getSelfInterfaceType());
97-
}
98-
99-
if (!proto->getSuperclassDecl())
100-
return Type();
101-
} else if (auto classDecl = dyn_cast<ClassDecl>(nominalDecl)) {
102-
if (!classDecl->getSuperclassDecl())
103-
return Type();
104-
}
89+
if (!classDecl->getSuperclassDecl())
90+
return Type();
10591

106-
for (unsigned int idx : nominalDecl->getInherited().getIndices()) {
92+
for (unsigned int idx : classDecl->getInherited().getIndices()) {
10793
auto result = evaluateOrDefault(evaluator,
108-
InheritedTypeRequest{nominalDecl, idx, stage},
94+
InheritedTypeRequest{classDecl, idx, stage},
10995
Type());
11096
if (!result)
11197
continue;

0 commit comments

Comments
 (0)