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:
@@ -708,6 +708,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;
|
||||
|
||||
@@ -746,6 +749,10 @@ namespace swift {
|
||||
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; }
|
||||
bool getWarningsAsErrors() const { return warningsAsErrors; }
|
||||
@@ -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);
|
||||
@@ -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 {
|
||||
|
||||
@@ -55,6 +55,9 @@ public:
|
||||
/// Suppress all warnings
|
||||
bool SuppressWarnings = false;
|
||||
|
||||
/// Suppress all remarks
|
||||
bool SuppressRemarks = false;
|
||||
|
||||
/// Treat all warnings as errors
|
||||
bool WarningsAsErrors = false;
|
||||
|
||||
|
||||
@@ -478,7 +478,7 @@ private:
|
||||
}
|
||||
void
|
||||
inheritOptionsForBuildingInterface(const SearchPathOptions &SearchPathOpts,
|
||||
const LangOptions &LangOpts,
|
||||
const LangOptions &LangOpts, bool suppressRemarks,
|
||||
RequireOSSAModules_t requireOSSAModules);
|
||||
bool extractSwiftInterfaceVersionAndArgs(CompilerInvocation &subInvocation,
|
||||
SmallVectorImpl<const char *> &SubArgs,
|
||||
|
||||
@@ -658,6 +658,10 @@ 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]>,
|
||||
HelpText<"Continue building, even after errors are encountered">;
|
||||
|
||||
@@ -1028,6 +1028,11 @@ DiagnosticBehavior DiagnosticState::determineBehavior(const Diagnostic &diag) {
|
||||
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) {
|
||||
fatalErrorOccurred = true;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -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).
|
||||
@@ -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();
|
||||
|
||||
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