Skip to content

Commit 8b97d43

Browse files
authored
Merge pull request #68598 from artemcm/ExplicitInterfaceTypecheckFix
[Explicit Modules] Fix detection of a type-checking action in `ExplicitModuleInterfaceBuilder`
2 parents b714554 + 373d491 commit 8b97d43

File tree

7 files changed

+48
-16
lines changed

7 files changed

+48
-16
lines changed

include/swift/Frontend/Frontend.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,10 @@ class CompilerInstance {
641641
/// Whether this compiler instance supports caching.
642642
bool supportCaching() const;
643643

644+
/// Whether errors during interface verification can be downgrated
645+
/// to warnings.
646+
bool downgradeInterfaceVerificationErrors() const;
647+
644648
/// Gets the SourceFile which is the primary input for this CompilerInstance.
645649
/// \returns the primary SourceFile, or nullptr if there is no primary input;
646650
/// if there are _multiple_ primary inputs, fails with an assertion.

include/swift/Frontend/FrontendOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@ class FrontendOptions {
507507
/// Whether we're configured to track system intermodule dependencies.
508508
bool shouldTrackSystemDependencies() const;
509509

510+
/// Whether we are configured with -typecheck or -typecheck-module-from-interface actuin
511+
bool isTypeCheckAction() const;
512+
510513
/// Whether to emit symbol graphs for the output module.
511514
bool EmitSymbolGraph = false;
512515

lib/Frontend/Frontend.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,18 @@ bool CompilerInstance::supportCaching() const {
11301130
Invocation.getFrontendOptions().RequestedAction);
11311131
}
11321132

1133+
bool CompilerInstance::downgradeInterfaceVerificationErrors() const {
1134+
auto &FrontendOpts = Invocation.getFrontendOptions();
1135+
if (Context->blockListConfig.hasBlockListAction(FrontendOpts.ModuleName,
1136+
BlockListKeyKind::ModuleName,
1137+
BlockListAction::DowngradeInterfaceVerificationFailure)) {
1138+
Context->Diags.diagnose(SourceLoc(), diag::interface_block_listed_broken,
1139+
FrontendOpts.ModuleName);
1140+
return true;
1141+
}
1142+
return FrontendOpts.DowngradeInterfaceVerificationError;
1143+
}
1144+
11331145
ImplicitImportInfo CompilerInstance::getImplicitImportInfo() const {
11341146
auto &frontendOpts = Invocation.getFrontendOptions();
11351147

lib/Frontend/FrontendOptions.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,3 +928,8 @@ bool FrontendOptions::shouldTrackSystemDependencies() const {
928928
return IntermoduleDependencyTracking ==
929929
IntermoduleDepTrackingMode::IncludeSystem;
930930
}
931+
932+
bool FrontendOptions::isTypeCheckAction() const {
933+
return RequestedAction == FrontendOptions::ActionType::Typecheck ||
934+
RequestedAction == FrontendOptions::ActionType::TypecheckModuleFromInterface;
935+
}

lib/Frontend/ModuleInterfaceBuilder.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,6 @@ bool ExplicitModuleInterfaceBuilder::collectDepsForSerialization(
187187
return false;
188188
}
189189

190-
static bool shouldDowngradeInterfaceVerificationError(const FrontendOptions &opts,
191-
ASTContext &ctx) {
192-
if (ctx.blockListConfig.hasBlockListAction(opts.ModuleName,
193-
BlockListKeyKind::ModuleName,
194-
BlockListAction::DowngradeInterfaceVerificationFailure)) {
195-
ctx.Diags.diagnose(SourceLoc(), diag::interface_block_listed_broken,
196-
opts.ModuleName);
197-
return true;
198-
}
199-
return opts.DowngradeInterfaceVerificationError;
200-
}
201-
202190
std::error_code ExplicitModuleInterfaceBuilder::buildSwiftModuleFromInterface(
203191
StringRef InterfacePath, StringRef OutputPath, bool ShouldSerializeDeps,
204192
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer,
@@ -214,8 +202,7 @@ std::error_code ExplicitModuleInterfaceBuilder::buildSwiftModuleFromInterface(
214202
return std::error_code();
215203
}
216204
FrontendOptions &FEOpts = Invocation.getFrontendOptions();
217-
bool isTypeChecking =
218-
(FEOpts.RequestedAction == FrontendOptions::ActionType::Typecheck);
205+
bool isTypeChecking = FEOpts.isTypeCheckAction();
219206
const auto &InputInfo = FEOpts.InputsAndOutputs.firstInput();
220207
StringRef InPath = InputInfo.getFileName();
221208

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

228215
LLVM_DEBUG(llvm::dbgs() << "Performing sema\n");
229216
if (isTypeChecking &&
230-
shouldDowngradeInterfaceVerificationError(FEOpts, Instance.getASTContext())) {
217+
Instance.downgradeInterfaceVerificationErrors()) {
231218
ErrorDowngradeConsumerRAII R(Instance.getDiags());
232219
Instance.performSema();
233220
return std::error_code();

lib/FrontendTool/FrontendTool.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1464,13 +1464,17 @@ static bool performCompile(CompilerInstance &Instance,
14641464
}() && "Only supports parsing .swift files");
14651465

14661466
bool hadError = performAction(Instance, ReturnValue, observer);
1467+
auto canIgnoreErrorForExit = [&Instance, &opts]() {
1468+
return opts.AllowModuleWithCompilerErrors ||
1469+
(opts.isTypeCheckAction() && Instance.downgradeInterfaceVerificationErrors());
1470+
};
14671471

14681472
// We might have freed the ASTContext already, but in that case we would
14691473
// have already performed these actions.
14701474
if (Instance.hasASTContext() &&
14711475
FrontendOptions::doesActionPerformEndOfPipelineActions(Action)) {
14721476
performEndOfPipelineActions(Instance);
1473-
if (!opts.AllowModuleWithCompilerErrors)
1477+
if (!canIgnoreErrorForExit())
14741478
hadError |= Instance.getASTContext().hadError();
14751479
}
14761480
return hadError;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: echo "// swift-interface-format-version: 1.0" > %t/Main.swiftinterface
3+
// RUN: echo "// swift-module-flags: -module-name Foo" >> %t/Main.swiftinterface
4+
// RUN: echo "malfunctioned" >> %t/Main.swiftinterface
5+
6+
// Verify with '-downgrade-typecheck-interface-error'
7+
// 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
8+
9+
// Verify with a blocklist
10+
// RUN: echo "---" > %t/blocklist.yml
11+
// RUN: echo "DowngradeInterfaceVerificationFailure:" >> %t/blocklist.yml
12+
// RUN: echo " ModuleName:" >> %t/blocklist.yml
13+
// RUN: echo " - Foo" >> %t/blocklist.yml
14+
// 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
15+
16+
// CHECK: warning:
17+
// CHECK-NOT: error:

0 commit comments

Comments
 (0)