Skip to content

[5.10 🍒][Explicit Modules] Fix detection of a type-checking action in 'ExplicitModuleInterfaceBuilder' #68599

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
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
4 changes: 4 additions & 0 deletions include/swift/Frontend/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,10 @@ class CompilerInstance {
/// Whether this compiler instance supports caching.
bool supportCaching() const;

/// Whether errors during interface verification can be downgrated
/// to warnings.
bool downgradeInterfaceVerificationErrors() const;

/// Gets the SourceFile which is the primary input for this CompilerInstance.
/// \returns the primary SourceFile, or nullptr if there is no primary input;
/// if there are _multiple_ primary inputs, fails with an assertion.
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,9 @@ class FrontendOptions {
/// Whether we're configured to track system intermodule dependencies.
bool shouldTrackSystemDependencies() const;

/// Whether we are configured with -typecheck or -typecheck-module-from-interface actuin
bool isTypeCheckAction() const;

/// Whether to emit symbol graphs for the output module.
bool EmitSymbolGraph = false;

Expand Down
12 changes: 12 additions & 0 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,18 @@ bool CompilerInstance::supportCaching() const {
Invocation.getFrontendOptions().RequestedAction);
}

bool CompilerInstance::downgradeInterfaceVerificationErrors() const {
auto &FrontendOpts = Invocation.getFrontendOptions();
if (Context->blockListConfig.hasBlockListAction(FrontendOpts.ModuleName,
BlockListKeyKind::ModuleName,
BlockListAction::DowngradeInterfaceVerificationFailure)) {
Context->Diags.diagnose(SourceLoc(), diag::interface_block_listed_broken,
FrontendOpts.ModuleName);
return true;
}
return FrontendOpts.DowngradeInterfaceVerificationError;
}

ImplicitImportInfo CompilerInstance::getImplicitImportInfo() const {
auto &frontendOpts = Invocation.getFrontendOptions();

Expand Down
5 changes: 5 additions & 0 deletions lib/Frontend/FrontendOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,3 +928,8 @@ bool FrontendOptions::shouldTrackSystemDependencies() const {
return IntermoduleDependencyTracking ==
IntermoduleDepTrackingMode::IncludeSystem;
}

bool FrontendOptions::isTypeCheckAction() const {
return RequestedAction == FrontendOptions::ActionType::Typecheck ||
RequestedAction == FrontendOptions::ActionType::TypecheckModuleFromInterface;
}
17 changes: 2 additions & 15 deletions lib/Frontend/ModuleInterfaceBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,6 @@ bool ExplicitModuleInterfaceBuilder::collectDepsForSerialization(
return false;
}

static bool shouldDowngradeInterfaceVerificationError(const FrontendOptions &opts,
ASTContext &ctx) {
if (ctx.blockListConfig.hasBlockListAction(opts.ModuleName,
BlockListKeyKind::ModuleName,
BlockListAction::DowngradeInterfaceVerificationFailure)) {
ctx.Diags.diagnose(SourceLoc(), diag::interface_block_listed_broken,
opts.ModuleName);
return true;
}
return opts.DowngradeInterfaceVerificationError;
}

std::error_code ExplicitModuleInterfaceBuilder::buildSwiftModuleFromInterface(
StringRef InterfacePath, StringRef OutputPath, bool ShouldSerializeDeps,
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer,
Expand All @@ -214,8 +202,7 @@ std::error_code ExplicitModuleInterfaceBuilder::buildSwiftModuleFromInterface(
return std::error_code();
}
FrontendOptions &FEOpts = Invocation.getFrontendOptions();
bool isTypeChecking =
(FEOpts.RequestedAction == FrontendOptions::ActionType::Typecheck);
bool isTypeChecking = FEOpts.isTypeCheckAction();
const auto &InputInfo = FEOpts.InputsAndOutputs.firstInput();
StringRef InPath = InputInfo.getFileName();

Expand All @@ -227,7 +214,7 @@ std::error_code ExplicitModuleInterfaceBuilder::buildSwiftModuleFromInterface(

LLVM_DEBUG(llvm::dbgs() << "Performing sema\n");
if (isTypeChecking &&
shouldDowngradeInterfaceVerificationError(FEOpts, Instance.getASTContext())) {
Instance.downgradeInterfaceVerificationErrors()) {
ErrorDowngradeConsumerRAII R(Instance.getDiags());
Instance.performSema();
return std::error_code();
Expand Down
6 changes: 5 additions & 1 deletion lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1464,13 +1464,17 @@ static bool performCompile(CompilerInstance &Instance,
}() && "Only supports parsing .swift files");

bool hadError = performAction(Instance, ReturnValue, observer);
auto canIgnoreErrorForExit = [&Instance, &opts]() {
return opts.AllowModuleWithCompilerErrors ||
(opts.isTypeCheckAction() && Instance.downgradeInterfaceVerificationErrors());
};

// We might have freed the ASTContext already, but in that case we would
// have already performed these actions.
if (Instance.hasASTContext() &&
FrontendOptions::doesActionPerformEndOfPipelineActions(Action)) {
performEndOfPipelineActions(Instance);
if (!opts.AllowModuleWithCompilerErrors)
if (!canIgnoreErrorForExit())
hadError |= Instance.getASTContext().hadError();
}
return hadError;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %empty-directory(%t)
// RUN: echo "// swift-interface-format-version: 1.0" > %t/Main.swiftinterface
// RUN: echo "// swift-module-flags: -module-name Foo" >> %t/Main.swiftinterface
// RUN: echo "malfunctioned" >> %t/Main.swiftinterface

// Verify with '-downgrade-typecheck-interface-error'
// RUN: %target-swift-frontend -typecheck-module-from-interface %t/Main.swiftinterface -module-name Foo -downgrade-typecheck-interface-error -explicit-interface-module-build 2>&1 | %FileCheck %s

// Verify with a blocklist
// RUN: echo "---" > %t/blocklist.yml
// RUN: echo "DowngradeInterfaceVerificationFailure:" >> %t/blocklist.yml
// RUN: echo " ModuleName:" >> %t/blocklist.yml
// RUN: echo " - Foo" >> %t/blocklist.yml
// RUN: %target-swift-frontend -typecheck-module-from-interface %t/Main.swiftinterface -module-name Foo -blocklist-file %t/blocklist.yml -explicit-interface-module-build 2>&1 | %FileCheck %s

// CHECK: warning:
// CHECK-NOT: error: