Skip to content

Commit 7d80ae4

Browse files
authored
Merge pull request #34059 from CodaFi/graphics-card
[NFC] Some Uncontroversial Frontend Refactorings
2 parents 361c477 + 7c256f2 commit 7d80ae4

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class SerializedModuleLoaderBase : public ModuleLoader {
153153
///
154154
/// If the AST cannot be loaded and \p diagLoc is present, a diagnostic is
155155
/// printed. (Note that \p diagLoc is allowed to be invalid.)
156-
FileUnit *
156+
LoadedFile *
157157
loadAST(ModuleDecl &M, Optional<SourceLoc> diagLoc,
158158
StringRef moduleInterfacePath,
159159
std::unique_ptr<llvm::MemoryBuffer> moduleInputBuffer,

lib/AST/FrontendSourceFileDepGraphFactory.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// it is written to a file which is read by the driver in order to decide which
1616
// source files require recompilation.
1717

18-
#include "swift/AST/FrontendSourceFileDepGraphFactory.h"
18+
#include "FrontendSourceFileDepGraphFactory.h"
1919

2020
// may not all be needed
2121
#include "swift/AST/ASTContext.h"
@@ -298,16 +298,13 @@ std::string FrontendSourceFileDepGraphFactory::getFingerprint(SourceFile *SF) {
298298
// MARK: FrontendSourceFileDepGraphFactory - adding collections of defined Decls
299299
//==============================================================================
300300
//==============================================================================
301-
// MARK: SourceFileDeclFinder
301+
// MARK: DeclFinder
302302
//==============================================================================
303303

304304
namespace {
305305
/// Takes all the Decls in a SourceFile, and collects them into buckets by
306306
/// groups of DeclKinds. Also casts them to more specific types
307-
/// TODO: Factor with SourceFileDeclFinder
308-
struct SourceFileDeclFinder {
309-
310-
public:
307+
struct DeclFinder {
311308
/// Existing system excludes private decls in some cases.
312309
/// In the future, we might not want to do this, so use bool to decide.
313310
const bool includePrivateDecls;
@@ -324,11 +321,16 @@ struct SourceFileDeclFinder {
324321
ConstPtrPairVec<NominalTypeDecl, ValueDecl> valuesInExtensions;
325322
ConstPtrVec<ValueDecl> classMembers;
326323

324+
using LookupClassMember = llvm::function_ref<void(VisibleDeclConsumer &)>;
325+
326+
public:
327327
/// Construct me and separates the Decls.
328328
// clang-format off
329-
SourceFileDeclFinder(const SourceFile *const SF, const bool includePrivateDecls)
329+
DeclFinder(ArrayRef<Decl *> topLevelDecls,
330+
const bool includePrivateDecls,
331+
LookupClassMember lookupClassMember)
330332
: includePrivateDecls(includePrivateDecls) {
331-
for (const Decl *const D : SF->getTopLevelDecls()) {
333+
for (const Decl *const D : topLevelDecls) {
332334
select<ExtensionDecl, DeclKind::Extension>(D, extensions, false) ||
333335
select<OperatorDecl, DeclKind::InfixOperator, DeclKind::PrefixOperator,
334336
DeclKind::PostfixOperator>(D, operators, false) ||
@@ -345,7 +347,7 @@ struct SourceFileDeclFinder {
345347
findNominalsFromExtensions();
346348
findNominalsInTopNominals();
347349
findValuesInExtensions();
348-
findClassMembers(SF);
350+
findClassMembers(lookupClassMember);
349351
}
350352

351353
private:
@@ -419,7 +421,7 @@ struct SourceFileDeclFinder {
419421
}
420422

421423
/// Class members are needed for dynamic lookup dependency nodes.
422-
void findClassMembers(const SourceFile *const SF) {
424+
void findClassMembers(LookupClassMember lookup) {
423425
struct Collector : public VisibleDeclConsumer {
424426
ConstPtrVec<ValueDecl> &classMembers;
425427
Collector(ConstPtrVec<ValueDecl> &classMembers)
@@ -429,7 +431,7 @@ struct SourceFileDeclFinder {
429431
classMembers.push_back(VD);
430432
}
431433
} collector{classMembers};
432-
SF->lookupClassMembers({}, collector);
434+
lookup(collector);
433435
}
434436

435437
/// Check \p D to see if it is one of the DeclKinds in the template
@@ -470,7 +472,10 @@ void FrontendSourceFileDepGraphFactory::addAllDefinedDecls() {
470472

471473
// Many kinds of Decls become top-level depends.
472474

473-
SourceFileDeclFinder declFinder(SF, includePrivateDeps);
475+
DeclFinder declFinder(SF->getTopLevelDecls(), includePrivateDeps,
476+
[this](VisibleDeclConsumer &consumer) {
477+
SF->lookupClassMembers({}, consumer);
478+
});
474479

475480
addAllDefinedDeclsOfAGivenType<NodeKind::topLevel>(
476481
declFinder.precedenceGroups);

include/swift/AST/FrontendSourceFileDepGraphFactory.h renamed to lib/AST/FrontendSourceFileDepGraphFactory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===----- FrontendSourceFileDepGraphFactory.h -------------------*- C++ -*-===//
1+
//===----- FrontendSourceFileDepGraphFactory.h ------------------*- C++ -*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ getOSAndVersionForDiagnostics(const llvm::Triple &triple) {
673673
return {osName, version};
674674
}
675675

676-
FileUnit *SerializedModuleLoaderBase::loadAST(
676+
LoadedFile *SerializedModuleLoaderBase::loadAST(
677677
ModuleDecl &M, Optional<SourceLoc> diagLoc,
678678
StringRef moduleInterfacePath,
679679
std::unique_ptr<llvm::MemoryBuffer> moduleInputBuffer,

0 commit comments

Comments
 (0)