Skip to content

Commit 28b0b22

Browse files
committed
ModuleInterface: refactor several configuration values into an Option struct
1 parent 1ae70a5 commit 28b0b22

File tree

5 files changed

+45
-65
lines changed

5 files changed

+45
-65
lines changed

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ class LangOptions;
127127
class SearchPathOptions;
128128
class CompilerInvocation;
129129

130+
struct ModuleInterfaceLoaderOptions {
131+
bool remarkOnRebuildFromInterface = false;
132+
bool disableInterfaceLock = false;
133+
bool disableImplicitSwiftModule = false;
134+
ModuleInterfaceLoaderOptions(const FrontendOptions &Opts):
135+
remarkOnRebuildFromInterface(Opts.RemarkOnRebuildFromModuleInterface),
136+
disableInterfaceLock(Opts.DisableInterfaceFileLock),
137+
disableImplicitSwiftModule(Opts.DisableImplicitModules) {}
138+
ModuleInterfaceLoaderOptions() = default;
139+
};
130140
/// A ModuleLoader that runs a subordinate \c CompilerInvocation and
131141
/// \c CompilerInstance to convert .swiftinterface files to .swiftmodule
132142
/// files on the fly, caching the resulting .swiftmodules in the module cache
@@ -137,23 +147,17 @@ class ModuleInterfaceLoader : public SerializedModuleLoaderBase {
137147
ASTContext &ctx, StringRef cacheDir, StringRef prebuiltCacheDir,
138148
DependencyTracker *tracker, ModuleLoadingMode loadMode,
139149
ArrayRef<std::string> PreferInterfaceForModules,
140-
bool RemarkOnRebuildFromInterface, bool IgnoreSwiftSourceInfoFile,
141-
bool DisableInterfaceFileLock, bool DisableImplicitSwiftModule)
150+
bool IgnoreSwiftSourceInfoFile, ModuleInterfaceLoaderOptions Opts)
142151
: SerializedModuleLoaderBase(ctx, tracker, loadMode,
143152
IgnoreSwiftSourceInfoFile),
144153
CacheDir(cacheDir), PrebuiltCacheDir(prebuiltCacheDir),
145-
RemarkOnRebuildFromInterface(RemarkOnRebuildFromInterface),
146-
DisableInterfaceFileLock(DisableInterfaceFileLock),
147-
DisableImplicitSwiftModule(DisableImplicitSwiftModule),
148-
PreferInterfaceForModules(PreferInterfaceForModules)
149-
{}
154+
PreferInterfaceForModules(PreferInterfaceForModules),
155+
Opts(Opts) {}
150156

151157
std::string CacheDir;
152158
std::string PrebuiltCacheDir;
153-
bool RemarkOnRebuildFromInterface;
154-
bool DisableInterfaceFileLock;
155-
bool DisableImplicitSwiftModule;
156159
ArrayRef<std::string> PreferInterfaceForModules;
160+
ModuleInterfaceLoaderOptions Opts;
157161

158162
std::error_code findModuleFilesInDirectory(
159163
AccessPathElem ModuleID,
@@ -170,18 +174,14 @@ class ModuleInterfaceLoader : public SerializedModuleLoaderBase {
170174
create(ASTContext &ctx, StringRef cacheDir, StringRef prebuiltCacheDir,
171175
DependencyTracker *tracker, ModuleLoadingMode loadMode,
172176
ArrayRef<std::string> PreferInterfaceForModules = {},
173-
bool RemarkOnRebuildFromInterface = false,
174-
bool IgnoreSwiftSourceInfoFile = false,
175-
bool DisableInterfaceFileLock = false,
176-
bool DisableImplicitSwiftModule = false) {
177+
ModuleInterfaceLoaderOptions Opts = ModuleInterfaceLoaderOptions(),
178+
bool IgnoreSwiftSourceInfoFile = false) {
177179
return std::unique_ptr<ModuleInterfaceLoader>(
178180
new ModuleInterfaceLoader(ctx, cacheDir, prebuiltCacheDir,
179181
tracker, loadMode,
180182
PreferInterfaceForModules,
181-
RemarkOnRebuildFromInterface,
182183
IgnoreSwiftSourceInfoFile,
183-
DisableInterfaceFileLock,
184-
DisableImplicitSwiftModule));
184+
Opts));
185185
}
186186

187187
/// Append visible module names to \p names. Note that names are possibly
@@ -200,8 +200,7 @@ class ModuleInterfaceLoader : public SerializedModuleLoaderBase {
200200
StringRef CacheDir, StringRef PrebuiltCacheDir,
201201
StringRef ModuleName, StringRef InPath, StringRef OutPath,
202202
bool SerializeDependencyHashes, bool TrackSystemDependencies,
203-
bool RemarkOnRebuildFromInterface, bool DisableInterfaceFileLock,
204-
bool DisableImplicitSwiftModules);
203+
ModuleInterfaceLoaderOptions Opts);
205204
};
206205

207206
struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
@@ -237,15 +236,13 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
237236
DiagnosticEngine &Diags,
238237
const SearchPathOptions &searchPathOpts,
239238
const LangOptions &langOpts,
239+
ModuleInterfaceLoaderOptions LoaderOpts,
240240
ClangModuleLoader *clangImporter,
241241
bool buildModuleCacheDirIfAbsent,
242242
StringRef moduleCachePath,
243243
StringRef prebuiltCachePath,
244244
bool serializeDependencyHashes,
245-
bool trackSystemDependencies,
246-
bool remarkOnRebuildFromInterface,
247-
bool disableInterfaceFileLock,
248-
bool disableImplicitSwiftModule);
245+
bool trackSystemDependencies);
249246
bool runInSubContext(StringRef moduleName,
250247
StringRef interfacePath,
251248
StringRef outputPath,

lib/Frontend/Frontend.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,13 +455,12 @@ bool CompilerInstance::setUpModuleLoaders() {
455455
std::string ModuleCachePath = getModuleCachePathFromClang(Clang);
456456
auto &FEOpts = Invocation.getFrontendOptions();
457457
StringRef PrebuiltModuleCachePath = FEOpts.PrebuiltModuleCachePath;
458+
ModuleInterfaceLoaderOptions LoaderOpts(FEOpts);
458459
auto PIML = ModuleInterfaceLoader::create(
459460
*Context, ModuleCachePath, PrebuiltModuleCachePath,
460461
getDependencyTracker(), MLM, FEOpts.PreferInterfaceForModules,
461-
FEOpts.RemarkOnRebuildFromModuleInterface,
462-
IgnoreSourceInfoFile,
463-
FEOpts.DisableInterfaceFileLock,
464-
FEOpts.DisableImplicitModules);
462+
LoaderOpts,
463+
IgnoreSourceInfoFile);
465464
Context->addModuleLoader(std::move(PIML));
466465
}
467466

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -339,25 +339,19 @@ class ModuleInterfaceLoaderImpl {
339339
const SourceLoc diagnosticLoc;
340340
DependencyTracker *const dependencyTracker;
341341
const ModuleLoadingMode loadMode;
342-
const bool remarkOnRebuildFromInterface;
343-
const bool disableInterfaceLock;
344-
const bool disableImplicitSwiftModule;
342+
ModuleInterfaceLoaderOptions Opts;
345343

346344
ModuleInterfaceLoaderImpl(
347345
ASTContext &ctx, StringRef modulePath, StringRef interfacePath,
348346
StringRef moduleName, StringRef cacheDir, StringRef prebuiltCacheDir,
349-
SourceLoc diagLoc, bool remarkOnRebuildFromInterface,
350-
bool disableInterfaceLock, bool disableImplicitSwiftModule,
347+
SourceLoc diagLoc, ModuleInterfaceLoaderOptions Opts,
351348
DependencyTracker *dependencyTracker = nullptr,
352349
ModuleLoadingMode loadMode = ModuleLoadingMode::PreferSerialized)
353350
: ctx(ctx), fs(*ctx.SourceMgr.getFileSystem()), diags(ctx.Diags),
354351
modulePath(modulePath), interfacePath(interfacePath),
355352
moduleName(moduleName), prebuiltCacheDir(prebuiltCacheDir),
356353
cacheDir(cacheDir), diagnosticLoc(diagLoc),
357-
dependencyTracker(dependencyTracker), loadMode(loadMode),
358-
remarkOnRebuildFromInterface(remarkOnRebuildFromInterface),
359-
disableInterfaceLock(disableInterfaceLock),
360-
disableImplicitSwiftModule(disableImplicitSwiftModule) {}
354+
dependencyTracker(dependencyTracker), loadMode(loadMode), Opts(Opts) {}
361355

362356
/// Constructs the full path of the dependency \p dep by prepending the SDK
363357
/// path if necessary.
@@ -830,21 +824,19 @@ class ModuleInterfaceLoaderImpl {
830824
}
831825
InterfaceSubContextDelegateImpl astDelegate(ctx.SourceMgr, ctx.Diags,
832826
ctx.SearchPathOpts, ctx.LangOpts,
827+
Opts,
833828
ctx.getClangModuleLoader(),
834829
/*buildModuleCacheDirIfAbsent*/true,
835830
cacheDir,
836831
prebuiltCacheDir,
837832
/*serializeDependencyHashes*/false,
838-
trackSystemDependencies,
839-
remarkOnRebuildFromInterface,
840-
disableInterfaceLock,
841-
disableImplicitSwiftModule);
833+
trackSystemDependencies);
842834
// Set up a builder if we need to build the module. It'll also set up
843835
// the subinvocation we'll need to use to compute the cache paths.
844836
ModuleInterfaceBuilder builder(
845837
ctx.SourceMgr, ctx.Diags, astDelegate, interfacePath, moduleName, cacheDir,
846838
prebuiltCacheDir,
847-
disableInterfaceLock, diagnosticLoc,
839+
Opts.disableInterfaceLock, diagnosticLoc,
848840
dependencyTracker);
849841

850842
// Compute the output path if we're loading or emitting a cached module.
@@ -907,7 +899,7 @@ class ModuleInterfaceLoaderImpl {
907899

908900
if (builder.buildSwiftModule(cachedOutputPath, /*shouldSerializeDeps*/true,
909901
&moduleBuffer,
910-
remarkOnRebuildFromInterface ? remarkRebuild:
902+
Opts.remarkOnRebuildFromInterface ? remarkRebuild:
911903
llvm::function_ref<void()>()))
912904
return std::make_error_code(std::errc::invalid_argument);
913905

@@ -967,8 +959,7 @@ std::error_code ModuleInterfaceLoader::findModuleFilesInDirectory(
967959
ModuleInterfaceLoaderImpl Impl(
968960
Ctx, ModPath, InPath, ModuleName,
969961
CacheDir, PrebuiltCacheDir, ModuleID.Loc,
970-
RemarkOnRebuildFromInterface, DisableInterfaceFileLock,
971-
DisableImplicitSwiftModule,
962+
Opts,
972963
dependencyTracker,
973964
llvm::is_contained(PreferInterfaceForModules,
974965
ModuleName) ?
@@ -1008,18 +999,15 @@ bool ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface(
1008999
StringRef CacheDir, StringRef PrebuiltCacheDir,
10091000
StringRef ModuleName, StringRef InPath, StringRef OutPath,
10101001
bool SerializeDependencyHashes, bool TrackSystemDependencies,
1011-
bool RemarkOnRebuildFromInterface, bool DisableInterfaceFileLock,
1012-
bool DisableImplicitSwiftModule) {
1002+
ModuleInterfaceLoaderOptions LoaderOpts) {
10131003
InterfaceSubContextDelegateImpl astDelegate(SourceMgr, Diags,
10141004
SearchPathOpts, LangOpts,
1005+
LoaderOpts,
10151006
/*clangImporter*/nullptr,
10161007
/*CreateCacheDirIfAbsent*/true,
10171008
CacheDir, PrebuiltCacheDir,
10181009
SerializeDependencyHashes,
1019-
TrackSystemDependencies,
1020-
RemarkOnRebuildFromInterface,
1021-
DisableInterfaceFileLock,
1022-
DisableImplicitSwiftModule);
1010+
TrackSystemDependencies);
10231011
// At this point we don't have an ClangImporter instance because the instance
10241012
// is created later when we create a new ASTContext to build the interface.
10251013
// Thus, we have to add these extra clang flags manually here to ensure explict
@@ -1029,7 +1017,7 @@ bool ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface(
10291017
}
10301018
ModuleInterfaceBuilder builder(SourceMgr, Diags, astDelegate, InPath,
10311019
ModuleName, CacheDir, PrebuiltCacheDir,
1032-
DisableInterfaceFileLock);
1020+
LoaderOpts.disableInterfaceLock);
10331021
// FIXME: We really only want to serialize 'important' dependencies here, if
10341022
// we want to ship the built swiftmodules to another machine.
10351023
return builder.buildSwiftModule(OutPath, /*shouldSerializeDeps*/true,
@@ -1183,15 +1171,13 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
11831171
DiagnosticEngine &Diags,
11841172
const SearchPathOptions &searchPathOpts,
11851173
const LangOptions &langOpts,
1174+
ModuleInterfaceLoaderOptions LoaderOpts,
11861175
ClangModuleLoader *clangImporter,
11871176
bool buildModuleCacheDirIfAbsent,
11881177
StringRef moduleCachePath,
11891178
StringRef prebuiltCachePath,
11901179
bool serializeDependencyHashes,
1191-
bool trackSystemDependencies,
1192-
bool remarkOnRebuildFromInterface,
1193-
bool disableInterfaceFileLock,
1194-
bool disableImplicitSwiftModule): SM(SM), Diags(Diags), ArgSaver(Allocator) {
1180+
bool trackSystemDependencies): SM(SM), Diags(Diags), ArgSaver(Allocator) {
11951181
inheritOptionsForBuildingInterface(searchPathOpts, langOpts);
11961182
// Configure front-end input.
11971183
auto &SubFEOpts = subInvocation.getFrontendOptions();
@@ -1211,7 +1197,7 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
12111197
if (trackSystemDependencies) {
12121198
GenericArgs.push_back("-track-system-dependencies");
12131199
}
1214-
if (disableImplicitSwiftModule) {
1200+
if (LoaderOpts.disableImplicitSwiftModule) {
12151201
subInvocation.getFrontendOptions().DisableImplicitModules = true;
12161202
GenericArgs.push_back("-disable-implicit-swift-modules");
12171203
}
@@ -1244,8 +1230,8 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
12441230
// Tell the subinvocation to remark on rebuilds from an interface if asked
12451231
// to do so.
12461232
frontendOpts.RemarkOnRebuildFromModuleInterface =
1247-
remarkOnRebuildFromInterface;
1248-
if (remarkOnRebuildFromInterface) {
1233+
LoaderOpts.remarkOnRebuildFromInterface;
1234+
if (LoaderOpts.remarkOnRebuildFromInterface) {
12491235
GenericArgs.push_back("-Rmodule-interface-rebuild");
12501236
}
12511237

lib/FrontendTool/FrontendTool.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ static bool buildModuleFromInterface(CompilerInstance &Instance) {
778778
assert(FEOpts.InputsAndOutputs.hasSingleInput());
779779
StringRef InputPath = FEOpts.InputsAndOutputs.getFilenameOfFirstInput();
780780
StringRef PrebuiltCachePath = FEOpts.PrebuiltModuleCachePath;
781+
ModuleInterfaceLoaderOptions LoaderOpts(FEOpts);
781782
return ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface(
782783
Instance.getSourceMgr(), Instance.getDiags(),
783784
Invocation.getSearchPathOptions(), Invocation.getLangOptions(),
@@ -786,9 +787,7 @@ static bool buildModuleFromInterface(CompilerInstance &Instance) {
786787
PrebuiltCachePath, Invocation.getModuleName(), InputPath,
787788
Invocation.getOutputFilename(),
788789
FEOpts.SerializeModuleInterfaceDependencyHashes,
789-
FEOpts.TrackSystemDeps, FEOpts.RemarkOnRebuildFromModuleInterface,
790-
FEOpts.DisableInterfaceFileLock,
791-
FEOpts.DisableImplicitModules);
790+
FEOpts.TrackSystemDeps, LoaderOpts);
792791
}
793792

794793
static bool compileLLVMIR(CompilerInstance &Instance) {

lib/FrontendTool/ScanDependencies.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,16 @@ static std::vector<ModuleDependencyID> resolveDirectDependencies(
6969
auto ModuleCachePath = getModuleCachePathFromClang(ctx
7070
.getClangModuleLoader()->getClangInstance());
7171
auto &FEOpts = instance.getInvocation().getFrontendOptions();
72+
ModuleInterfaceLoaderOptions LoaderOpts(FEOpts);
7273
InterfaceSubContextDelegateImpl ASTDelegate(ctx.SourceMgr, ctx.Diags,
7374
ctx.SearchPathOpts, ctx.LangOpts,
75+
LoaderOpts,
7476
ctx.getClangModuleLoader(),
7577
/*buildModuleCacheDirIfAbsent*/false,
7678
ModuleCachePath,
7779
FEOpts.PrebuiltModuleCachePath,
7880
FEOpts.SerializeModuleInterfaceDependencyHashes,
79-
FEOpts.TrackSystemDeps,
80-
FEOpts.RemarkOnRebuildFromModuleInterface,
81-
FEOpts.DisableInterfaceFileLock,
82-
FEOpts.DisableImplicitModules);
81+
FEOpts.TrackSystemDeps);
8382
// Find the dependencies of every module this module directly depends on.
8483
std::vector<ModuleDependencyID> result;
8584
for (auto dependsOn : knownDependencies.getModuleDependencies()) {

0 commit comments

Comments
 (0)