Skip to content

Commit c51efbe

Browse files
committed
Add option to suppress emission of remarks ('-suppress-remarks')
And enforce it especially in downstream contexts such as building interfaces of SDK dependencies, where the remarks are not actionable by the user.
1 parent 783d0c6 commit c51efbe

File tree

10 files changed

+55
-3
lines changed

10 files changed

+55
-3
lines changed

include/swift/AST/DiagnosticEngine.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,9 @@ namespace swift {
707707

708708
/// Don't emit any warnings
709709
bool suppressWarnings = false;
710+
711+
/// Don't emit any remarks
712+
bool suppressRemarks = false;
710713

711714
/// Emit all warnings as errors
712715
bool warningsAsErrors = false;
@@ -745,6 +748,10 @@ namespace swift {
745748
/// Whether to skip emitting warnings
746749
void setSuppressWarnings(bool val) { suppressWarnings = val; }
747750
bool getSuppressWarnings() const { return suppressWarnings; }
751+
752+
/// Whether to skip emitting remarks
753+
void setSuppressRemarks(bool val) { suppressRemarks = val; }
754+
bool getSuppressRemarks() const { return suppressRemarks; }
748755

749756
/// Whether to treat warnings as errors
750757
void setWarningsAsErrors(bool val) { warningsAsErrors = val; }
@@ -763,6 +770,7 @@ namespace swift {
763770
void swap(DiagnosticState &other) {
764771
std::swap(showDiagnosticsAfterFatalError, other.showDiagnosticsAfterFatalError);
765772
std::swap(suppressWarnings, other.suppressWarnings);
773+
std::swap(suppressRemarks, other.suppressRemarks);
766774
std::swap(warningsAsErrors, other.warningsAsErrors);
767775
std::swap(fatalErrorOccurred, other.fatalErrorOccurred);
768776
std::swap(anyErrorOccurred, other.anyErrorOccurred);
@@ -880,6 +888,12 @@ namespace swift {
880888
return state.getSuppressWarnings();
881889
}
882890

891+
/// Whether to skip emitting remarks
892+
void setSuppressRemarks(bool val) { state.setSuppressRemarks(val); }
893+
bool getSuppressRemarks() const {
894+
return state.getSuppressRemarks();
895+
}
896+
883897
/// Whether to treat warnings as errors
884898
void setWarningsAsErrors(bool val) { state.setWarningsAsErrors(val); }
885899
bool getWarningsAsErrors() const {

include/swift/Basic/DiagnosticOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ class DiagnosticOptions {
5454

5555
/// Suppress all warnings
5656
bool SuppressWarnings = false;
57+
58+
/// Suppress all remarks
59+
bool SuppressRemarks = false;
5760

5861
/// Treat all warnings as errors
5962
bool WarningsAsErrors = false;

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
478478
}
479479
void
480480
inheritOptionsForBuildingInterface(const SearchPathOptions &SearchPathOpts,
481-
const LangOptions &LangOpts,
481+
const LangOptions &LangOpts, bool suppressRemarks,
482482
RequireOSSAModules_t requireOSSAModules);
483483
bool extractSwiftInterfaceVersionAndArgs(CompilerInvocation &subInvocation,
484484
SmallVectorImpl<const char *> &SubArgs,

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,10 @@ def warnings_as_errors : Flag<["-"], "warnings-as-errors">,
657657
def no_warnings_as_errors : Flag<["-"], "no-warnings-as-errors">,
658658
Flags<[FrontendOption]>,
659659
HelpText<"Don't treat warnings as errors">;
660+
661+
def suppress_remarks : Flag<["-"], "suppress-remarks">,
662+
Flags<[FrontendOption]>,
663+
HelpText<"Suppress all remarks">;
660664

661665
def continue_building_after_errors : Flag<["-"], "continue-building-after-errors">,
662666
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,

lib/AST/DiagnosticEngine.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,11 @@ DiagnosticBehavior DiagnosticState::determineBehavior(const Diagnostic &diag) {
10271027
if (suppressWarnings)
10281028
lvl = DiagnosticBehavior::Ignore;
10291029
}
1030+
1031+
if (lvl == DiagnosticBehavior::Remark) {
1032+
if (suppressRemarks)
1033+
lvl = DiagnosticBehavior::Ignore;
1034+
}
10301035

10311036
// 5) Update current state for use during the next diagnostic
10321037
if (lvl == DiagnosticBehavior::Fatal) {

lib/Driver/ToolChains.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
261261
inputArgs.AddLastArg(arguments, options::OPT_Rpass_EQ);
262262
inputArgs.AddLastArg(arguments, options::OPT_Rpass_missed_EQ);
263263
inputArgs.AddLastArg(arguments, options::OPT_suppress_warnings);
264+
inputArgs.AddLastArg(arguments, options::OPT_suppress_remarks);
264265
inputArgs.AddLastArg(arguments, options::OPT_profile_generate);
265266
inputArgs.AddLastArg(arguments, options::OPT_profile_use);
266267
inputArgs.AddLastArg(arguments, options::OPT_profile_coverage_mapping);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,7 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
14441444

14451445
Opts.FixitCodeForAllDiagnostics |= Args.hasArg(OPT_fixit_all);
14461446
Opts.SuppressWarnings |= Args.hasArg(OPT_suppress_warnings);
1447+
Opts.SuppressRemarks |= Args.hasArg(OPT_suppress_remarks);
14471448
Opts.WarningsAsErrors = Args.hasFlag(options::OPT_warnings_as_errors,
14481449
options::OPT_no_warnings_as_errors,
14491450
false);

lib/Frontend/Frontend.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,9 @@ void CompilerInstance::setUpDiagnosticOptions() {
454454
if (Invocation.getDiagnosticOptions().SuppressWarnings) {
455455
Diagnostics.setSuppressWarnings(true);
456456
}
457+
if (Invocation.getDiagnosticOptions().SuppressRemarks) {
458+
Diagnostics.setSuppressRemarks(true);
459+
}
457460
if (Invocation.getDiagnosticOptions().WarningsAsErrors) {
458461
Diagnostics.setWarningsAsErrors(true);
459462
}

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,7 @@ void ModuleInterfaceLoader::collectVisibleTopLevelModuleNames(
14051405

14061406
void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
14071407
const SearchPathOptions &SearchPathOpts, const LangOptions &LangOpts,
1408-
RequireOSSAModules_t RequireOSSAModules) {
1408+
bool suppressRemarks, RequireOSSAModules_t RequireOSSAModules) {
14091409
GenericArgs.push_back("-frontend");
14101410
// Start with a genericSubInvocation that copies various state from our
14111411
// invoking ASTContext.
@@ -1458,9 +1458,14 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
14581458
}
14591459

14601460
// Inhibit warnings from the genericSubInvocation since we are assuming the user
1461-
// is not in a position to fix them.
1461+
// is not in a position to address them.
14621462
genericSubInvocation.getDiagnosticOptions().SuppressWarnings = true;
14631463
GenericArgs.push_back("-suppress-warnings");
1464+
// Inherit the parent invocation's setting on whether to suppress remarks
1465+
if (suppressRemarks) {
1466+
genericSubInvocation.getDiagnosticOptions().SuppressRemarks = true;
1467+
GenericArgs.push_back("-suppress-remarks");
1468+
}
14641469

14651470
// Inherit this setting down so that it can affect error diagnostics (mostly
14661471
// by making them non-fatal).
@@ -1538,6 +1543,7 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
15381543
: SM(SM), Diags(Diags), ArgSaver(Allocator) {
15391544
genericSubInvocation.setMainExecutablePath(LoaderOpts.mainExecutablePath);
15401545
inheritOptionsForBuildingInterface(searchPathOpts, langOpts,
1546+
Diags->getSuppressRemarks(),
15411547
requireOSSAModules);
15421548
// Configure front-end input.
15431549
auto &SubFEOpts = genericSubInvocation.getFrontendOptions();

test/Frontend/SuppressRemarks.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/OtherActors.swiftmodule -module-name OtherActors %S/../Concurrency/Inputs/OtherActors.swift -disable-availability-checking
3+
4+
// RUN: not %target-swift-frontend -typecheck -I %t %s 2>&1 | %FileCheck -check-prefix=DEFAULT %s
5+
// RUN: not %target-swift-frontend -typecheck -I %t %s -suppress-remarks 2>&1 | %FileCheck -check-prefix=NOREMARK %s
6+
7+
@preconcurrency import OtherActors
8+
// DEFAULT: error: cannot find 'xyz' in scope
9+
// DEFAULT: remark: '@preconcurrency' attribute on module 'OtherActors' is unused
10+
// NORMEARK: error: cannot find 'xyz' in scope
11+
// NOREMARK-NOT: remark: '@preconcurrency' attribute on module 'OtherActors' is unused
12+
13+
func bar() {
14+
xyz
15+
}

0 commit comments

Comments
 (0)