Skip to content

Commit b0577b0

Browse files
authored
Merge pull request swiftlang#34472 from bnbarham/benb/allow-errors-69815975
[Serialization] Add an option to output modules regardless of errors
2 parents e201c73 + 241559d commit b0577b0

21 files changed

+386
-22
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ namespace swift {
367367
/// TODO: remove this when @_implementationOnly modules are robust enough.
368368
bool AllowDeserializingImplementationOnly = false;
369369

370+
// Allow errors during module generation. See corresponding option in
371+
// FrontendOptions.
372+
bool AllowModuleWithCompilerErrors = false;
373+
370374
/// Sets the target we are building for and updates platform conditions
371375
/// to match.
372376
///

include/swift/Frontend/FrontendOptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,12 @@ class FrontendOptions {
290290
/// any merge-modules jobs.
291291
bool EnableExperimentalCrossModuleIncrementalBuild = false;
292292

293+
/// Best effort to output a .swiftmodule regardless of any compilation
294+
/// errors. SIL generation and serialization is skipped entirely when there
295+
/// are errors. The resulting serialized AST may include errors types and
296+
/// skip nodes entirely, depending on the errors involved.
297+
bool AllowModuleWithCompilerErrors = false;
298+
293299
/// The different modes for validating TBD against the LLVM IR.
294300
enum class TBDValidationMode {
295301
Default, ///< Do the default validation for the current platform.

include/swift/Option/FrontendOptions.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,4 +779,9 @@ def experimental_skip_all_function_bodies:
779779
Flag<["-"], "experimental-skip-all-function-bodies">,
780780
HelpText<"Skip type-checking function bodies and all SIL generation">;
781781

782+
def experimental_allow_module_with_compiler_errors:
783+
Flag<["-"], "experimental-allow-module-with-compiler-errors">,
784+
Flags<[HelpHidden]>,
785+
HelpText<"Attempt to output .swiftmodule, regardless of compilation errors">;
786+
782787
} // end let Flags = [FrontendOption, NoDriverOption, HelpHidden]

include/swift/Serialization/Validation.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ class ExtendedValidationInfo {
9898
unsigned IsSIB : 1;
9999
unsigned IsTestable : 1;
100100
unsigned ResilienceStrategy : 2;
101-
unsigned IsImplicitDynamicEnabled: 1;
101+
unsigned IsImplicitDynamicEnabled : 1;
102+
unsigned IsAllowModuleWithCompilerErrorsEnabled : 1;
102103
} Bits;
103104
public:
104105
ExtendedValidationInfo() : Bits() {}
@@ -138,6 +139,12 @@ class ExtendedValidationInfo {
138139
void setResilienceStrategy(ResilienceStrategy resilience) {
139140
Bits.ResilienceStrategy = unsigned(resilience);
140141
}
142+
bool isAllowModuleWithCompilerErrorsEnabled() {
143+
return Bits.IsAllowModuleWithCompilerErrorsEnabled;
144+
}
145+
void setAllowModuleWithCompilerErrorsEnabled(bool val) {
146+
Bits.IsAllowModuleWithCompilerErrorsEnabled = val;
147+
}
141148
};
142149

143150
/// Returns info about the serialized AST in the given data.

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ bool ArgsToFrontendOptionsConverter::convert(
214214
Opts.EnableIncrementalDependencyVerifier |= Args.hasArg(OPT_verify_incremental_dependencies);
215215
Opts.UseSharedResourceFolder = !Args.hasArg(OPT_use_static_resource_dir);
216216
Opts.DisableBuildingInterface = Args.hasArg(OPT_disable_building_interface);
217+
Opts.AllowModuleWithCompilerErrors = Args.hasArg(OPT_experimental_allow_module_with_compiler_errors);
217218

218219
computeImportObjCHeaderOptions();
219220
computeImplicitImportModuleNames(OPT_import_module, /*isTestable=*/false);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
683683
Opts.DisableAvailabilityChecking = true;
684684
}
685685

686+
if (FrontendOpts.AllowModuleWithCompilerErrors) {
687+
Opts.AllowModuleWithCompilerErrors = true;
688+
}
689+
686690
return HadError || UnsupportedOS || UnsupportedArch;
687691
}
688692

lib/Frontend/Frontend.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,8 @@ static void countStatsPostSILOpt(UnifiedStatsReporter &Stats,
11531153
}
11541154

11551155
bool CompilerInstance::performSILProcessing(SILModule *silModule) {
1156-
if (performMandatorySILPasses(Invocation, silModule))
1156+
if (performMandatorySILPasses(Invocation, silModule) &&
1157+
!Invocation.getFrontendOptions().AllowModuleWithCompilerErrors)
11571158
return true;
11581159

11591160
{

lib/FrontendTool/FrontendTool.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,11 +1787,13 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
17871787
assert(ctx.getLoadedModules().begin()->second == Instance.getMainModule());
17881788
}
17891789

1790-
// Verify the AST for all the modules we've loaded.
1791-
ctx.verifyAllLoadedModules();
1790+
if (!opts.AllowModuleWithCompilerErrors) {
1791+
// Verify the AST for all the modules we've loaded.
1792+
ctx.verifyAllLoadedModules();
17921793

1793-
// Verify generic signatures if we've been asked to.
1794-
verifyGenericSignaturesIfNeeded(Invocation, ctx);
1794+
// Verify generic signatures if we've been asked to.
1795+
verifyGenericSignaturesIfNeeded(Invocation, ctx);
1796+
}
17951797

17961798
// Emit any additional outputs that we only need for a successful compilation.
17971799
// We don't want to unnecessarily delay getting any errors back to the user.
@@ -1913,7 +1915,8 @@ withSemanticAnalysis(CompilerInstance &Instance, FrontendObserver *observer,
19131915

19141916
(void)migrator::updateCodeAndEmitRemapIfNeeded(&Instance);
19151917

1916-
if (Instance.getASTContext().hadError())
1918+
if (Instance.getASTContext().hadError() &&
1919+
!opts.AllowModuleWithCompilerErrors)
19171920
return true;
19181921

19191922
return cont(Instance);
@@ -2096,7 +2099,8 @@ static bool performCompile(CompilerInstance &Instance,
20962099
if (Instance.hasASTContext() &&
20972100
FrontendOptions::doesActionPerformEndOfPipelineActions(Action)) {
20982101
performEndOfPipelineActions(Instance);
2099-
hadError |= Instance.getASTContext().hadError();
2102+
if (!opts.AllowModuleWithCompilerErrors)
2103+
hadError |= Instance.getASTContext().hadError();
21002104
}
21012105
return hadError;
21022106
}
@@ -2382,7 +2386,7 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
23822386
if (PSPs.haveModuleOrModuleDocOutputPaths()) {
23832387
if (Action == FrontendOptions::ActionType::MergeModules ||
23842388
Action == FrontendOptions::ActionType::EmitModuleOnly) {
2385-
return Context.hadError();
2389+
return Context.hadError() && !opts.AllowModuleWithCompilerErrors;
23862390
}
23872391
}
23882392

@@ -2400,7 +2404,7 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
24002404

24012405
// Check if we had any errors; if we did, don't proceed to IRGen.
24022406
if (Context.hadError())
2403-
return true;
2407+
return !opts.AllowModuleWithCompilerErrors;
24042408

24052409
runSILLoweringPasses(*SM);
24062410

lib/SILGen/SILGen.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,6 +1952,11 @@ ASTLoweringRequest::evaluate(Evaluator &evaluator,
19521952
if (desc.opts.SkipFunctionBodies == FunctionBodySkipping::All)
19531953
return silMod;
19541954

1955+
// Skip emitting SIL if there's been any compilation errors
1956+
if (silMod->getASTContext().hadError() &&
1957+
silMod->getASTContext().LangOpts.AllowModuleWithCompilerErrors)
1958+
return silMod;
1959+
19551960
SILGenModuleRAII scope(*silMod);
19561961

19571962
// Emit a specific set of SILDeclRefs if needed.

lib/Sema/TypeCheckStorage.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,6 +2308,8 @@ IsAccessorTransparentRequest::evaluate(Evaluator &evaluator,
23082308
// Anything else should not have a synthesized setter.
23092309
LLVM_FALLTHROUGH;
23102310
case WriteImplKind::Immutable:
2311+
if (accessor->getASTContext().LangOpts.AllowModuleWithCompilerErrors)
2312+
return false;
23112313
llvm_unreachable("should not be synthesizing accessor in this case");
23122314

23132315
case WriteImplKind::StoredWithObservers:

0 commit comments

Comments
 (0)