Skip to content

Add option to suppress emission of remarks ('-suppress-remarks') #61762

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 1 commit into from
Oct 31, 2022
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
14 changes: 14 additions & 0 deletions include/swift/AST/DiagnosticEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,9 @@ namespace swift {

/// Don't emit any warnings
bool suppressWarnings = false;

/// Don't emit any remarks
bool suppressRemarks = false;

/// Emit all warnings as errors
bool warningsAsErrors = false;
Expand Down Expand Up @@ -745,6 +748,10 @@ namespace swift {
/// Whether to skip emitting warnings
void setSuppressWarnings(bool val) { suppressWarnings = val; }
bool getSuppressWarnings() const { return suppressWarnings; }

/// Whether to skip emitting remarks
void setSuppressRemarks(bool val) { suppressRemarks = val; }
bool getSuppressRemarks() const { return suppressRemarks; }

/// Whether to treat warnings as errors
void setWarningsAsErrors(bool val) { warningsAsErrors = val; }
Expand All @@ -763,6 +770,7 @@ namespace swift {
void swap(DiagnosticState &other) {
std::swap(showDiagnosticsAfterFatalError, other.showDiagnosticsAfterFatalError);
std::swap(suppressWarnings, other.suppressWarnings);
std::swap(suppressRemarks, other.suppressRemarks);
std::swap(warningsAsErrors, other.warningsAsErrors);
std::swap(fatalErrorOccurred, other.fatalErrorOccurred);
std::swap(anyErrorOccurred, other.anyErrorOccurred);
Expand Down Expand Up @@ -880,6 +888,12 @@ namespace swift {
return state.getSuppressWarnings();
}

/// Whether to skip emitting remarks
void setSuppressRemarks(bool val) { state.setSuppressRemarks(val); }
bool getSuppressRemarks() const {
return state.getSuppressRemarks();
}

/// Whether to treat warnings as errors
void setWarningsAsErrors(bool val) { state.setWarningsAsErrors(val); }
bool getWarningsAsErrors() const {
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Basic/DiagnosticOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class DiagnosticOptions {

/// Suppress all warnings
bool SuppressWarnings = false;

/// Suppress all remarks
bool SuppressRemarks = false;

/// Treat all warnings as errors
bool WarningsAsErrors = false;
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Frontend/ModuleInterfaceLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
}
void
inheritOptionsForBuildingInterface(const SearchPathOptions &SearchPathOpts,
const LangOptions &LangOpts,
const LangOptions &LangOpts, bool suppressRemarks,
RequireOSSAModules_t requireOSSAModules);
bool extractSwiftInterfaceVersionAndArgs(CompilerInvocation &subInvocation,
SmallVectorImpl<const char *> &SubArgs,
Expand Down
4 changes: 4 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,10 @@ def warnings_as_errors : Flag<["-"], "warnings-as-errors">,
def no_warnings_as_errors : Flag<["-"], "no-warnings-as-errors">,
Flags<[FrontendOption]>,
HelpText<"Don't treat warnings as errors">;

def suppress_remarks : Flag<["-"], "suppress-remarks">,
Flags<[FrontendOption]>,
HelpText<"Suppress all remarks">;

def continue_building_after_errors : Flag<["-"], "continue-building-after-errors">,
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
Expand Down
5 changes: 5 additions & 0 deletions lib/AST/DiagnosticEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,11 @@ DiagnosticBehavior DiagnosticState::determineBehavior(const Diagnostic &diag) {
if (suppressWarnings)
lvl = DiagnosticBehavior::Ignore;
}

if (lvl == DiagnosticBehavior::Remark) {
if (suppressRemarks)
lvl = DiagnosticBehavior::Ignore;
}

// 5) Update current state for use during the next diagnostic
if (lvl == DiagnosticBehavior::Fatal) {
Expand Down
1 change: 1 addition & 0 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
inputArgs.AddLastArg(arguments, options::OPT_Rpass_EQ);
inputArgs.AddLastArg(arguments, options::OPT_Rpass_missed_EQ);
inputArgs.AddLastArg(arguments, options::OPT_suppress_warnings);
inputArgs.AddLastArg(arguments, options::OPT_suppress_remarks);
inputArgs.AddLastArg(arguments, options::OPT_profile_generate);
inputArgs.AddLastArg(arguments, options::OPT_profile_use);
inputArgs.AddLastArg(arguments, options::OPT_profile_coverage_mapping);
Expand Down
1 change: 1 addition & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,7 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,

Opts.FixitCodeForAllDiagnostics |= Args.hasArg(OPT_fixit_all);
Opts.SuppressWarnings |= Args.hasArg(OPT_suppress_warnings);
Opts.SuppressRemarks |= Args.hasArg(OPT_suppress_remarks);
Opts.WarningsAsErrors = Args.hasFlag(options::OPT_warnings_as_errors,
options::OPT_no_warnings_as_errors,
false);
Expand Down
3 changes: 3 additions & 0 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ void CompilerInstance::setUpDiagnosticOptions() {
if (Invocation.getDiagnosticOptions().SuppressWarnings) {
Diagnostics.setSuppressWarnings(true);
}
if (Invocation.getDiagnosticOptions().SuppressRemarks) {
Diagnostics.setSuppressRemarks(true);
}
if (Invocation.getDiagnosticOptions().WarningsAsErrors) {
Diagnostics.setWarningsAsErrors(true);
}
Expand Down
10 changes: 8 additions & 2 deletions lib/Frontend/ModuleInterfaceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,7 @@ void ModuleInterfaceLoader::collectVisibleTopLevelModuleNames(

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

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

// Inherit this setting down so that it can affect error diagnostics (mostly
// by making them non-fatal).
Expand Down Expand Up @@ -1538,6 +1543,7 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
: SM(SM), Diags(Diags), ArgSaver(Allocator) {
genericSubInvocation.setMainExecutablePath(LoaderOpts.mainExecutablePath);
inheritOptionsForBuildingInterface(searchPathOpts, langOpts,
Diags->getSuppressRemarks(),
requireOSSAModules);
// Configure front-end input.
auto &SubFEOpts = genericSubInvocation.getFrontendOptions();
Expand Down
15 changes: 15 additions & 0 deletions test/Frontend/SuppressRemarks.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/OtherActors.swiftmodule -module-name OtherActors %S/../Concurrency/Inputs/OtherActors.swift -disable-availability-checking

// RUN: not %target-swift-frontend -typecheck -I %t %s 2>&1 | %FileCheck -check-prefix=DEFAULT %s
// RUN: not %target-swift-frontend -typecheck -I %t %s -suppress-remarks 2>&1 | %FileCheck -check-prefix=NOREMARK %s

@preconcurrency import OtherActors
// DEFAULT: error: cannot find 'xyz' in scope
// DEFAULT: remark: '@preconcurrency' attribute on module 'OtherActors' is unused
// NORMEARK: error: cannot find 'xyz' in scope
// NOREMARK-NOT: remark: '@preconcurrency' attribute on module 'OtherActors' is unused

func bar() {
xyz
}