ModuleInterface: refactor compiler instance configuration to a standalone delegate class. NFC

Module interface builder used to maintain a separate compiler instance for
building Swift modules. The configuration of this compiler instance is also
useful for dependencies scanner because it needs to emit front-end compiler invocation
for building Swift modules explicitly.

This patch refactor the configuration out to a delegate class, and the
delegate class is also used by the dependency scanner.
This commit is contained in:
Xi Ge
2020-05-11 14:33:15 -07:00
parent c5503cee21
commit 3952fd5bf7
15 changed files with 414 additions and 372 deletions

View File

@@ -33,12 +33,13 @@ class ModuleDependencyScanner : public SerializedModuleLoaderBase {
ErrorOr<ModuleDependencies> scanInterfaceFile(
Twine moduleInterfacePath);
SubASTContextDelegate &astDelegate;
InterfaceSubContextDelegate &astDelegate;
public:
Optional<ModuleDependencies> dependencies;
ModuleDependencyScanner(ASTContext &ctx, ModuleLoadingMode LoadMode,
Identifier moduleName, SubASTContextDelegate &astDelegate)
Identifier moduleName,
InterfaceSubContextDelegate &astDelegate)
: SerializedModuleLoaderBase(ctx, nullptr, LoadMode,
/*IgnoreSwiftSourceInfoFile=*/true),
moduleName(moduleName), astDelegate(astDelegate) { }
@@ -104,9 +105,10 @@ ErrorOr<ModuleDependencies> ModuleDependencyScanner::scanInterfaceFile(
ModuleDependencies Result = ModuleDependencies::forSwiftInterface(
modulePath.str().str(), moduleInterfacePath.str());
std::error_code code;
auto hasError = astDelegate.runInSubContext(Ctx,
moduleInterfacePath.str(),
[&](ASTContext &Ctx) {
auto hasError = astDelegate.runInSubContext(moduleName.str(),
moduleInterfacePath.str(),
StringRef(), SourceLoc(),
[&](ASTContext &Ctx) {
// Open the interface file.
auto &fs = *Ctx.SourceMgr.getFileSystem();
auto interfaceBuf = fs.getBufferForFile(moduleInterfacePath);
@@ -135,7 +137,7 @@ ErrorOr<ModuleDependencies> ModuleDependencyScanner::scanInterfaceFile(
Optional<ModuleDependencies> SerializedModuleLoaderBase::getModuleDependencies(
StringRef moduleName, ModuleDependenciesCache &cache,
SubASTContextDelegate &delegate) {
InterfaceSubContextDelegate &delegate) {
// Check whether we've cached this result.
if (auto found = cache.findDependencies(
moduleName, ModuleDependenciesKind::Swift))