mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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.
This commit is contained in:
@@ -707,6 +707,9 @@ namespace swift {
|
|||||||
|
|
||||||
/// Don't emit any warnings
|
/// Don't emit any warnings
|
||||||
bool suppressWarnings = false;
|
bool suppressWarnings = false;
|
||||||
|
|
||||||
|
/// Don't emit any remarks
|
||||||
|
bool suppressRemarks = false;
|
||||||
|
|
||||||
/// Emit all warnings as errors
|
/// Emit all warnings as errors
|
||||||
bool warningsAsErrors = false;
|
bool warningsAsErrors = false;
|
||||||
@@ -745,6 +748,10 @@ namespace swift {
|
|||||||
/// Whether to skip emitting warnings
|
/// Whether to skip emitting warnings
|
||||||
void setSuppressWarnings(bool val) { suppressWarnings = val; }
|
void setSuppressWarnings(bool val) { suppressWarnings = val; }
|
||||||
bool getSuppressWarnings() const { return suppressWarnings; }
|
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
|
/// Whether to treat warnings as errors
|
||||||
void setWarningsAsErrors(bool val) { warningsAsErrors = val; }
|
void setWarningsAsErrors(bool val) { warningsAsErrors = val; }
|
||||||
@@ -763,6 +770,7 @@ namespace swift {
|
|||||||
void swap(DiagnosticState &other) {
|
void swap(DiagnosticState &other) {
|
||||||
std::swap(showDiagnosticsAfterFatalError, other.showDiagnosticsAfterFatalError);
|
std::swap(showDiagnosticsAfterFatalError, other.showDiagnosticsAfterFatalError);
|
||||||
std::swap(suppressWarnings, other.suppressWarnings);
|
std::swap(suppressWarnings, other.suppressWarnings);
|
||||||
|
std::swap(suppressRemarks, other.suppressRemarks);
|
||||||
std::swap(warningsAsErrors, other.warningsAsErrors);
|
std::swap(warningsAsErrors, other.warningsAsErrors);
|
||||||
std::swap(fatalErrorOccurred, other.fatalErrorOccurred);
|
std::swap(fatalErrorOccurred, other.fatalErrorOccurred);
|
||||||
std::swap(anyErrorOccurred, other.anyErrorOccurred);
|
std::swap(anyErrorOccurred, other.anyErrorOccurred);
|
||||||
@@ -880,6 +888,12 @@ namespace swift {
|
|||||||
return state.getSuppressWarnings();
|
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
|
/// Whether to treat warnings as errors
|
||||||
void setWarningsAsErrors(bool val) { state.setWarningsAsErrors(val); }
|
void setWarningsAsErrors(bool val) { state.setWarningsAsErrors(val); }
|
||||||
bool getWarningsAsErrors() const {
|
bool getWarningsAsErrors() const {
|
||||||
|
|||||||
@@ -54,6 +54,9 @@ public:
|
|||||||
|
|
||||||
/// Suppress all warnings
|
/// Suppress all warnings
|
||||||
bool SuppressWarnings = false;
|
bool SuppressWarnings = false;
|
||||||
|
|
||||||
|
/// Suppress all remarks
|
||||||
|
bool SuppressRemarks = false;
|
||||||
|
|
||||||
/// Treat all warnings as errors
|
/// Treat all warnings as errors
|
||||||
bool WarningsAsErrors = false;
|
bool WarningsAsErrors = false;
|
||||||
|
|||||||
@@ -478,7 +478,7 @@ private:
|
|||||||
}
|
}
|
||||||
void
|
void
|
||||||
inheritOptionsForBuildingInterface(const SearchPathOptions &SearchPathOpts,
|
inheritOptionsForBuildingInterface(const SearchPathOptions &SearchPathOpts,
|
||||||
const LangOptions &LangOpts,
|
const LangOptions &LangOpts, bool suppressRemarks,
|
||||||
RequireOSSAModules_t requireOSSAModules);
|
RequireOSSAModules_t requireOSSAModules);
|
||||||
bool extractSwiftInterfaceVersionAndArgs(CompilerInvocation &subInvocation,
|
bool extractSwiftInterfaceVersionAndArgs(CompilerInvocation &subInvocation,
|
||||||
SmallVectorImpl<const char *> &SubArgs,
|
SmallVectorImpl<const char *> &SubArgs,
|
||||||
|
|||||||
@@ -657,6 +657,10 @@ def warnings_as_errors : Flag<["-"], "warnings-as-errors">,
|
|||||||
def no_warnings_as_errors : Flag<["-"], "no-warnings-as-errors">,
|
def no_warnings_as_errors : Flag<["-"], "no-warnings-as-errors">,
|
||||||
Flags<[FrontendOption]>,
|
Flags<[FrontendOption]>,
|
||||||
HelpText<"Don't treat warnings as errors">;
|
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">,
|
def continue_building_after_errors : Flag<["-"], "continue-building-after-errors">,
|
||||||
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
|
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
|
||||||
|
|||||||
@@ -1027,6 +1027,11 @@ DiagnosticBehavior DiagnosticState::determineBehavior(const Diagnostic &diag) {
|
|||||||
if (suppressWarnings)
|
if (suppressWarnings)
|
||||||
lvl = DiagnosticBehavior::Ignore;
|
lvl = DiagnosticBehavior::Ignore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lvl == DiagnosticBehavior::Remark) {
|
||||||
|
if (suppressRemarks)
|
||||||
|
lvl = DiagnosticBehavior::Ignore;
|
||||||
|
}
|
||||||
|
|
||||||
// 5) Update current state for use during the next diagnostic
|
// 5) Update current state for use during the next diagnostic
|
||||||
if (lvl == DiagnosticBehavior::Fatal) {
|
if (lvl == DiagnosticBehavior::Fatal) {
|
||||||
|
|||||||
@@ -261,6 +261,7 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
|
|||||||
inputArgs.AddLastArg(arguments, options::OPT_Rpass_EQ);
|
inputArgs.AddLastArg(arguments, options::OPT_Rpass_EQ);
|
||||||
inputArgs.AddLastArg(arguments, options::OPT_Rpass_missed_EQ);
|
inputArgs.AddLastArg(arguments, options::OPT_Rpass_missed_EQ);
|
||||||
inputArgs.AddLastArg(arguments, options::OPT_suppress_warnings);
|
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_generate);
|
||||||
inputArgs.AddLastArg(arguments, options::OPT_profile_use);
|
inputArgs.AddLastArg(arguments, options::OPT_profile_use);
|
||||||
inputArgs.AddLastArg(arguments, options::OPT_profile_coverage_mapping);
|
inputArgs.AddLastArg(arguments, options::OPT_profile_coverage_mapping);
|
||||||
|
|||||||
@@ -1444,6 +1444,7 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
|
|||||||
|
|
||||||
Opts.FixitCodeForAllDiagnostics |= Args.hasArg(OPT_fixit_all);
|
Opts.FixitCodeForAllDiagnostics |= Args.hasArg(OPT_fixit_all);
|
||||||
Opts.SuppressWarnings |= Args.hasArg(OPT_suppress_warnings);
|
Opts.SuppressWarnings |= Args.hasArg(OPT_suppress_warnings);
|
||||||
|
Opts.SuppressRemarks |= Args.hasArg(OPT_suppress_remarks);
|
||||||
Opts.WarningsAsErrors = Args.hasFlag(options::OPT_warnings_as_errors,
|
Opts.WarningsAsErrors = Args.hasFlag(options::OPT_warnings_as_errors,
|
||||||
options::OPT_no_warnings_as_errors,
|
options::OPT_no_warnings_as_errors,
|
||||||
false);
|
false);
|
||||||
|
|||||||
@@ -454,6 +454,9 @@ void CompilerInstance::setUpDiagnosticOptions() {
|
|||||||
if (Invocation.getDiagnosticOptions().SuppressWarnings) {
|
if (Invocation.getDiagnosticOptions().SuppressWarnings) {
|
||||||
Diagnostics.setSuppressWarnings(true);
|
Diagnostics.setSuppressWarnings(true);
|
||||||
}
|
}
|
||||||
|
if (Invocation.getDiagnosticOptions().SuppressRemarks) {
|
||||||
|
Diagnostics.setSuppressRemarks(true);
|
||||||
|
}
|
||||||
if (Invocation.getDiagnosticOptions().WarningsAsErrors) {
|
if (Invocation.getDiagnosticOptions().WarningsAsErrors) {
|
||||||
Diagnostics.setWarningsAsErrors(true);
|
Diagnostics.setWarningsAsErrors(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1405,7 +1405,7 @@ void ModuleInterfaceLoader::collectVisibleTopLevelModuleNames(
|
|||||||
|
|
||||||
void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
|
void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
|
||||||
const SearchPathOptions &SearchPathOpts, const LangOptions &LangOpts,
|
const SearchPathOptions &SearchPathOpts, const LangOptions &LangOpts,
|
||||||
RequireOSSAModules_t RequireOSSAModules) {
|
bool suppressRemarks, RequireOSSAModules_t RequireOSSAModules) {
|
||||||
GenericArgs.push_back("-frontend");
|
GenericArgs.push_back("-frontend");
|
||||||
// Start with a genericSubInvocation that copies various state from our
|
// Start with a genericSubInvocation that copies various state from our
|
||||||
// invoking ASTContext.
|
// invoking ASTContext.
|
||||||
@@ -1458,9 +1458,14 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Inhibit warnings from the genericSubInvocation since we are assuming the user
|
// 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;
|
genericSubInvocation.getDiagnosticOptions().SuppressWarnings = true;
|
||||||
GenericArgs.push_back("-suppress-warnings");
|
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
|
// Inherit this setting down so that it can affect error diagnostics (mostly
|
||||||
// by making them non-fatal).
|
// by making them non-fatal).
|
||||||
@@ -1538,6 +1543,7 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
|
|||||||
: SM(SM), Diags(Diags), ArgSaver(Allocator) {
|
: SM(SM), Diags(Diags), ArgSaver(Allocator) {
|
||||||
genericSubInvocation.setMainExecutablePath(LoaderOpts.mainExecutablePath);
|
genericSubInvocation.setMainExecutablePath(LoaderOpts.mainExecutablePath);
|
||||||
inheritOptionsForBuildingInterface(searchPathOpts, langOpts,
|
inheritOptionsForBuildingInterface(searchPathOpts, langOpts,
|
||||||
|
Diags->getSuppressRemarks(),
|
||||||
requireOSSAModules);
|
requireOSSAModules);
|
||||||
// Configure front-end input.
|
// Configure front-end input.
|
||||||
auto &SubFEOpts = genericSubInvocation.getFrontendOptions();
|
auto &SubFEOpts = genericSubInvocation.getFrontendOptions();
|
||||||
|
|||||||
15
test/Frontend/SuppressRemarks.swift
Normal file
15
test/Frontend/SuppressRemarks.swift
Normal file
@@ -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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user