diff --git a/include/swift/AST/DiagnosticEngine.h b/include/swift/AST/DiagnosticEngine.h index 8f04b6f982eaf..ed59eb2ac44c5 100644 --- a/include/swift/AST/DiagnosticEngine.h +++ b/include/swift/AST/DiagnosticEngine.h @@ -616,6 +616,9 @@ namespace swift { /// Don't emit any warnings bool suppressWarnings = false; + + /// Don't emit any notes + bool suppressNotes = false; /// Don't emit any remarks bool suppressRemarks = false; @@ -663,6 +666,10 @@ namespace swift { void setSuppressWarnings(bool val) { suppressWarnings = val; } bool getSuppressWarnings() const { return suppressWarnings; } + /// Whether to skip emitting notes + void setSuppressNotes(bool val) { suppressNotes = val; } + bool getSuppressNotes() const { return suppressNotes; } + /// Whether to skip emitting remarks void setSuppressRemarks(bool val) { suppressRemarks = val; } bool getSuppressRemarks() const { return suppressRemarks; } @@ -708,6 +715,7 @@ namespace swift { void swap(DiagnosticState &other) { std::swap(showDiagnosticsAfterFatalError, other.showDiagnosticsAfterFatalError); std::swap(suppressWarnings, other.suppressWarnings); + std::swap(suppressNotes, other.suppressNotes); std::swap(suppressRemarks, other.suppressRemarks); std::swap(warningsAsErrors, other.warningsAsErrors); std::swap(fatalErrorOccurred, other.fatalErrorOccurred); @@ -904,6 +912,12 @@ namespace swift { return state.getSuppressWarnings(); } + /// Whether to skip emitting notes + void setSuppressNotes(bool val) { state.setSuppressNotes(val); } + bool getSuppressNotes() const { + return state.getSuppressNotes(); + } + /// Whether to skip emitting remarks void setSuppressRemarks(bool val) { state.setSuppressRemarks(val); } bool getSuppressRemarks() const { diff --git a/include/swift/Basic/DiagnosticOptions.h b/include/swift/Basic/DiagnosticOptions.h index 2be70d7e1a43a..e346e6199e61e 100644 --- a/include/swift/Basic/DiagnosticOptions.h +++ b/include/swift/Basic/DiagnosticOptions.h @@ -58,6 +58,9 @@ class DiagnosticOptions { /// Suppress all warnings bool SuppressWarnings = false; + /// Suppress all notes + bool SuppressNotes = false; + /// Suppress all remarks bool SuppressRemarks = false; diff --git a/include/swift/Frontend/ModuleInterfaceLoader.h b/include/swift/Frontend/ModuleInterfaceLoader.h index ad38919e56538..c1cbdb7ed7d85 100644 --- a/include/swift/Frontend/ModuleInterfaceLoader.h +++ b/include/swift/Frontend/ModuleInterfaceLoader.h @@ -643,7 +643,7 @@ struct InterfaceSubContextDelegateImpl : InterfaceSubContextDelegate { const LangOptions &LangOpts, const ClangImporterOptions &clangImporterOpts, const CASOptions &casOpts, - bool suppressRemarks); + bool suppressNotes, bool suppressRemarks); bool extractSwiftInterfaceVersionAndArgs(CompilerInvocation &subInvocation, DiagnosticEngine &subInstanceDiags, SwiftInterfaceInfo &interfaceInfo, diff --git a/include/swift/Option/Options.td b/include/swift/Option/Options.td index b25c87080876c..10ffc1b2dc6e9 100644 --- a/include/swift/Option/Options.td +++ b/include/swift/Option/Options.td @@ -929,6 +929,10 @@ def Wwarning : Separate<["-"], "Wwarning">, MetaVarName<"">, HelpText<"Treat this warning group as warning">; +def suppress_notes : Flag<["-"], "suppress-notes">, + Flags<[FrontendOption]>, + HelpText<"Suppress all notes">; + def suppress_remarks : Flag<["-"], "suppress-remarks">, Flags<[FrontendOption]>, HelpText<"Suppress all remarks">; diff --git a/lib/AST/DiagnosticEngine.cpp b/lib/AST/DiagnosticEngine.cpp index cf926f713ea80..7d85c2607c3d2 100644 --- a/lib/AST/DiagnosticEngine.cpp +++ b/lib/AST/DiagnosticEngine.cpp @@ -1345,6 +1345,11 @@ DiagnosticState::determineBehavior(const Diagnostic &diag) const { if (suppressWarnings) lvl = DiagnosticBehavior::Ignore; } + + if (lvl == DiagnosticBehavior::Note) { + if (suppressNotes) + lvl = DiagnosticBehavior::Ignore; + } if (lvl == DiagnosticBehavior::Remark) { if (suppressRemarks) diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index ab67d57abfda6..db8b79bf2f813 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -2652,6 +2652,7 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, } Opts.SuppressWarnings |= Args.hasArg(OPT_suppress_warnings); + Opts.SuppressNotes |= Args.hasArg(OPT_suppress_notes); Opts.SuppressRemarks |= Args.hasArg(OPT_suppress_remarks); for (const Arg *arg : Args.filtered(OPT_warning_treating_Group)) { Opts.WarningsAsErrorsRules.push_back([&] { @@ -2732,6 +2733,9 @@ static void configureDiagnosticEngine( if (Options.SuppressWarnings) { Diagnostics.setSuppressWarnings(true); } + if (Options.SuppressNotes) { + Diagnostics.setSuppressNotes(true); + } if (Options.SuppressRemarks) { Diagnostics.setSuppressRemarks(true); } diff --git a/lib/Frontend/ModuleInterfaceLoader.cpp b/lib/Frontend/ModuleInterfaceLoader.cpp index 27c3b70862dbb..a6dfdbe394a91 100644 --- a/lib/Frontend/ModuleInterfaceLoader.cpp +++ b/lib/Frontend/ModuleInterfaceLoader.cpp @@ -1663,7 +1663,7 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface( FrontendOptions::ActionType requestedAction, const SearchPathOptions &SearchPathOpts, const LangOptions &LangOpts, const ClangImporterOptions &clangImporterOpts, const CASOptions &casOpts, - bool suppressRemarks) { + bool suppressNotes, bool suppressRemarks) { GenericArgs.push_back("-frontend"); // Start with a genericSubInvocation that copies various state from our // invoking ASTContext. @@ -1752,6 +1752,12 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface( genericSubInvocation.getDiagnosticOptions().SuppressWarnings = true; GenericArgs.push_back("-suppress-warnings"); + // Inherit the parent invocation's setting on whether to suppress remarks + if (suppressNotes) { + genericSubInvocation.getDiagnosticOptions().SuppressNotes = true; + GenericArgs.push_back("-suppress-notes"); + } + // Inherit the parent invocation's setting on whether to suppress remarks if (suppressRemarks) { genericSubInvocation.getDiagnosticOptions().SuppressRemarks = true; @@ -1863,6 +1869,7 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl( genericSubInvocation.setMainExecutablePath(LoaderOpts.mainExecutablePath); inheritOptionsForBuildingInterface(LoaderOpts.requestedAction, searchPathOpts, langOpts, clangImporterOpts, casOpts, + Diags->getSuppressNotes(), Diags->getSuppressRemarks()); // Configure front-end input. auto &SubFEOpts = genericSubInvocation.getFrontendOptions();