Skip to content

Commit 3c5ae23

Browse files
committed
Frontend: Honor warning suppression when parsing arguments from swiftinterfaces.
Diagnostics are suppressed when parsing swiftinterface files, since the warnings emitted from compiling the swiftinterface of a dependency would just be a nuisance. It follows that warnings generated when parsing the arguments in a swiftinterface file should also be suppressed, but that wasn't happening because the diagnostic engine of the main compile was used for parsing. Pass the diagnostic engine of the compiler subinstance instead, and proactively suppress warnings before parsing begins. Resolves rdar://142814164.
1 parent 8dd7669 commit 3c5ae23

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,11 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
654654
bool suppressRemarks,
655655
RequireOSSAModules_t requireOSSAModules);
656656
bool extractSwiftInterfaceVersionAndArgs(CompilerInvocation &subInvocation,
657+
DiagnosticEngine &subInstanceDiags,
657658
SwiftInterfaceInfo &interfaceInfo,
658659
StringRef interfacePath,
659660
SourceLoc diagnosticLoc);
661+
660662
public:
661663
InterfaceSubContextDelegateImpl(
662664
SourceManager &SM, DiagnosticEngine *Diags,

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,8 +1814,9 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
18141814
}
18151815

18161816
bool InterfaceSubContextDelegateImpl::extractSwiftInterfaceVersionAndArgs(
1817-
CompilerInvocation &subInvocation, SwiftInterfaceInfo &interfaceInfo,
1818-
StringRef interfacePath, SourceLoc diagnosticLoc) {
1817+
CompilerInvocation &subInvocation, DiagnosticEngine &subInstanceDiags,
1818+
SwiftInterfaceInfo &interfaceInfo, StringRef interfacePath,
1819+
SourceLoc diagnosticLoc) {
18191820
if (readSwiftInterfaceVersionAndArgs(SM, *Diags, ArgSaver, interfaceInfo,
18201821
interfacePath, diagnosticLoc,
18211822
subInvocation.getLangOptions().Target))
@@ -1833,7 +1834,7 @@ bool InterfaceSubContextDelegateImpl::extractSwiftInterfaceVersionAndArgs(
18331834
}
18341835

18351836
SmallString<32> ExpectedModuleName = subInvocation.getModuleName();
1836-
if (subInvocation.parseArgs(interfaceInfo.Arguments, *Diags)) {
1837+
if (subInvocation.parseArgs(interfaceInfo.Arguments, subInstanceDiags)) {
18371838
return true;
18381839
}
18391840

@@ -2236,11 +2237,25 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
22362237
subInvocation.getFrontendOptions().InputsAndOutputs
22372238
.setMainAndSupplementaryOutputs(outputFiles, ModuleOutputPaths);
22382239

2240+
CompilerInstance subInstance;
2241+
ForwardingDiagnosticConsumer FDC(*Diags);
2242+
NullDiagnosticConsumer noopConsumer;
2243+
if (!silenceErrors) {
2244+
subInstance.addDiagnosticConsumer(&FDC);
2245+
} else {
2246+
subInstance.addDiagnosticConsumer(&noopConsumer);
2247+
}
2248+
2249+
// Eagerly suppress warnings if necessary, before parsing arguments.
2250+
if (subInvocation.getDiagnosticOptions().SuppressWarnings)
2251+
subInstance.getDiags().setSuppressWarnings(true);
2252+
22392253
SwiftInterfaceInfo interfaceInfo;
22402254
// Extract compiler arguments from the interface file and use them to configure
22412255
// the compiler invocation.
2242-
if (extractSwiftInterfaceVersionAndArgs(subInvocation, interfaceInfo,
2243-
interfacePath, diagLoc)) {
2256+
if (extractSwiftInterfaceVersionAndArgs(subInvocation, subInstance.getDiags(),
2257+
interfaceInfo, interfacePath,
2258+
diagLoc)) {
22442259
return std::make_error_code(std::errc::not_supported);
22452260
}
22462261

@@ -2252,21 +2267,12 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
22522267
subInvocation.getFrontendOptions().StrictImplicitModuleContext =
22532268
StrictImplicitModuleContext;
22542269

2255-
CompilerInstance subInstance;
22562270
SubCompilerInstanceInfo info;
22572271
info.Instance = &subInstance;
22582272
info.CompilerVersion = interfaceInfo.CompilerVersion;
22592273

22602274
subInstance.getSourceMgr().setFileSystem(SM.getFileSystem());
22612275

2262-
ForwardingDiagnosticConsumer FDC(*Diags);
2263-
NullDiagnosticConsumer noopConsumer;
2264-
if (!silenceErrors) {
2265-
subInstance.addDiagnosticConsumer(&FDC);
2266-
} else {
2267-
subInstance.addDiagnosticConsumer(&noopConsumer);
2268-
}
2269-
22702276
std::string InstanceSetupError;
22712277
if (subInstance.setup(subInvocation, InstanceSetupError)) {
22722278
return std::make_error_code(std::errc::not_supported);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-module-flags: -module-name SuppressWarnings -swift-version 6 -enable-upcoming-feature ConciseMagicFile
3+
4+
import Swift
5+
6+
@inlinable public func neverMutated() {
7+
var x = 1
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-swift-frontend -compile-module-from-interface %S/Inputs/suppress-warnings/SuppressWarnings.swiftinterface -o /dev/null -module-name SuppressWarnings 2>&1 | %FileCheck %s --allow-empty
2+
// RUN: %target-swift-frontend -typecheck %s -I %S/Inputs/suppress-warnings/ 2>&1 | %FileCheck %s --allow-empty
3+
4+
// Warnings should not be emitted when compiling SuppressWarnings from its interface
5+
// CHECK-NOT: warning
6+
7+
import SuppressWarnings

0 commit comments

Comments
 (0)