Skip to content

Commit 72caba2

Browse files
authored
Merge pull request #60556 from artemcm/ExplicitInterfaceBuild
Add an option for an explicit interface build without an additional Compile SubInstance
2 parents 5c2f5a2 + aee4579 commit 72caba2

13 files changed

+462
-320
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ WARNING(warning_cannot_find_locale_file,none,
9999
"cannot find translations for '%0' at '%1': no such file", (StringRef, StringRef))
100100
WARNING(warning_cannot_multithread_batch_mode,none,
101101
"ignoring -num-threads argument; cannot multithread batch mode", ())
102-
ERROR(error_cannot_ignore_interface_options_in_mode,none,
103-
"'-ignore-interface-provided-options' only supported when building a module from interface ('-compile-module-from-interface')'", ())
102+
ERROR(error_cannot_explicit_interface_build_in_mode,none,
103+
"'-explicit-interface-module-build' only supported when building a module from interface ('-compile-module-from-interface')'", ())
104104
ERROR(error_unsupported_option_argument,none,
105105
"unsupported argument '%1' to option '%0'", (StringRef, StringRef))
106106
ERROR(error_immediate_mode_missing_stdlib,none,

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: 34 additions & 13 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,
457+
DependencyTracker *tracker = nullptr);
445458
};
446459

447460
struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
@@ -460,13 +473,8 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
460473
InFlightDiagnostic diagnose(StringRef interfacePath,
461474
SourceLoc diagnosticLoc,
462475
Diag<ArgTypes...> ID,
463-
typename detail::PassArgument<ArgTypes>::type... Args) {
464-
SourceLoc loc = diagnosticLoc;
465-
if (diagnosticLoc.isInvalid()) {
466-
// Diagnose this inside the interface file, if possible.
467-
loc = SM.getLocFromExternalSource(interfacePath, 1, 1);
468-
}
469-
return Diags->diagnose(loc, ID, std::move(Args)...);
476+
typename detail::PassArgument<ArgTypes>::type... Args) {
477+
return InterfaceSubContextDelegateImpl::diagnose(interfacePath, diagnosticLoc, SM, Diags, ID, std::move(Args)...);
470478
}
471479
void
472480
inheritOptionsForBuildingInterface(const SearchPathOptions &SearchPathOpts,
@@ -476,8 +484,7 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
476484
SmallVectorImpl<const char *> &SubArgs,
477485
std::string &CompilerVersion,
478486
StringRef interfacePath,
479-
SourceLoc diagnosticLoc,
480-
bool ignoreInterfaceProvidedOptions);
487+
SourceLoc diagnosticLoc);
481488
public:
482489
InterfaceSubContextDelegateImpl(
483490
SourceManager &SM, DiagnosticEngine *Diags,
@@ -488,19 +495,33 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
488495
StringRef backupModuleInterfaceDir,
489496
bool serializeDependencyHashes, bool trackSystemDependencies,
490497
RequireOSSAModules_t requireOSSAModules);
498+
499+
template<typename ...ArgTypes>
500+
static InFlightDiagnostic diagnose(StringRef interfacePath,
501+
SourceLoc diagnosticLoc,
502+
SourceManager &SM,
503+
DiagnosticEngine *Diags,
504+
Diag<ArgTypes...> ID,
505+
typename detail::PassArgument<ArgTypes>::type... Args) {
506+
SourceLoc loc = diagnosticLoc;
507+
if (diagnosticLoc.isInvalid()) {
508+
// Diagnose this inside the interface file, if possible.
509+
loc = SM.getLocFromExternalSource(interfacePath, 1, 1);
510+
}
511+
return Diags->diagnose(loc, ID, std::move(Args)...);
512+
}
513+
491514
std::error_code runInSubContext(StringRef moduleName,
492515
StringRef interfacePath,
493516
StringRef outputPath,
494517
SourceLoc diagLoc,
495-
bool ignoreInterfaceProvidedOptions,
496518
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*,
497519
ArrayRef<StringRef>, ArrayRef<StringRef>,
498520
StringRef)> action) override;
499521
std::error_code runInSubCompilerInstance(StringRef moduleName,
500522
StringRef interfacePath,
501523
StringRef outputPath,
502524
SourceLoc diagLoc,
503-
bool ignoreInterfaceProvidedOptions,
504525
llvm::function_ref<std::error_code(SubCompilerInstanceInfo&)> action) override;
505526

506527
~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: 7 additions & 3 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);
@@ -93,6 +93,10 @@ bool ArgsToFrontendOptionsConverter::convert(
9393
if (Args.hasArg(OPT_track_system_dependencies)) {
9494
Opts.IntermoduleDependencyTracking =
9595
IntermoduleDepTrackingMode::IncludeSystem;
96+
} else if (Args.hasArg(OPT_explicit_interface_module_build)) {
97+
// Always track at least the non-system dependencies for interface building.
98+
Opts.IntermoduleDependencyTracking =
99+
IntermoduleDepTrackingMode::ExcludeSystem;
96100
}
97101

98102
if (const Arg *A = Args.getLastArg(OPT_bad_file_descriptor_retry_count)) {
@@ -622,9 +626,9 @@ bool ArgsToFrontendOptionsConverter::
622626
bool ArgsToFrontendOptionsConverter::checkBuildFromInterfaceOnlyOptions()
623627
const {
624628
if (Opts.RequestedAction != FrontendOptions::ActionType::CompileModuleFromInterface &&
625-
Opts.IgnoreInterfaceProvidedOptions) {
629+
Opts.ExplicitInterfaceBuild) {
626630
Diags.diagnose(SourceLoc(),
627-
diag::error_cannot_ignore_interface_options_in_mode);
631+
diag::error_cannot_explicit_interface_build_in_mode);
628632
return true;
629633
}
630634
return false;

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)