Skip to content

Commit 2a55d28

Browse files
committed
Refactor 'ModuleInterfaceBuilder' to separate CompilerInstance setup logic from compilation logic (moved to ExplicitModuleInterfaceBuilder).
1 parent e5a35f9 commit 2a55d28

File tree

11 files changed

+357
-263
lines changed

11 files changed

+357
-263
lines changed

include/swift/AST/ModuleLoader.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,13 @@ struct InterfaceSubContextDelegate {
165165
StringRef interfacePath,
166166
StringRef outputPath,
167167
SourceLoc diagLoc,
168-
bool ignoreInterfaceProvidedOptions,
169168
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*,
170169
ArrayRef<StringRef>,
171170
ArrayRef<StringRef>, StringRef)> action) = 0;
172171
virtual std::error_code runInSubCompilerInstance(StringRef moduleName,
173172
StringRef interfacePath,
174173
StringRef outputPath,
175174
SourceLoc diagLoc,
176-
bool ignoreInterfaceProvidedOptions,
177175
llvm::function_ref<std::error_code(SubCompilerInstanceInfo&)> action) = 0;
178176

179177
virtual ~InterfaceSubContextDelegate() = default;

include/swift/Frontend/FrontendOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class FrontendOptions {
110110

111111
/// If building a module from interface, ignore compiler flags
112112
/// specified in the swiftinterface.
113-
bool IgnoreInterfaceProvidedOptions = false;
113+
bool ExplicitInterfaceBuild = false;
114114

115115
/// The module for which we should verify all of the generic signatures.
116116
std::string VerifyGenericSignaturesInModule;

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,15 +300,13 @@ struct ModuleInterfaceLoaderOptions {
300300
bool disableImplicitSwiftModule = false;
301301
bool disableBuildingInterface = false;
302302
bool downgradeInterfaceVerificationError = false;
303-
bool ignoreInterfaceProvidedOptions = false;
304303
std::string mainExecutablePath;
305304
ModuleInterfaceLoaderOptions(const FrontendOptions &Opts):
306305
remarkOnRebuildFromInterface(Opts.RemarkOnRebuildFromModuleInterface),
307306
disableInterfaceLock(Opts.DisableInterfaceFileLock),
308307
disableImplicitSwiftModule(Opts.DisableImplicitModules),
309308
disableBuildingInterface(Opts.DisableBuildingInterface),
310309
downgradeInterfaceVerificationError(Opts.DowngradeInterfaceVerificationError),
311-
ignoreInterfaceProvidedOptions(Opts.IgnoreInterfaceProvidedOptions),
312310
mainExecutablePath(Opts.MainExecutablePath)
313311
{
314312
switch (Opts.RequestedAction) {
@@ -442,6 +440,21 @@ class ModuleInterfaceLoader : public SerializedModuleLoaderBase {
442440
bool SerializeDependencyHashes,
443441
bool TrackSystemDependencies, ModuleInterfaceLoaderOptions Opts,
444442
RequireOSSAModules_t RequireOSSAModules);
443+
444+
/// Unconditionally build \p InPath (a swiftinterface file) to \p OutPath (as
445+
/// a swiftmodule file).
446+
///
447+
/// Unlike the above `buildSwiftModuleFromSwiftInterface`, this method
448+
/// bypasses the instantiation of a `CompilerInstance` from the compiler
449+
/// configuration flags in the interface and instead directly uses the
450+
/// supplied \p Instance
451+
static bool buildExplicitSwiftModuleFromSwiftInterface(
452+
CompilerInstance &Instance, const StringRef moduleCachePath,
453+
const StringRef backupInterfaceDir, const StringRef prebuiltCachePath,
454+
const StringRef ABIDescriptorPath, StringRef interfacePath,
455+
StringRef outputPath, bool ShouldSerializeDeps,
456+
ArrayRef<std::string> CompiledCandidates, StringRef CompilerVersion,
457+
DependencyTracker *tracker = nullptr);
445458
};
446459

447460
struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
@@ -476,8 +489,7 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
476489
SmallVectorImpl<const char *> &SubArgs,
477490
std::string &CompilerVersion,
478491
StringRef interfacePath,
479-
SourceLoc diagnosticLoc,
480-
bool ignoreInterfaceProvidedOptions);
492+
SourceLoc diagnosticLoc);
481493
public:
482494
InterfaceSubContextDelegateImpl(
483495
SourceManager &SM, DiagnosticEngine *Diags,
@@ -492,15 +504,13 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
492504
StringRef interfacePath,
493505
StringRef outputPath,
494506
SourceLoc diagLoc,
495-
bool ignoreInterfaceProvidedOptions,
496507
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*,
497508
ArrayRef<StringRef>, ArrayRef<StringRef>,
498509
StringRef)> action) override;
499510
std::error_code runInSubCompilerInstance(StringRef moduleName,
500511
StringRef interfacePath,
501512
StringRef outputPath,
502513
SourceLoc diagLoc,
503-
bool ignoreInterfaceProvidedOptions,
504514
llvm::function_ref<std::error_code(SubCompilerInstanceInfo&)> action) override;
505515

506516
~InterfaceSubContextDelegateImpl() = default;

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -877,9 +877,9 @@ def compile_module_from_interface :
877877
HelpText<"Treat the (single) input as a swiftinterface and produce a module">,
878878
ModeOpt;
879879

880-
def ignore_interface_provided_options :
881-
Flag<["-"], "ignore-interface-provided-options">,
882-
HelpText<"Ignore all module flags specified in the swiftinterface being built">;
880+
def explicit_interface_module_build :
881+
Flag<["-"], "explicit-interface-module-build">,
882+
HelpText<"Use the specified command-line to build the module from interface, instead of flags specified in the interface">;
883883

884884
def build_module_from_parseable_interface :
885885
Flag<["-"], "build-module-from-parseable-interface">,

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ bool ArgsToFrontendOptionsConverter::convert(
8383
Opts.EnablePrivateImports |= Args.hasArg(OPT_enable_private_imports);
8484
Opts.EnableLibraryEvolution |= Args.hasArg(OPT_enable_library_evolution);
8585
Opts.FrontendParseableOutput |= Args.hasArg(OPT_frontend_parseable_output);
86-
Opts.IgnoreInterfaceProvidedOptions |= Args.hasArg(OPT_ignore_interface_provided_options);
86+
Opts.ExplicitInterfaceBuild |= Args.hasArg(OPT_explicit_interface_module_build);
8787

8888
// FIXME: Remove this flag
8989
Opts.EnableLibraryEvolution |= Args.hasArg(OPT_enable_resilience);
@@ -622,7 +622,7 @@ bool ArgsToFrontendOptionsConverter::
622622
bool ArgsToFrontendOptionsConverter::checkBuildFromInterfaceOnlyOptions()
623623
const {
624624
if (Opts.RequestedAction != FrontendOptions::ActionType::CompileModuleFromInterface &&
625-
Opts.IgnoreInterfaceProvidedOptions) {
625+
Opts.ExplicitInterfaceBuild) {
626626
Diags.diagnose(SourceLoc(),
627627
diag::error_cannot_ignore_interface_options_in_mode);
628628
return true;

lib/Frontend/Frontend.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,11 @@ void CompilerInstance::recordPrimaryInputBuffer(unsigned BufID) {
211211
}
212212

213213
bool CompilerInstance::setUpASTContextIfNeeded() {
214-
if (Invocation.getFrontendOptions().RequestedAction ==
214+
if ((Invocation.getFrontendOptions().RequestedAction ==
215215
FrontendOptions::ActionType::CompileModuleFromInterface ||
216216
Invocation.getFrontendOptions().RequestedAction ==
217-
FrontendOptions::ActionType::TypecheckModuleFromInterface) {
217+
FrontendOptions::ActionType::TypecheckModuleFromInterface) &&
218+
!Invocation.getFrontendOptions().ExplicitInterfaceBuild) {
218219
// Compiling a module interface from source uses its own CompilerInstance
219220
// with options read from the input file. Don't bother setting up an
220221
// ASTContext at this level.

0 commit comments

Comments
 (0)