Skip to content

Commit 0e4ccb2

Browse files
committed
AST: Remove various references to AbstractTypeParamDecl
1 parent ad06d27 commit 0e4ccb2

File tree

7 files changed

+31
-21
lines changed

7 files changed

+31
-21
lines changed

include/swift/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3503,7 +3503,7 @@ class AssociatedTypeDecl : public AbstractTypeParamDecl {
35033503
/// Retrieve the (first) overridden associated type declaration, if any.
35043504
AssociatedTypeDecl *getOverriddenDecl() const {
35053505
return cast_or_null<AssociatedTypeDecl>(
3506-
AbstractTypeParamDecl::getOverriddenDecl());
3506+
TypeDecl::getOverriddenDecl());
35073507
}
35083508

35093509
/// Retrieve the set of associated types overridden by this associated

lib/AST/ASTWalker.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -275,23 +275,29 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
275275
return false;
276276
}
277277

278-
bool visitAbstractTypeParamDecl(AbstractTypeParamDecl *TPD) {
279-
for (const auto &Inherit: TPD->getInherited()) {
278+
bool visitGenericTypeParamDecl(GenericTypeParamDecl *GTPD) {
279+
for (const auto &Inherit: GTPD->getInherited()) {
280280
if (auto *const TyR = Inherit.getTypeRepr())
281281
if (doIt(TyR))
282282
return true;
283283
}
284+
return false;
285+
}
284286

285-
if (const auto ATD = dyn_cast<AssociatedTypeDecl>(TPD)) {
286-
if (const auto DefaultTy = ATD->getDefaultDefinitionTypeRepr())
287-
if (doIt(DefaultTy))
287+
bool visitAssociatedTypeDecl(AssociatedTypeDecl *ATD) {
288+
for (const auto &Inherit: ATD->getInherited()) {
289+
if (auto *const TyR = Inherit.getTypeRepr())
290+
if (doIt(TyR))
288291
return true;
292+
}
293+
if (const auto DefaultTy = ATD->getDefaultDefinitionTypeRepr())
294+
if (doIt(DefaultTy))
295+
return true;
289296

290-
if (auto *WhereClause = ATD->getTrailingWhereClause()) {
291-
for (auto &Req: WhereClause->getRequirements()) {
292-
if (doIt(Req))
293-
return true;
294-
}
297+
if (auto *WhereClause = ATD->getTrailingWhereClause()) {
298+
for (auto &Req: WhereClause->getRequirements()) {
299+
if (doIt(Req))
300+
return true;
295301
}
296302
}
297303
return false;

lib/AST/Decl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ bool Decl::canHaveComment() const {
547547
return !this->hasClangNode() &&
548548
(isa<ValueDecl>(this) || isa<ExtensionDecl>(this)) &&
549549
!isa<ParamDecl>(this) &&
550-
(!isa<AbstractTypeParamDecl>(this) || isa<AssociatedTypeDecl>(this));
550+
!isa<GenericTypeParamDecl>(this);
551551
}
552552

553553
ModuleDecl *Decl::getModuleContext() const {
@@ -4756,7 +4756,7 @@ AssociatedTypeDecl::getOverriddenDecls() const {
47564756
if (auto cached = request.getCachedResult())
47574757
overridden = std::move(*cached);
47584758
else
4759-
overridden = AbstractTypeParamDecl::getOverriddenDecls();
4759+
overridden = TypeDecl::getOverriddenDecls();
47604760

47614761
llvm::TinyPtrVector<AssociatedTypeDecl *> assocTypes;
47624762
for (auto decl : overridden) {
@@ -4784,7 +4784,7 @@ static AssociatedTypeDecl *getAssociatedTypeAnchor(
47844784
auto anchor = getAssociatedTypeAnchor(assocType, searched);
47854785
if (!anchor)
47864786
continue;
4787-
if (!bestAnchor || AbstractTypeParamDecl::compare(anchor, bestAnchor) < 0)
4787+
if (!bestAnchor || TypeDecl::compare(anchor, bestAnchor) < 0)
47884788
bestAnchor = anchor;
47894789
}
47904790

lib/AST/NameLookup.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2300,7 +2300,8 @@ resolveTypeDeclsToNominal(Evaluator &evaluator,
23002300
}
23012301

23022302
// Make sure we didn't miss some interesting kind of type declaration.
2303-
assert(isa<AbstractTypeParamDecl>(typeDecl));
2303+
assert(isa<GenericTypeParamDecl>(typeDecl) ||
2304+
isa<AssociatedTypeDecl>(typeDecl));
23042305
}
23052306

23062307
return nominalDecls;

lib/IDE/CodeCompletionResultBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ using namespace swift::ide;
2727

2828
static bool shouldCopyAssociatedUSRForDecl(const ValueDecl *VD) {
2929
// Avoid trying to generate a USR for some declaration types.
30-
if (isa<AbstractTypeParamDecl>(VD) && !isa<AssociatedTypeDecl>(VD))
30+
if (isa<GenericTypeParamDecl>(VD))
3131
return false;
3232
if (isa<ParamDecl>(VD))
3333
return false;

lib/PrintAsClang/ModuleContentsWriter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,10 @@ class ModuleWriter {
314314
return;
315315
} else if (auto ED = dyn_cast<EnumDecl>(TD)) {
316316
forwardDeclare(ED);
317-
} else if (isa<AbstractTypeParamDecl>(TD)) {
318-
llvm_unreachable("should not see type params here");
317+
} else if (isa<GenericTypeParamDecl>(TD)) {
318+
llvm_unreachable("should not see generic parameters here");
319+
} else if (isa<AssociatedTypeDecl>(TD)) {
320+
llvm_unreachable("should not see associated types here");
319321
} else if (isa<StructDecl>(TD) &&
320322
TD->getModuleContext()->isStdlibModule()) {
321323
// stdlib has some @_cdecl functions with structs.

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ static void checkInheritanceClause(
180180
// For generic parameters and associated types, the GSB checks constraints;
181181
// however, we still want to fire off the requests to produce diagnostics
182182
// in some circular validation cases.
183-
if (isa<AbstractTypeParamDecl>(decl))
183+
if (isa<GenericTypeParamDecl>(decl) ||
184+
isa<AssociatedTypeDecl>(decl))
184185
continue;
185186

186187
// Check whether we inherited from 'AnyObject' twice.
@@ -192,7 +193,7 @@ static void checkInheritanceClause(
192193
// for Swift >= 5.
193194
auto sourceRange = inherited.getSourceRange();
194195
bool isWrittenAsClass =
195-
(isa<ProtocolDecl>(decl) || isa<AbstractTypeParamDecl>(decl)) &&
196+
isa<ProtocolDecl>(decl) &&
196197
Lexer::getTokenAtLocation(ctx.SourceMgr, sourceRange.Start)
197198
.is(tok::kw_class);
198199
if (ctx.LangOpts.isSwiftVersionAtLeast(5) && isWrittenAsClass) {
@@ -210,7 +211,7 @@ static void checkInheritanceClause(
210211
auto knownRange = inheritedAnyObject->second;
211212
SourceRange removeRange = getRemovalRange(knownIndex);
212213
if (!ctx.LangOpts.isSwiftVersionAtLeast(5) &&
213-
(isa<ProtocolDecl>(decl) || isa<AbstractTypeParamDecl>(decl)) &&
214+
isa<ProtocolDecl>(decl) &&
214215
Lexer::getTokenAtLocation(ctx.SourceMgr, knownRange.Start)
215216
.is(tok::kw_class)) {
216217
SourceLoc classLoc = knownRange.Start;

0 commit comments

Comments
 (0)