Skip to content

Commit 747be58

Browse files
committed
[Frontend] Do not output swiftinterface when there has been errors
When allowing errors with -experimental-allow-module-with-compiler-errors, do not output the .swiftinterface when there has been errors. There's no real need to output them for invalid modules, so this avoids module interface printing having to have checks for normally-impossible cases. Resolves rdar://78039608.
1 parent 41e3332 commit 747be58

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ static void emitIndexData(const CompilerInstance &Instance) {
816816
/// anything past type-checking.
817817
static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
818818
CompilerInstance &Instance) {
819+
const auto &Context = Instance.getASTContext();
819820
const auto &Invocation = Instance.getInvocation();
820821
const FrontendOptions &opts = Invocation.getFrontendOptions();
821822

@@ -834,7 +835,8 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
834835
// failure does not mean skipping the rest.
835836
bool hadAnyError = false;
836837

837-
if (opts.InputsAndOutputs.hasObjCHeaderOutputPath()) {
838+
if ((!Context.hadError() || opts.AllowModuleWithCompilerErrors) &&
839+
opts.InputsAndOutputs.hasObjCHeaderOutputPath()) {
838840
std::string BridgingHeaderPathForPrint;
839841
if (!opts.ImplicitObjCHeaderPath.empty()) {
840842
if (opts.BridgingHeaderDirForPrint.hasValue()) {
@@ -854,6 +856,11 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
854856
Invocation.isModuleExternallyConsumed(Instance.getMainModule()));
855857
}
856858

859+
// Only want the header if there's been any errors, ie. there's not much
860+
// point outputting a swiftinterface for an invalid module
861+
if (Context.hadError())
862+
return hadAnyError;
863+
857864
if (opts.InputsAndOutputs.hasModuleInterfaceOutputPath()) {
858865
hadAnyError |= printModuleInterfaceIfNeeded(
859866
Invocation.getModuleInterfaceOutputPathForWholeModule(),
@@ -996,9 +1003,10 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
9961003

9971004
dumpAPIIfNeeded(Instance);
9981005
}
999-
if (!ctx.hadError() || opts.AllowModuleWithCompilerErrors) {
1000-
emitAnyWholeModulePostTypeCheckSupplementaryOutputs(Instance);
1001-
}
1006+
1007+
// Contains the hadError checks internally, we still want to output the
1008+
// Objective-C header when there's errors and currently allowing them
1009+
emitAnyWholeModulePostTypeCheckSupplementaryOutputs(Instance);
10021010

10031011
// Verify reference dependencies of the current compilation job. Note this
10041012
// must be run *before* verifying diagnostics so that the former can be tested

test/Frontend/allow-errors.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/mods)
3+
// RUN: touch %t/empty.swift
24

35
// The module should be generated regardless of errors, including .swiftdeps, .d,
46
// .swiftsourceinfo, etc. Diagnostics should still be output as well
57

6-
// RUN: %target-swift-frontend -verify -emit-module -o %t/errors.swiftmodule -emit-module-source-info -emit-module-doc -emit-reference-dependencies-path %t/errors.swiftdeps -emit-dependencies-path %t/errors.d -experimental-allow-module-with-compiler-errors -primary-file %s
7-
// RUN: llvm-bcanalyzer %t/errors.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s
8-
// RUN: ls %t/errors.swiftdeps %t/errors.d %t/errors.swiftsourceinfo %t/errors.swiftdoc
8+
// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/mods/errorsmain.partial.swiftmodule -emit-reference-dependencies-path %t/mods/errorsmain.partial.swiftdeps -experimental-allow-module-with-compiler-errors -primary-file %s
9+
// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/mods/errorsempty.partial.swiftmodule %t/empty.swift
10+
// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/mods/errors.swiftmodule -experimental-allow-module-with-compiler-errors %t/mods/errorsmain.partial.swiftmodule %t/mods/errorsempty.partial.swiftmodule -emit-module-source-info -emit-module-doc -emit-dependencies-path %t/mods/errors.d -emit-objc-header -emit-objc-header-path %t/mods/errors.h -emit-module-interface-path %t/mods/errors.swiftinterface -emit-tbd-path %t/mods/errors.tbd
11+
12+
// RUN: llvm-bcanalyzer %t/mods/errors.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s
13+
// RUN: ls %t/mods/errorsmain.partial.swiftdeps %t/mods/errors.d %t/mods/errors.swiftsourceinfo %t/mods/errors.swiftdoc %t/mods/errors.h
14+
// RUN: not ls %t/mods/errors.swiftinterface
15+
// RUN: not ls %t/mods/errors.tbd
916
// CHECK-BC-NOT: UnknownCode
1017

1118
public func invalid() -> undefined {} // expected-error {{cannot find type 'undefined'}}

0 commit comments

Comments
 (0)