Skip to content

Commit 9249966

Browse files
committed
[Source loader] Delay parsing and type checking for source imports.
Use the delayed parsing of function bodies for source imports, and switch source imports over to lazy type checking. There's no point in doing a full type check for them.
1 parent d8b745d commit 9249966

File tree

3 files changed

+5
-33
lines changed

3 files changed

+5
-33
lines changed

include/swift/Sema/SourceLoader.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,20 @@ class ModuleDecl;
2424
class SourceLoader : public ModuleLoader {
2525
private:
2626
ASTContext &Ctx;
27-
bool SkipBodies;
2827
bool EnableLibraryEvolution;
2928

3029
explicit SourceLoader(ASTContext &ctx,
31-
bool skipBodies,
3230
bool enableResilience,
3331
DependencyTracker *tracker)
3432
: ModuleLoader(tracker), Ctx(ctx),
35-
SkipBodies(skipBodies), EnableLibraryEvolution(enableResilience) {}
33+
EnableLibraryEvolution(enableResilience) {}
3634

3735
public:
3836
static std::unique_ptr<SourceLoader>
39-
create(ASTContext &ctx, bool skipBodies, bool enableResilience,
37+
create(ASTContext &ctx, bool enableResilience,
4038
DependencyTracker *tracker = nullptr) {
4139
return std::unique_ptr<SourceLoader>{
42-
new SourceLoader(ctx, skipBodies, enableResilience, tracker)
40+
new SourceLoader(ctx, enableResilience, tracker)
4341
};
4442
}
4543

lib/Frontend/Frontend.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,9 @@ void CompilerInstance::setUpDiagnosticOptions() {
315315

316316
bool CompilerInstance::setUpModuleLoaders() {
317317
if (hasSourceImport()) {
318-
bool immediate = FrontendOptions::isActionImmediate(
319-
Invocation.getFrontendOptions().RequestedAction);
320318
bool enableLibraryEvolution =
321319
Invocation.getFrontendOptions().EnableLibraryEvolution;
322320
Context->addModuleLoader(SourceLoader::create(*Context,
323-
!immediate,
324321
enableLibraryEvolution,
325322
getDependencyTracker()));
326323
}

lib/Sema/SourceLoader.cpp

+2-25
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,6 @@ static FileOrError findModule(ASTContext &ctx, StringRef moduleID,
5656
return make_error_code(std::errc::no_such_file_or_directory);
5757
}
5858

59-
namespace {
60-
61-
/// Don't parse any function bodies except those that are transparent.
62-
class SkipNonTransparentFunctions : public DelayedParsingCallbacks {
63-
bool shouldDelayFunctionBodyParsing(Parser &TheParser,
64-
AbstractFunctionDecl *AFD,
65-
const DeclAttributes &Attrs,
66-
SourceRange BodyRange) override {
67-
return Attrs.hasAttribute<TransparentAttr>();
68-
}
69-
};
70-
71-
} // unnamed namespace
72-
7359
void SourceLoader::collectVisibleTopLevelModuleNames(
7460
SmallVectorImpl<Identifier> &names) const {
7561
// TODO: Implement?
@@ -145,20 +131,11 @@ ModuleDecl *SourceLoader::loadModule(SourceLoc importLoc,
145131
importMod->addFile(*importFile);
146132

147133
bool done;
148-
PersistentParserState persistentState;
149-
SkipNonTransparentFunctions delayCallbacks;
150-
parseIntoSourceFile(*importFile, bufferID, &done, nullptr, &persistentState,
151-
SkipBodies ? &delayCallbacks : nullptr);
134+
parseIntoSourceFile(*importFile, bufferID, &done, nullptr, nullptr, nullptr);
152135
assert(done && "Parser returned early?");
153136
(void)done;
154137

155-
// FIXME: Support recursive definitions in immediate modes by making type
156-
// checking even lazier.
157-
if (SkipBodies)
158-
performNameBinding(*importFile);
159-
else
160-
performTypeChecking(*importFile, persistentState.getTopLevelContext(),
161-
None);
138+
performNameBinding(*importFile);
162139
importMod->setHasResolvedImports();
163140
return importMod;
164141
}

0 commit comments

Comments
 (0)