Skip to content

Commit 1b38c91

Browse files
authored
Merge pull request #85098 from artemcm/DefaultIgnoreDiagnosticGroups
[Diagnostics] Replace diagnostics' `DefaultIgnore` option with a corresponding option on diagnostic groups
2 parents e252673 + 9e35f82 commit 1b38c91

12 files changed

+217
-141
lines changed

include/swift/AST/DefineDiagnosticGroupsMacros.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
// Declares a diagnostic group.
2929
// Parameters:
3030
// Name - group name as it appears in DiagGroupID enum and DiagGroupInfo.name
31+
// Option - attribute applying to members of this diagnostic group
3132
// DocsFile - file with a human readable description for the group located in
3233
// userdocs/diagnostic_groups
3334
#ifndef GROUP
34-
#define GROUP(Name, DocsFile)
35+
#define GROUP(Name, Option, DocsFile)
3536
#endif
3637

3738
// GROUP_LINK macro:

include/swift/AST/DiagnosticEngine.h

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace swift {
5757
/// this enumeration type that uniquely identifies it.
5858
enum class DiagID : uint32_t;
5959

60-
enum class DiagGroupID : uint16_t;
60+
enum class DiagGroupID : uint32_t;
6161

6262
/// Describes a diagnostic along with its argument types.
6363
///
@@ -633,6 +633,14 @@ namespace swift {
633633
/// escalated to errors.
634634
llvm::BitVector warningsAsErrors;
635635

636+
/// Track which diagnostic group (`DiagGroupID`) warnings should be ignored.
637+
llvm::BitVector ignoredDiagnosticGroups;
638+
639+
/// For compiler-internal purposes only, track which diagnostics should
640+
/// be ignored completely. For example, this is used by LLDB to
641+
/// suppress certain errors in expression evaluation.
642+
llvm::BitVector compilerIgnoredDiagnostics;
643+
636644
/// Whether a fatal error has occurred
637645
bool fatalErrorOccurred = false;
638646

@@ -642,9 +650,6 @@ namespace swift {
642650
/// Track the previous emitted Behavior, useful for notes
643651
DiagnosticBehavior previousBehavior = DiagnosticBehavior::Unspecified;
644652

645-
/// Track which diagnostics should be ignored.
646-
llvm::BitVector ignoredDiagnostics;
647-
648653
friend class DiagnosticStateRAII;
649654

650655
public:
@@ -708,25 +713,36 @@ namespace swift {
708713
fatalErrorOccurred = false;
709714
}
710715

711-
/// Set whether a diagnostic should be ignored.
712-
void setIgnoredDiagnostic(DiagID id, bool ignored) {
713-
ignoredDiagnostics[(unsigned)id] = ignored;
716+
/// Set whether a diagnostic group should be ignored.
717+
void setIgnoredDiagnosticGroup(DiagGroupID id, bool ignored) {
718+
ignoredDiagnosticGroups[(unsigned)id] = ignored;
719+
}
720+
721+
/// Query whether a specific diagnostic group is ignored.
722+
bool isIgnoredDiagnosticGroup(DiagGroupID id) const {
723+
return ignoredDiagnosticGroups[(unsigned)id];
714724
}
715725

716-
bool isIgnoredDiagnostic(DiagID id) const {
717-
return ignoredDiagnostics[(unsigned)id];
726+
/// Set a specific diagnostic to be ignored by the compiler.
727+
void compilerInternalIgnoreDiagnostic(DiagID id) {
728+
compilerIgnoredDiagnostics[(unsigned)id] = true;
718729
}
719730

731+
/// Query whether a specific diagnostic group and *all*
732+
/// of its subgroups are ignored.
733+
bool isIgnoredDiagnosticGroupTree(DiagGroupID id) const;
734+
720735
void swap(DiagnosticState &other) {
721-
std::swap(showDiagnosticsAfterFatalError, other.showDiagnosticsAfterFatalError);
736+
std::swap(showDiagnosticsAfterFatalError,
737+
other.showDiagnosticsAfterFatalError);
722738
std::swap(suppressWarnings, other.suppressWarnings);
723739
std::swap(suppressNotes, other.suppressNotes);
724740
std::swap(suppressRemarks, other.suppressRemarks);
725741
std::swap(warningsAsErrors, other.warningsAsErrors);
726742
std::swap(fatalErrorOccurred, other.fatalErrorOccurred);
727743
std::swap(anyErrorOccurred, other.anyErrorOccurred);
728744
std::swap(previousBehavior, other.previousBehavior);
729-
std::swap(ignoredDiagnostics, other.ignoredDiagnostics);
745+
std::swap(ignoredDiagnosticGroups, other.ignoredDiagnosticGroups);
730746
}
731747

732748
private:
@@ -966,12 +982,16 @@ namespace swift {
966982
localization = diag::LocalizationProducer::producerFor(locale, path);
967983
}
968984

969-
void ignoreDiagnostic(DiagID id) {
970-
state.setIgnoredDiagnostic(id, true);
985+
bool isIgnoredDiagnosticGroup(DiagGroupID id) const {
986+
return state.isIgnoredDiagnosticGroup(id);
987+
}
988+
989+
bool isIgnoredDiagnosticGroupTree(DiagGroupID id) const {
990+
return state.isIgnoredDiagnosticGroupTree(id);
971991
}
972992

973-
bool isIgnoredDiagnostic(DiagID id) const {
974-
return state.isIgnoredDiagnostic(id);
993+
void ignoreDiagnostic(DiagID id) {
994+
state.compilerInternalIgnoreDiagnostic(id);
975995
}
976996

977997
void resetHadAnyError() {

include/swift/AST/DiagnosticGroups.def

Lines changed: 56 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -35,63 +35,66 @@
3535
#define DEFINE_DIAGNOSTIC_GROUPS_MACROS
3636
#include "swift/AST/DefineDiagnosticGroupsMacros.h"
3737

38-
// GROUP(Name, DocsFile)
39-
// GROUP_LINK(Parent, Child)
38+
// GROUP(Name,Option,DocsFile)
39+
// GROUP_LINK(Parent,Child)
4040

41-
GROUP(no_group, "")
41+
GROUP(no_group,none,"")
4242

43-
GROUP(ActorIsolatedCall, "actor-isolated-call")
44-
GROUP(AlwaysAvailableDomain, "always-available-domain")
45-
GROUP(AvailabilityUnrecognizedName, "availability-unrecognized-name")
46-
GROUP(ClangDeclarationImport, "clang-declaration-import")
47-
GROUP(CompilationCaching, "compilation-caching")
48-
GROUP(ConformanceIsolation, "conformance-isolation")
49-
GROUP(ForeignReferenceType, "foreign-reference-type")
50-
GROUP(DeprecatedDeclaration, "deprecated-declaration")
51-
GROUP(DynamicCallable, "dynamic-callable-requirements")
52-
GROUP(DynamicExclusivity, "dynamic-exclusivity")
53-
GROUP(EmbeddedRestrictions, "embedded-restrictions")
54-
GROUP(ErrorInFutureSwiftVersion, "error-in-future-swift-version")
55-
GROUP(ExclusivityViolation, "exclusivity-violation")
56-
GROUP(ExistentialAny, "existential-any")
57-
GROUP(ExistentialMemberAccess, "existential-member-access-limitations")
58-
GROUP(ExistentialType, "existential-type")
59-
GROUP(ImplementationOnlyDeprecated, "implementation-only-deprecated")
60-
GROUP(IsolatedConformances, "isolated-conformances")
61-
GROUP(MemberImportVisibility, "member-import-visibility")
62-
GROUP(MissingModuleOnKnownPaths, "missing-module-on-known-paths")
63-
GROUP(ModuleNotTestable, "module-not-testable")
64-
GROUP(ModuleVersionMissing, "module-version-missing")
65-
GROUP(MultipleInheritance, "multiple-inheritance")
66-
GROUP(MutableGlobalVariable, "mutable-global-variable")
67-
GROUP(NominalTypes, "nominal-types")
68-
GROUP(NonisolatedNonsendingByDefault, "nonisolated-nonsending-by-default")
69-
GROUP(OpaqueTypeInference, "opaque-type-inference")
70-
GROUP(PerformanceHints, "performance-hints")
71-
GROUP(PreconcurrencyImport, "preconcurrency-import")
72-
GROUP(PropertyWrappers, "property-wrapper-requirements")
73-
GROUP(ProtocolTypeNonConformance, "protocol-type-non-conformance")
74-
GROUP(RegionIsolation, "region-isolation")
75-
GROUP(ResultBuilderMethods, "result-builder-methods")
76-
GROUP(ReturnTypeImplicitCopy, "return-type-implicit-copy")
77-
GROUP(SemanticCopies, "semantic-copies")
78-
GROUP(SendableClosureCaptures, "sendable-closure-captures")
79-
GROUP(SendableMetatypes, "sendable-metatypes")
80-
GROUP(SendingClosureRisksDataRace, "sending-closure-risks-data-race")
81-
GROUP(SendingRisksDataRace, "sending-risks-data-race")
82-
GROUP(StrictLanguageFeatures, "strict-language-features")
83-
GROUP(StrictMemorySafety, "strict-memory-safety")
84-
GROUP(StringInterpolationConformance, "string-interpolation-conformance")
85-
GROUP(TemporaryPointers, "temporary-pointers")
86-
GROUP(TrailingClosureMatching, "trailing-closure-matching")
87-
GROUP(UnknownWarningGroup, "unknown-warning-group")
88-
GROUP(WeakMutability, "weak-mutability")
43+
GROUP(ActorIsolatedCall,none,"actor-isolated-call")
44+
GROUP(AlwaysAvailableDomain,none,"always-available-domain")
45+
GROUP(AvailabilityUnrecognizedName,none,"availability-unrecognized-name")
46+
GROUP(ClangDeclarationImport,none,"clang-declaration-import")
47+
GROUP(CompilationCaching,none,"compilation-caching")
48+
GROUP(ConformanceIsolation,none,"conformance-isolation")
49+
GROUP(ForeignReferenceType,none,"foreign-reference-type")
50+
GROUP(DeprecatedDeclaration,none,"deprecated-declaration")
51+
GROUP(DynamicExclusivity,DefaultIgnoreWarnings,"dynamic-exclusivity")
52+
GROUP(DynamicCallable,none,"dynamic-callable-requirements")
53+
GROUP(EmbeddedRestrictions,DefaultIgnoreWarnings,"embedded-restrictions")
54+
GROUP(ErrorInFutureSwiftVersion,none,"error-in-future-swift-version")
55+
GROUP(ExclusivityViolation,none,"exclusivity-violation")
56+
GROUP(ExistentialAny,none,"existential-any")
57+
GROUP(ExistentialMemberAccess,none,"existential-member-access-limitations")
58+
GROUP(ExistentialType,none,"existential-type")
59+
GROUP(ImplementationOnlyDeprecated,none,"implementation-only-deprecated")
60+
GROUP(IsolatedConformances,none,"isolated-conformances")
61+
GROUP(MemberImportVisibility,none,"member-import-visibility")
62+
GROUP(MissingModuleOnKnownPaths,none,"missing-module-on-known-paths")
63+
GROUP(ModuleNotTestable,none,"module-not-testable")
64+
GROUP(ModuleVersionMissing,none,"module-version-missing")
65+
GROUP(MultipleInheritance,none,"multiple-inheritance")
66+
GROUP(MutableGlobalVariable,none,"mutable-global-variable")
67+
GROUP(NominalTypes,none,"nominal-types")
68+
GROUP(NonisolatedNonsendingByDefault,none,"nonisolated-nonsending-by-default")
69+
GROUP(OpaqueTypeInference,none,"opaque-type-inference")
70+
GROUP(PerformanceHints,DefaultIgnoreWarnings,"performance-hints")
71+
GROUP(PreconcurrencyImport,DefaultIgnoreWarnings,"preconcurrency-import")
72+
GROUP(PropertyWrappers,none,"property-wrapper-requirements")
73+
GROUP(ProtocolTypeNonConformance,none,"protocol-type-non-conformance")
74+
GROUP(RegionIsolation,none,"region-isolation")
75+
GROUP(ResultBuilderMethods,none,"result-builder-methods")
76+
GROUP(ReturnTypeImplicitCopy,none,"return-type-implicit-copy")
77+
GROUP(SendableClosureCaptures,none,"sendable-closure-captures")
78+
GROUP(SendableMetatypes,none,"sendable-metatypes")
79+
GROUP(SemanticCopies,DefaultIgnoreWarnings,"semantic-copies")
80+
GROUP(SendingClosureRisksDataRace,none,"sending-closure-risks-data-race")
81+
GROUP(SendingRisksDataRace,none,"sending-risks-data-race")
82+
GROUP(StrictLanguageFeatures,none,"strict-language-features")
83+
GROUP(UnrecognizedStrictLanguageFeatures,DefaultIgnoreWarnings,"strict-language-features")
84+
GROUP(StrictMemorySafety,none,"strict-memory-safety")
85+
GROUP(StringInterpolationConformance,none,"string-interpolation-conformance")
86+
GROUP(TemporaryPointers,none,"temporary-pointers")
87+
GROUP(TrailingClosureMatching,none,"trailing-closure-matching")
88+
GROUP(UnknownWarningGroup,none,"unknown-warning-group")
89+
GROUP(WeakMutability,none,"weak-mutability")
8990

90-
GROUP_LINK(PerformanceHints, ExistentialType)
91-
GROUP_LINK(PerformanceHints, ReturnTypeImplicitCopy)
91+
GROUP_LINK(PerformanceHints,ExistentialType)
92+
GROUP_LINK(PerformanceHints,ReturnTypeImplicitCopy)
9293

93-
GROUP_LINK(RegionIsolation, SendingClosureRisksDataRace)
94-
GROUP_LINK(RegionIsolation, SendingRisksDataRace)
94+
GROUP_LINK(RegionIsolation,SendingClosureRisksDataRace)
95+
GROUP_LINK(RegionIsolation,SendingRisksDataRace)
96+
97+
GROUP_LINK(StrictLanguageFeatures, UnrecognizedStrictLanguageFeatures)
9598

9699
#define UNDEFINE_DIAGNOSTIC_GROUPS_MACROS
97100
#include "swift/AST/DefineDiagnosticGroupsMacros.h"

include/swift/AST/DiagnosticGroups.h

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,25 @@
2424
#include <unordered_map>
2525

2626
namespace swift {
27+
enum class DiagnosticGroupOptions {
28+
/// No options.
29+
none,
30+
31+
/// The diagnostic warnings belonging to this group should be ignored by default,
32+
/// but will be re-enabled by various warning options (-Wwarning, -Werror).
33+
DefaultIgnoreWarnings,
34+
};
35+
2736
enum class DiagID : uint32_t;
2837

29-
enum class DiagGroupID : uint16_t {
30-
#define GROUP(Name, Version) Name,
38+
enum class DiagGroupID : uint32_t {
39+
#define GROUP(Name, Option, DocsFile) Name,
3140
#include "swift/AST/DiagnosticGroups.def"
3241
};
3342

3443
constexpr const auto DiagGroupsCount = [] {
3544
size_t count = 0;
36-
#define GROUP(Name, Version) ++count;
45+
#define GROUP(Name, Option, DocsFile) ++count;
3746
#include "DiagnosticGroups.def"
3847
return count;
3948
}();
@@ -45,9 +54,30 @@ struct DiagGroupInfo {
4554
llvm::ArrayRef<DiagGroupID> supergroups;
4655
llvm::ArrayRef<DiagGroupID> subgroups;
4756
llvm::ArrayRef<DiagID> diagnostics;
57+
bool defaultIgnoreWarnings : 1;
58+
59+
constexpr DiagGroupInfo(DiagGroupID groupID, std::string_view name,
60+
std::string_view documentationFile,
61+
llvm::ArrayRef<DiagGroupID> supergroups,
62+
llvm::ArrayRef<DiagGroupID> subgroups,
63+
llvm::ArrayRef<DiagID> diagnostics,
64+
bool defaultIgnoreWarnings)
65+
: id(groupID), name(name), documentationFile(documentationFile),
66+
supergroups(supergroups), subgroups(subgroups), diagnostics(diagnostics),
67+
defaultIgnoreWarnings(defaultIgnoreWarnings) {}
68+
69+
constexpr DiagGroupInfo(DiagGroupID groupID, std::string_view name,
70+
std::string_view documentationFile,
71+
DiagnosticGroupOptions opts,
72+
llvm::ArrayRef<DiagGroupID> supergroups,
73+
llvm::ArrayRef<DiagGroupID> subgroups,
74+
llvm::ArrayRef<DiagID> diagnostics)
75+
: DiagGroupInfo(groupID, name, documentationFile, supergroups,
76+
subgroups, diagnostics,
77+
opts == DiagnosticGroupOptions::DefaultIgnoreWarnings) {}
4878

4979
void traverseDepthFirst(
50-
llvm::function_ref<void(const DiagGroupInfo &)> func) const;
80+
llvm::function_ref<void(const DiagGroupInfo &)> func) const;
5181
};
5282

5383
extern const std::array<DiagGroupInfo, DiagGroupsCount> diagnosticGroupsInfo;

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ WARNING(warning_upcoming_feature_on_by_default, none,
4040
"upcoming feature '%0' is already enabled as of Swift version %1",
4141
(StringRef, unsigned))
4242

43-
GROUPED_WARNING(unrecognized_feature, StrictLanguageFeatures, DefaultIgnore,
43+
GROUPED_WARNING(unrecognized_feature, UnrecognizedStrictLanguageFeatures, none,
4444
"'%0' is not a recognized "
4545
"%select{experimental|upcoming}1 feature",
4646
(StringRef, bool))
4747

48-
GROUPED_WARNING(feature_not_experimental, StrictLanguageFeatures, DefaultIgnore,
48+
GROUPED_WARNING(feature_not_experimental, UnrecognizedStrictLanguageFeatures, none,
4949
"'%0' is not an experimental feature, "
5050
"use -%select{disable|enable}1-upcoming-feature instead",
5151
(StringRef, bool))

include/swift/AST/DiagnosticsSIL.def

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,18 +435,18 @@ NOTE(performance_called_from,none,
435435
"called from here", ())
436436

437437
// ManualOwnership diagnostics
438-
GROUPED_WARNING(manualownership_copy,SemanticCopies,DefaultIgnore,
438+
GROUPED_WARNING(manualownership_copy,SemanticCopies,none,
439439
"implicit 'copy' happens here; please report this vague diagnostic as a bug", ())
440-
GROUPED_WARNING(manualownership_copy_happened,SemanticCopies,DefaultIgnore,
440+
GROUPED_WARNING(manualownership_copy_happened,SemanticCopies,none,
441441
"accessing %0 may produce a copy; write 'copy' to acknowledge or 'consume' to elide", (Identifier))
442-
GROUPED_WARNING(manualownership_copy_demanded,SemanticCopies,DefaultIgnore,
442+
GROUPED_WARNING(manualownership_copy_demanded,SemanticCopies,none,
443443
"independent copy of %0 is required here; write 'copy' to acknowledge or 'consume' to elide", (Identifier))
444-
GROUPED_WARNING(manualownership_copy_captured,SemanticCopies,DefaultIgnore,
444+
GROUPED_WARNING(manualownership_copy_captured,SemanticCopies,none,
445445
"closure capture of '%0' requires independent copy of it; write [%0 = copy %0] in the closure's capture list to acknowledge", (StringRef))
446446

447-
GROUPED_WARNING(manualownership_exclusivity,DynamicExclusivity,DefaultIgnore,
447+
GROUPED_WARNING(manualownership_exclusivity,DynamicExclusivity,none,
448448
"exclusive access here will be checked at runtime; please report this vague diagnostic as a bug", ())
449-
GROUPED_WARNING(manualownership_exclusivity_named,DynamicExclusivity,DefaultIgnore,
449+
GROUPED_WARNING(manualownership_exclusivity_named,DynamicExclusivity,none,
450450
"accessing %0 here may incur runtime exclusivity check%1", (Identifier, StringRef))
451451

452452
// 'transparent' diagnostics

0 commit comments

Comments
 (0)