Skip to content

Commit 813c0d6

Browse files
committed
Move import warning silencing logic
Move the warning suppression code from the frontend and into import resolution. Parsing already has its own logic for silencing warnings.
1 parent 49ca2d0 commit 813c0d6

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lib/Frontend/Frontend.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -929,10 +929,6 @@ void CompilerInstance::parseAndTypeCheckMainFileUpTo(
929929
SourceFile &MainFile =
930930
MainModule->getMainSourceFile(Invocation.getSourceFileKind());
931931

932-
auto &Diags = MainFile.getASTContext().Diags;
933-
auto DidSuppressWarnings = Diags.getSuppressWarnings();
934-
Diags.setSuppressWarnings(DidSuppressWarnings || !mainIsPrimary);
935-
936932
// For a primary, perform type checking if needed. Otherwise, just do import
937933
// resolution.
938934
if (mainIsPrimary && LimitStage >= SourceFile::TypeChecked) {
@@ -948,8 +944,6 @@ void CompilerInstance::parseAndTypeCheckMainFileUpTo(
948944
parseSourceFileSIL(MainFile, &SILContext);
949945
}
950946

951-
Diags.setSuppressWarnings(DidSuppressWarnings);
952-
953947
if (mainIsPrimary && !Context->hadError() &&
954948
Invocation.getFrontendOptions().DebuggerTestingTransform) {
955949
performDebuggerTestingTransform(MainFile);

lib/Sema/ImportResolution.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,17 @@ void swift::performImportResolution(SourceFile &SF) {
282282

283283
FrontendStatsTracer tracer(SF.getASTContext().Stats,
284284
"Import resolution");
285+
286+
// If we're silencing parsing warnings, then also silence import warnings.
287+
// This is necessary for secondary files as they can be parsed and have their
288+
// imports resolved multiple times.
289+
auto &diags = SF.getASTContext().Diags;
290+
auto didSuppressWarnings = diags.getSuppressWarnings();
291+
auto shouldSuppress = SF.getParsingOptions().contains(
292+
SourceFile::ParsingFlags::SuppressWarnings);
293+
diags.setSuppressWarnings(didSuppressWarnings || shouldSuppress);
294+
SWIFT_DEFER { diags.setSuppressWarnings(didSuppressWarnings); };
295+
285296
ImportResolver resolver(SF);
286297

287298
// Resolve each import declaration.

0 commit comments

Comments
 (0)