Skip to content

[5.5][Frontend] Do not output swiftinterface when there has been errors #37548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@ static void emitIndexData(const CompilerInstance &Instance) {
/// anything past type-checking.
static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
CompilerInstance &Instance) {
const auto &Context = Instance.getASTContext();
const auto &Invocation = Instance.getInvocation();
const FrontendOptions &opts = Invocation.getFrontendOptions();

Expand All @@ -833,7 +834,8 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
// failure does not mean skipping the rest.
bool hadAnyError = false;

if (opts.InputsAndOutputs.hasObjCHeaderOutputPath()) {
if ((!Context.hadError() || opts.AllowModuleWithCompilerErrors) &&
opts.InputsAndOutputs.hasObjCHeaderOutputPath()) {
std::string BridgingHeaderPathForPrint;
if (!opts.ImplicitObjCHeaderPath.empty()) {
if (opts.BridgingHeaderDirForPrint.hasValue()) {
Expand All @@ -853,6 +855,11 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
Invocation.isModuleExternallyConsumed(Instance.getMainModule()));
}

// Only want the header if there's been any errors, ie. there's not much
// point outputting a swiftinterface for an invalid module
if (Context.hadError())
return hadAnyError;

if (opts.InputsAndOutputs.hasModuleInterfaceOutputPath()) {
hadAnyError |= printModuleInterfaceIfNeeded(
Invocation.getModuleInterfaceOutputPathForWholeModule(),
Expand Down Expand Up @@ -995,9 +1002,10 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {

dumpAPIIfNeeded(Instance);
}
if (!ctx.hadError() || opts.AllowModuleWithCompilerErrors) {
emitAnyWholeModulePostTypeCheckSupplementaryOutputs(Instance);
}

// Contains the hadError checks internally, we still want to output the
// Objective-C header when there's errors and currently allowing them
emitAnyWholeModulePostTypeCheckSupplementaryOutputs(Instance);

// Verify reference dependencies of the current compilation job. Note this
// must be run *before* verifying diagnostics so that the former can be tested
Expand Down
13 changes: 10 additions & 3 deletions test/Frontend/allow-errors.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/mods)
// RUN: touch %t/empty.swift

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

// 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
// RUN: llvm-bcanalyzer %t/errors.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s
// RUN: ls %t/errors.swiftdeps %t/errors.d %t/errors.swiftsourceinfo %t/errors.swiftdoc
// 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
// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/mods/errorsempty.partial.swiftmodule %t/empty.swift
// 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

// RUN: llvm-bcanalyzer %t/mods/errors.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s
// RUN: ls %t/mods/errorsmain.partial.swiftdeps %t/mods/errors.d %t/mods/errors.swiftsourceinfo %t/mods/errors.swiftdoc %t/mods/errors.h
// RUN: not ls %t/mods/errors.swiftinterface
// RUN: not ls %t/mods/errors.tbd
// CHECK-BC-NOT: UnknownCode

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