Skip to content

Commit 9bf4043

Browse files
committed
[AST] Hack SourceFile::lookupLocalType() to look through local types.
This is only currently exercised by swift-remoteast-test, so do the minimum to ensure that we’re getting cached mangled names, but don’t fret over the linear-time search.
1 parent 2be98a2 commit 9bf4043

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/swift/AST/Module.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,8 @@ class SourceFile final : public FileUnit {
10521052
virtual void
10531053
getPrecedenceGroups(SmallVectorImpl<PrecedenceGroupDecl*> &results) const override;
10541054

1055+
virtual TypeDecl *lookupLocalType(llvm::StringRef MangledName) const override;
1056+
10551057
virtual void
10561058
getLocalTypeDecls(SmallVectorImpl<TypeDecl*> &results) const override;
10571059

lib/AST/Module.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "swift/AST/PrettyStackTrace.h"
3333
#include "swift/AST/PrintOptions.h"
3434
#include "swift/AST/ProtocolConformance.h"
35+
#include "swift/AST/TypeCheckRequests.h"
3536
#include "swift/Basic/Compiler.h"
3637
#include "swift/Basic/SourceManager.h"
3738
#include "swift/Basic/Statistic.h"
@@ -565,6 +566,22 @@ void SourceFile::getLocalTypeDecls(SmallVectorImpl<TypeDecl*> &Results) const {
565566
Results.append(LocalTypeDecls.begin(), LocalTypeDecls.end());
566567
}
567568

569+
TypeDecl *SourceFile::lookupLocalType(llvm::StringRef mangledName) const {
570+
ASTContext &ctx = getASTContext();
571+
for (auto typeDecl : LocalTypeDecls) {
572+
auto typeMangledName = evaluateOrDefault(ctx.evaluator,
573+
USRGenerationRequest { typeDecl },
574+
std::string());
575+
if (typeMangledName.find("s:") == 0)
576+
typeMangledName = typeMangledName.substr(2);
577+
578+
if (mangledName == typeMangledName)
579+
return typeDecl;
580+
}
581+
582+
return nullptr;
583+
}
584+
568585
void ModuleDecl::getDisplayDecls(SmallVectorImpl<Decl*> &Results) const {
569586
// FIXME: Should this do extra access control filtering?
570587
FORWARD(getDisplayDecls, (Results));

0 commit comments

Comments
 (0)