Skip to content

Commit 4c1a28b

Browse files
committed
AST: ComponentIdentTypeRepr::getBoundDecl() is always a TypeDecl
1 parent 2e04e24 commit 4c1a28b

File tree

6 files changed

+18
-20
lines changed

6 files changed

+18
-20
lines changed

include/swift/AST/TypeAlignments.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace swift {
4747
class Substitution;
4848
class TypeVariableType;
4949
class TypeBase;
50+
class TypeDecl;
5051
class ValueDecl;
5152

5253
/// We frequently use three tag bits on all of these types.
@@ -87,6 +88,7 @@ LLVM_DECLARE_TYPE_ALIGNMENT(swift::AssociatedTypeDecl, swift::DeclAlignInBits)
8788
LLVM_DECLARE_TYPE_ALIGNMENT(swift::GenericTypeParamDecl, swift::DeclAlignInBits)
8889
LLVM_DECLARE_TYPE_ALIGNMENT(swift::OperatorDecl, swift::DeclAlignInBits)
8990
LLVM_DECLARE_TYPE_ALIGNMENT(swift::ProtocolDecl, swift::DeclAlignInBits)
91+
LLVM_DECLARE_TYPE_ALIGNMENT(swift::TypeDecl, swift::DeclAlignInBits)
9092
LLVM_DECLARE_TYPE_ALIGNMENT(swift::ValueDecl, swift::DeclAlignInBits)
9193
LLVM_DECLARE_TYPE_ALIGNMENT(swift::ExtensionDecl, swift::DeclAlignInBits)
9294

include/swift/AST/TypeRepr.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace swift {
3333
class DeclContext;
3434
class GenericEnvironment;
3535
class IdentTypeRepr;
36-
class ValueDecl;
36+
class TypeDecl;
3737

3838
enum class TypeReprKind : uint8_t {
3939
#define TYPEREPR(ID, PARENT) ID,
@@ -243,7 +243,7 @@ class ComponentIdentTypeRepr : public IdentTypeRepr {
243243
///
244244
/// The initial parsed representation is always an identifier, and
245245
/// name binding will resolve this to a specific declaration.
246-
llvm::PointerUnion<Identifier, ValueDecl *> IdOrDecl;
246+
llvm::PointerUnion<Identifier, TypeDecl *> IdOrDecl;
247247

248248
protected:
249249
ComponentIdentTypeRepr(TypeReprKind K, SourceLoc Loc, Identifier Id)
@@ -258,11 +258,11 @@ class ComponentIdentTypeRepr : public IdentTypeRepr {
258258
void overwriteIdentifier(Identifier newId) { IdOrDecl = newId; }
259259

260260
/// Return true if this has been name-bound already.
261-
bool isBound() const { return IdOrDecl.is<ValueDecl *>(); }
261+
bool isBound() const { return IdOrDecl.is<TypeDecl *>(); }
262262

263-
ValueDecl *getBoundDecl() const { return IdOrDecl.dyn_cast<ValueDecl*>(); }
263+
TypeDecl *getBoundDecl() const { return IdOrDecl.dyn_cast<TypeDecl*>(); }
264264

265-
void setValue(ValueDecl *VD) { IdOrDecl = VD; }
265+
void setValue(TypeDecl *TD) { IdOrDecl = TD; }
266266

267267
static bool classof(const TypeRepr *T) {
268268
return T->getKind() == TypeReprKind::SimpleIdent ||

lib/AST/TypeRepr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Identifier ComponentIdentTypeRepr::getIdentifier() const {
7777
if (IdOrDecl.is<Identifier>())
7878
return IdOrDecl.get<Identifier>();
7979

80-
return IdOrDecl.get<ValueDecl *>()->getName();
80+
return IdOrDecl.get<TypeDecl *>()->getName();
8181
}
8282

8383
static void printTypeRepr(const TypeRepr *TyR, ASTPrinter &Printer,

lib/Parse/ParseSIL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,8 +775,8 @@ namespace {
775775
auto *T = dyn_cast_or_null<IdentTypeRepr>(Ty);
776776
auto Comp = T->getComponentRange().front();
777777
if (auto Entry = P.lookupInScope(Comp->getIdentifier()))
778-
if (isa<TypeDecl>(Entry)) {
779-
Comp->setValue(Entry);
778+
if (auto *TD = dyn_cast<TypeDecl>(Entry)) {
779+
Comp->setValue(TD);
780780
return false;
781781
}
782782
return true;

lib/Parse/ParseType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,8 @@ ParserResult<TypeRepr> Parser::parseTypeIdentifier() {
581581
// Lookup element #0 through our current scope chains in case it is some
582582
// thing local (this returns null if nothing is found).
583583
if (auto Entry = lookupInScope(ComponentsR[0]->getIdentifier()))
584-
if (isa<TypeDecl>(Entry))
585-
ComponentsR[0]->setValue(Entry);
584+
if (auto *TD = dyn_cast<TypeDecl>(Entry))
585+
ComponentsR[0]->setValue(TD);
586586

587587
ITR = IdentTypeRepr::create(Context, ComponentsR);
588588
}

lib/Sema/TypeCheckType.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,9 +1137,7 @@ resolveTopLevelIdentTypeComponent(TypeChecker &TC, DeclContext *DC,
11371137

11381138
// If the component has already been bound to a declaration, handle
11391139
// that now.
1140-
if (ValueDecl *VD = comp->getBoundDecl()) {
1141-
auto *typeDecl = cast<TypeDecl>(VD);
1142-
1140+
if (auto *typeDecl = comp->getBoundDecl()) {
11431141
// Resolve the type declaration within this context.
11441142
return resolveTypeDecl(TC, typeDecl, comp->getIdLoc(), DC,
11451143
dyn_cast<GenericIdentTypeRepr>(comp), options,
@@ -1328,9 +1326,7 @@ static Type resolveNestedIdentTypeComponent(
13281326
}
13291327

13301328
// Phase 2: If a declaration has already been bound, use it.
1331-
if (ValueDecl *decl = comp->getBoundDecl()) {
1332-
auto *typeDecl = cast<TypeDecl>(decl);
1333-
1329+
if (auto *typeDecl = comp->getBoundDecl()) {
13341330
// Otherwise, simply substitute the parent type into the member.
13351331
auto memberType = TC.substMemberTypeWithBase(DC->getParentModule(),
13361332
typeDecl, parentTy);
@@ -1428,7 +1424,7 @@ static Type resolveNestedIdentTypeComponent(
14281424
}
14291425

14301426
memberType = ty;
1431-
member = cast_or_null<TypeDecl>(comp->getBoundDecl());
1427+
member = comp->getBoundDecl();
14321428
} else {
14331429
memberType = memberTypes.back().second;
14341430
member = memberTypes.back().first;
@@ -1530,7 +1526,7 @@ static bool diagnoseAvailability(IdentTypeRepr *IdType,
15301526
bool AllowPotentiallyUnavailableProtocol) {
15311527
auto componentRange = IdType->getComponentRange();
15321528
for (auto comp : componentRange) {
1533-
if (auto typeDecl = dyn_cast_or_null<TypeDecl>(comp->getBoundDecl())) {
1529+
if (auto *typeDecl = comp->getBoundDecl()) {
15341530
// In Swift 3, components other than the last one were not properly
15351531
// checked for availability.
15361532
// FIXME: We should try to downgrade these errors to warnings, not just
@@ -4053,13 +4049,13 @@ class UnsupportedProtocolVisitor
40534049
return;
40544050

40554051
auto comp = T->getComponentRange().back();
4056-
if (auto proto = dyn_cast_or_null<ProtocolDecl>(comp->getBoundDecl())) {
4052+
if (auto *proto = dyn_cast_or_null<ProtocolDecl>(comp->getBoundDecl())) {
40574053
if (!proto->existentialTypeSupported(&TC)) {
40584054
TC.diagnose(comp->getIdLoc(), diag::unsupported_existential_type,
40594055
proto->getName());
40604056
T->setInvalid();
40614057
}
4062-
} else if (auto alias = dyn_cast_or_null<TypeAliasDecl>(comp->getBoundDecl())) {
4058+
} else if (auto *alias = dyn_cast_or_null<TypeAliasDecl>(comp->getBoundDecl())) {
40634059
if (!alias->hasInterfaceType())
40644060
return;
40654061
auto type = Type(alias->getDeclaredInterfaceType()->getDesugaredType());

0 commit comments

Comments
 (0)