Skip to content

Commit d4cf2d4

Browse files
author
David Ungar
authored
Merge pull request swiftlang#11656 from davidungar/addingTimers
Refactoring performSema in order to add timers
2 parents eccdeda + 4ca60fe commit d4cf2d4

File tree

9 files changed

+458
-288
lines changed

9 files changed

+458
-288
lines changed

include/swift/Frontend/Frontend.h

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,26 @@
1818
#ifndef SWIFT_FRONTEND_H
1919
#define SWIFT_FRONTEND_H
2020

21-
#include "swift/Basic/DiagnosticOptions.h"
22-
#include "swift/Basic/LangOptions.h"
23-
#include "swift/Basic/SourceManager.h"
2421
#include "swift/AST/DiagnosticConsumer.h"
2522
#include "swift/AST/DiagnosticEngine.h"
2623
#include "swift/AST/IRGenOptions.h"
2724
#include "swift/AST/LinkLibrary.h"
2825
#include "swift/AST/Module.h"
29-
#include "swift/AST/SearchPathOptions.h"
3026
#include "swift/AST/SILOptions.h"
31-
#include "swift/Parse/CodeCompletionCallbacks.h"
32-
#include "swift/Parse/Parser.h"
27+
#include "swift/AST/SearchPathOptions.h"
28+
#include "swift/Basic/DiagnosticOptions.h"
29+
#include "swift/Basic/LangOptions.h"
30+
#include "swift/Basic/SourceManager.h"
3331
#include "swift/ClangImporter/ClangImporter.h"
3432
#include "swift/ClangImporter/ClangImporterOptions.h"
3533
#include "swift/Frontend/FrontendOptions.h"
3634
#include "swift/Migrator/MigratorOptions.h"
35+
#include "swift/Parse/CodeCompletionCallbacks.h"
36+
#include "swift/Parse/Parser.h"
37+
#include "swift/SIL/SILModule.h"
3738
#include "swift/Sema/SourceLoader.h"
3839
#include "swift/Serialization/Validation.h"
39-
#include "swift/SIL/SILModule.h"
40+
#include "swift/Subsystems.h"
4041
#include "llvm/ADT/IntrusiveRefCntPtr.h"
4142
#include "llvm/Option/ArgList.h"
4243
#include "llvm/Support/Host.h"
@@ -304,6 +305,16 @@ class CompilerInvocation {
304305
/// identifying the conditions under which the module was built, for use
305306
/// in generating a cached PCH file for the bridging header.
306307
std::string getPCHHash() const;
308+
309+
SourceFile::ImplicitModuleImportKind getImplicitModuleImportKind() {
310+
if (getInputKind() == InputFileKind::IFK_SIL) {
311+
return SourceFile::ImplicitModuleImportKind::None;
312+
}
313+
if (getParseStdlib()) {
314+
return SourceFile::ImplicitModuleImportKind::Builtin;
315+
}
316+
return SourceFile::ImplicitModuleImportKind::Stdlib;
317+
}
307318
};
308319

309320
/// A class which manages the state and execution of the compiler.
@@ -341,11 +352,14 @@ class CompilerInstance {
341352

342353
enum : unsigned { NO_SUCH_BUFFER = ~0U };
343354
unsigned MainBufferID = NO_SUCH_BUFFER;
355+
356+
/// PrimaryBufferID corresponds to PrimaryInput.
344357
unsigned PrimaryBufferID = NO_SUCH_BUFFER;
358+
bool isWholeModuleCompilation() { return PrimaryBufferID == NO_SUCH_BUFFER; }
345359

346360
SourceFile *PrimarySourceFile = nullptr;
347361

348-
void createSILModule(bool WholeModule = false);
362+
void createSILModule();
349363
void setPrimarySourceFile(SourceFile *SF);
350364

351365
public:
@@ -433,6 +447,55 @@ class CompilerInstance {
433447
/// Frees up the ASTContext and SILModule objects that this instance is
434448
/// holding on.
435449
void freeContextAndSIL();
450+
451+
private:
452+
/// Load stdlib & return true if should continue, i.e. no error
453+
bool loadStdlib();
454+
ModuleDecl *importUnderlyingModule();
455+
ModuleDecl *importBridgingHeader();
456+
457+
void
458+
getImplicitlyImportedModules(SmallVectorImpl<ModuleDecl *> &importModules);
459+
460+
public: // for static functions in Frontend.cpp
461+
struct ImplicitImports {
462+
SourceFile::ImplicitModuleImportKind kind;
463+
ModuleDecl *objCModuleUnderlyingMixedFramework;
464+
ModuleDecl *headerModule;
465+
SmallVector<ModuleDecl *, 4> modules;
466+
467+
explicit ImplicitImports(CompilerInstance &compiler);
468+
};
469+
470+
private:
471+
void createREPLFile(const ImplicitImports &implicitImports) const;
472+
std::unique_ptr<DelayedParsingCallbacks> computeDelayedParsingCallback();
473+
474+
void addMainFileToModule(const ImplicitImports &implicitImports);
475+
476+
void parseAndCheckTypes(const ImplicitImports &implicitImports);
477+
478+
void parseLibraryFile(unsigned BufferID,
479+
const ImplicitImports &implicitImports,
480+
PersistentParserState &PersistentState,
481+
DelayedParsingCallbacks *DelayedParseCB);
482+
483+
/// Return true if had load error
484+
bool
485+
parsePartialModulesAndLibraryFiles(const ImplicitImports &implicitImports,
486+
PersistentParserState &PersistentState,
487+
DelayedParsingCallbacks *DelayedParseCB);
488+
489+
OptionSet<TypeCheckingFlags> computeTypeCheckingOptions();
490+
491+
void forEachFileToTypeCheck(llvm::function_ref<void(SourceFile &)> fn);
492+
493+
void parseAndTypeCheckMainFile(PersistentParserState &PersistentState,
494+
DelayedParsingCallbacks *DelayedParseCB,
495+
OptionSet<TypeCheckingFlags> TypeCheckOptions);
496+
void performTypeCheckingAndDelayedParsing();
497+
498+
void finishTypeChecking(OptionSet<TypeCheckingFlags> TypeCheckOptions);
436499
};
437500

438501
} // namespace swift

include/swift/Frontend/FrontendOptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ class FrontendOptions {
195195
EmitObject, ///< Emit object file
196196
};
197197

198+
bool isCreatingSIL() { return RequestedAction >= EmitSILGen; }
199+
198200
/// Indicates the action the user requested that the frontend perform.
199201
ActionType RequestedAction = NoneAction;
200202

include/swift/Subsystems.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ namespace swift {
186186

187187
/// Once type checking is complete, this walks protocol requirements
188188
/// to resolve default witnesses.
189-
void finishTypeChecking(SourceFile &SF);
189+
void finishTypeCheckingFile(SourceFile &SF);
190190

191191
/// Now that we have type-checked an entire module, perform any type
192192
/// checking that requires the full module, e.g., Objective-C method

lib/AST/ASTContext.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616

1717
#include "swift/AST/ASTContext.h"
1818
#include "ForeignRepresentationInfo.h"
19-
#include "swift/Strings.h"
20-
#include "swift/AST/ExistentialLayout.h"
21-
#include "swift/AST/GenericSignatureBuilder.h"
2219
#include "swift/AST/ConcreteDeclRef.h"
2320
#include "swift/AST/DiagnosticEngine.h"
2421
#include "swift/AST/DiagnosticsSema.h"
22+
#include "swift/AST/ExistentialLayout.h"
2523
#include "swift/AST/ForeignErrorConvention.h"
2624
#include "swift/AST/GenericEnvironment.h"
25+
#include "swift/AST/GenericSignatureBuilder.h"
2726
#include "swift/AST/KnownProtocols.h"
2827
#include "swift/AST/LazyResolver.h"
2928
#include "swift/AST/ModuleLoader.h"
@@ -35,8 +34,10 @@
3534
#include "swift/AST/TypeCheckerDebugConsumer.h"
3635
#include "swift/Basic/Compiler.h"
3736
#include "swift/Basic/SourceManager.h"
37+
#include "swift/Basic/Statistic.h"
3838
#include "swift/Basic/StringExtras.h"
3939
#include "swift/Parse/Lexer.h" // bad dependency
40+
#include "swift/Strings.h"
4041
#include "clang/AST/Attr.h"
4142
#include "clang/AST/DeclObjC.h"
4243
#include "clang/Lex/HeaderSearch.h"
@@ -1377,6 +1378,7 @@ void ASTContext::loadObjCMethods(
13771378

13781379
void ASTContext::verifyAllLoadedModules() const {
13791380
#ifndef NDEBUG
1381+
SharedTimer("verifyAllLoadedModules");
13801382
for (auto &loader : Impl.ModuleLoaders)
13811383
loader->verifyAllModules();
13821384

lib/AST/Module.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,15 +1289,17 @@ SourceFile::getCachedVisibleDecls() const {
12891289
return getCache().AllVisibleValues;
12901290
}
12911291

1292-
static void performAutoImport(SourceFile &SF,
1293-
SourceFile::ImplicitModuleImportKind modImpKind) {
1292+
static void performAutoImport(
1293+
SourceFile &SF,
1294+
SourceFile::ImplicitModuleImportKind implicitModuleImportKind) {
12941295
if (SF.Kind == SourceFileKind::SIL)
1295-
assert(modImpKind == SourceFile::ImplicitModuleImportKind::None);
1296+
assert(implicitModuleImportKind ==
1297+
SourceFile::ImplicitModuleImportKind::None);
12961298

12971299
ASTContext &Ctx = SF.getASTContext();
12981300
ModuleDecl *M = nullptr;
12991301

1300-
switch (modImpKind) {
1302+
switch (implicitModuleImportKind) {
13011303
case SourceFile::ImplicitModuleImportKind::None:
13021304
return;
13031305
case SourceFile::ImplicitModuleImportKind::Builtin:

lib/ClangImporter/ImportDecl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7978,6 +7978,10 @@ createUnavailableDecl(Identifier name, DeclContext *dc, Type type,
79787978

79797979
void
79807980
ClangImporter::Implementation::loadAllMembers(Decl *D, uint64_t extra) {
7981+
static RecursiveSharedTimer timer("ClangImporterLoadAllMembers");
7982+
auto guard = RecursiveSharedTimer::Guard(timer);
7983+
(void)guard;
7984+
79817985
assert(D);
79827986

79837987
// Check whether we're importing an Objective-C container of some sort.

0 commit comments

Comments
 (0)