Skip to content

Commit c25e218

Browse files
committed
Convert some TypeLoc computations to helpers
These aren't requirements of the (Simple)Request interface. Downgrade them to helper functions.
1 parent 087e2f2 commit c25e218

File tree

7 files changed

+23
-32
lines changed

7 files changed

+23
-32
lines changed

include/swift/AST/NameLookup.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,17 @@ getDirectlyInheritedNominalTypeDecls(
448448
SelfBounds getSelfBoundsFromWhereClause(
449449
llvm::PointerUnion<TypeDecl *, ExtensionDecl *> decl);
450450

451+
/// Retrieve the TypeLoc at the given \c index from among the set of
452+
/// type declarations that are directly "inherited" by the given declaration.
453+
inline TypeLoc &
454+
getInheritedTypeLocAtIndex(llvm::PointerUnion<TypeDecl *, ExtensionDecl *> decl,
455+
unsigned index) {
456+
if (auto typeDecl = decl.dyn_cast<TypeDecl *>())
457+
return typeDecl->getInherited()[index];
458+
459+
return decl.get<ExtensionDecl *>()->getInherited()[index];
460+
}
461+
451462
namespace namelookup {
452463

453464
/// Searches through statements and patterns for local variable declarations.

include/swift/AST/NameLookupRequests.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ class InheritedDeclsReferencedRequest :
6262
unsigned),
6363
CacheKind::Uncached> // FIXME: Cache these
6464
{
65-
/// Retrieve the TypeLoc for this inherited type.
66-
TypeLoc &getTypeLoc(llvm::PointerUnion<TypeDecl *, ExtensionDecl *> decl,
67-
unsigned index) const;
68-
6965
public:
7066
using SimpleRequest::SimpleRequest;
7167

include/swift/AST/TypeCheckRequests.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ class InheritedTypeRequest :
5757
TypeResolutionStage),
5858
CacheKind::SeparatelyCached>
5959
{
60-
/// Retrieve the TypeLoc for this inherited type.
61-
TypeLoc &getTypeLoc(llvm::PointerUnion<TypeDecl *, ExtensionDecl *> decl,
62-
unsigned index) const;
63-
6460
public:
6561
using SimpleRequest::SimpleRequest;
6662

lib/AST/NameLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2030,7 +2030,7 @@ DirectlyReferencedTypeDecls InheritedDeclsReferencedRequest::evaluate(
20302030
unsigned index) const {
20312031

20322032
// Prefer syntactic information when we have it.
2033-
TypeLoc &typeLoc = getTypeLoc(decl, index);
2033+
TypeLoc &typeLoc = getInheritedTypeLocAtIndex(decl, index);
20342034
if (auto typeRepr = typeLoc.getTypeRepr()) {
20352035
// Figure out the context in which name lookup will occur.
20362036
DeclContext *dc;

lib/AST/NameLookupRequests.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "swift/AST/NameLookup.h"
1314
#include "swift/AST/NameLookupRequests.h"
1415
#include "swift/Subsystems.h"
1516
#include "swift/AST/ASTContext.h"
@@ -31,19 +32,11 @@ namespace swift {
3132
//----------------------------------------------------------------------------//
3233
// Referenced inherited decls computation.
3334
//----------------------------------------------------------------------------//
34-
TypeLoc &InheritedDeclsReferencedRequest::getTypeLoc(
35-
llvm::PointerUnion<TypeDecl *, ExtensionDecl *> decl,
36-
unsigned index) const {
37-
// FIXME: Copy-pasted from InheritedTypeRequest. We need to consolidate here.
38-
if (auto typeDecl = decl.dyn_cast<TypeDecl *>())
39-
return typeDecl->getInherited()[index];
40-
41-
return decl.get<ExtensionDecl *>()->getInherited()[index];
42-
}
4335

4436
SourceLoc InheritedDeclsReferencedRequest::getNearestLoc() const {
4537
const auto &storage = getStorage();
46-
auto &typeLoc = getTypeLoc(std::get<0>(storage), std::get<1>(storage));
38+
auto &typeLoc = getInheritedTypeLocAtIndex(std::get<0>(storage),
39+
std::get<1>(storage));
4740
return typeLoc.getLoc();
4841
}
4942

lib/AST/TypeCheckRequests.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "swift/AST/Decl.h"
1414
#include "swift/AST/DiagnosticsCommon.h"
1515
#include "swift/AST/Module.h"
16+
#include "swift/AST/NameLookup.h"
1617
#include "swift/AST/PropertyWrappers.h"
1718
#include "swift/AST/TypeCheckRequests.h"
1819
#include "swift/AST/TypeLoc.h"
@@ -85,18 +86,10 @@ void swift::simple_display(llvm::raw_ostream &out, const TypeLoc source) {
8586
// Inherited type computation.
8687
//----------------------------------------------------------------------------//
8788

88-
TypeLoc &InheritedTypeRequest::getTypeLoc(
89-
llvm::PointerUnion<TypeDecl *, ExtensionDecl *> decl,
90-
unsigned index) const {
91-
if (auto typeDecl = decl.dyn_cast<TypeDecl *>())
92-
return typeDecl->getInherited()[index];
93-
94-
return decl.get<ExtensionDecl *>()->getInherited()[index];
95-
}
96-
9789
SourceLoc InheritedTypeRequest::getNearestLoc() const {
9890
const auto &storage = getStorage();
99-
auto &typeLoc = getTypeLoc(std::get<0>(storage), std::get<1>(storage));
91+
auto &typeLoc = getInheritedTypeLocAtIndex(std::get<0>(storage),
92+
std::get<1>(storage));
10093
return typeLoc.getLoc();
10194
}
10295

@@ -106,7 +99,8 @@ bool InheritedTypeRequest::isCached() const {
10699

107100
Optional<Type> InheritedTypeRequest::getCachedResult() const {
108101
const auto &storage = getStorage();
109-
auto &typeLoc = getTypeLoc(std::get<0>(storage), std::get<1>(storage));
102+
auto &typeLoc = getInheritedTypeLocAtIndex(std::get<0>(storage),
103+
std::get<1>(storage));
110104
if (typeLoc.wasValidated())
111105
return typeLoc.getType();
112106

@@ -115,7 +109,8 @@ Optional<Type> InheritedTypeRequest::getCachedResult() const {
115109

116110
void InheritedTypeRequest::cacheResult(Type value) const {
117111
const auto &storage = getStorage();
118-
auto &typeLoc = getTypeLoc(std::get<0>(storage), std::get<1>(storage));
112+
auto &typeLoc = getInheritedTypeLocAtIndex(std::get<0>(storage),
113+
std::get<1>(storage));
119114
typeLoc.setType(value);
120115
}
121116

lib/Sema/TypeCheckRequestFunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ InheritedTypeRequest::evaluate(
6868
}
6969
}
7070

71-
TypeLoc &typeLoc = getTypeLoc(decl, index);
71+
TypeLoc &typeLoc = getInheritedTypeLocAtIndex(decl, index);
7272

7373
Type inheritedType;
7474
if (typeLoc.getTypeRepr())

0 commit comments

Comments
 (0)