Skip to content

Commit e44c07f

Browse files
committed
[Diagnostics] Replace diagnostics' 'DefaultIgnore' option with a corresponding option on diagnostic groups
This brings this control in line with other diagnostic controls we have which operate on a per-group level. 'DefaultIgnoreWarnings' diagnostic group option applies to all warnings belonging to a certain diagnostic group. The inheritance rules are: - Marking a diagnostic group as 'DefaultIgnoreWarnings' means warnings belonging to this group will not be emitted by-default - Warnings belonging to sub-groups of this group will also not be emitted by-default - Enabling a 'DefaultIgnoreWarnings' group (with '-Werror','-Wwarning', etc.) means warnings belonging to this group will be emitted. - Warnings belonging to sub-groups of this group will also be emitted. - Warnings belonging to super-groups of this group will not be affected.
1 parent f515cd7 commit e44c07f

File tree

11 files changed

+184
-127
lines changed

11 files changed

+184
-127
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+
// Options - attributes 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, Options, DocsFile)
3536
#endif
3637

3738
// GROUP_LINK macro:

include/swift/AST/DiagnosticEngine.h

Lines changed: 22 additions & 16 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,9 @@ 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+
636639
/// Whether a fatal error has occurred
637640
bool fatalErrorOccurred = false;
638641

@@ -642,9 +645,6 @@ namespace swift {
642645
/// Track the previous emitted Behavior, useful for notes
643646
DiagnosticBehavior previousBehavior = DiagnosticBehavior::Unspecified;
644647

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

650650
public:
@@ -708,25 +708,31 @@ namespace swift {
708708
fatalErrorOccurred = false;
709709
}
710710

711-
/// Set whether a diagnostic should be ignored.
712-
void setIgnoredDiagnostic(DiagID id, bool ignored) {
713-
ignoredDiagnostics[(unsigned)id] = ignored;
711+
/// Set whether a diagnostic group should be ignored.
712+
void setIgnoredDiagnosticGroup(DiagGroupID id, bool ignored) {
713+
ignoredDiagnosticGroups[(unsigned)id] = ignored;
714714
}
715715

716-
bool isIgnoredDiagnostic(DiagID id) const {
717-
return ignoredDiagnostics[(unsigned)id];
716+
/// Query whether a specific diagnostic group is ignored.
717+
bool isIgnoredDiagnosticGroup(DiagGroupID id) const {
718+
return ignoredDiagnosticGroups[(unsigned)id];
718719
}
720+
721+
/// Query whether a specific diagnostic group and *all*
722+
/// of its subgroups are ignored.
723+
bool isIgnoredDiagnosticGroupTree(DiagGroupID id) const;
719724

720725
void swap(DiagnosticState &other) {
721-
std::swap(showDiagnosticsAfterFatalError, other.showDiagnosticsAfterFatalError);
726+
std::swap(showDiagnosticsAfterFatalError,
727+
other.showDiagnosticsAfterFatalError);
722728
std::swap(suppressWarnings, other.suppressWarnings);
723729
std::swap(suppressNotes, other.suppressNotes);
724730
std::swap(suppressRemarks, other.suppressRemarks);
725731
std::swap(warningsAsErrors, other.warningsAsErrors);
726732
std::swap(fatalErrorOccurred, other.fatalErrorOccurred);
727733
std::swap(anyErrorOccurred, other.anyErrorOccurred);
728734
std::swap(previousBehavior, other.previousBehavior);
729-
std::swap(ignoredDiagnostics, other.ignoredDiagnostics);
735+
std::swap(ignoredDiagnosticGroups, other.ignoredDiagnosticGroups);
730736
}
731737

732738
private:
@@ -966,12 +972,12 @@ namespace swift {
966972
localization = diag::LocalizationProducer::producerFor(locale, path);
967973
}
968974

969-
void ignoreDiagnostic(DiagID id) {
970-
state.setIgnoredDiagnostic(id, true);
975+
bool isIgnoredDiagnosticGroup(DiagGroupID id) const {
976+
return state.isIgnoredDiagnosticGroup(id);
971977
}
972-
973-
bool isIgnoredDiagnostic(DiagID id) const {
974-
return state.isIgnoredDiagnostic(id);
978+
979+
bool isIgnoredDiagnosticGroupTree(DiagGroupID id) const {
980+
return state.isIgnoredDiagnosticGroupTree(id);
975981
}
976982

977983
void resetHadAnyError() {

include/swift/AST/DiagnosticGroups.def

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

38-
// GROUP(Name, DocsFile)
38+
// GROUP(Name, Options, DocsFile)
3939
// 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(ConformanceIsolation, "conformance-isolation")
48-
GROUP(DeprecatedDeclaration, "deprecated-declaration")
49-
GROUP(DynamicCallable, "dynamic-callable-requirements")
50-
GROUP(EmbeddedRestrictions, "embedded-restrictions")
51-
GROUP(ErrorInFutureSwiftVersion, "error-in-future-swift-version")
52-
GROUP(ExclusivityViolation, "exclusivity-violation")
53-
GROUP(ExistentialAny, "existential-any")
54-
GROUP(ExistentialMemberAccess, "existential-member-access-limitations")
55-
GROUP(ImplementationOnlyDeprecated, "implementation-only-deprecated")
56-
GROUP(IsolatedConformances, "isolated-conformances")
57-
GROUP(MemberImportVisibility, "member-import-visibility")
58-
GROUP(MissingModuleOnKnownPaths, "missing-module-on-known-paths")
59-
GROUP(ModuleNotTestable, "module-not-testable")
60-
GROUP(ModuleVersionMissing, "module-version-missing")
61-
GROUP(MultipleInheritance, "multiple-inheritance")
62-
GROUP(MutableGlobalVariable, "mutable-global-variable")
63-
GROUP(NominalTypes, "nominal-types")
64-
GROUP(NonisolatedNonsendingByDefault, "nonisolated-nonsending-by-default")
65-
GROUP(OpaqueTypeInference, "opaque-type-inference")
66-
GROUP(PreconcurrencyImport, "preconcurrency-import")
67-
GROUP(PropertyWrappers, "property-wrapper-requirements")
68-
GROUP(ProtocolTypeNonConformance, "protocol-type-non-conformance")
69-
GROUP(ResultBuilderMethods, "result-builder-methods")
70-
GROUP(SendableClosureCaptures, "sendable-closure-captures")
71-
GROUP(SendableMetatypes, "sendable-metatypes")
72-
GROUP(SendingRisksDataRace, "sending-risks-data-race")
73-
GROUP(StrictLanguageFeatures, "strict-language-features")
74-
GROUP(StrictMemorySafety, "strict-memory-safety")
75-
GROUP(StringInterpolationConformance, "string-interpolation-conformance")
76-
GROUP(TemporaryPointers, "temporary-pointers")
77-
GROUP(TrailingClosureMatching, "trailing-closure-matching")
78-
GROUP(UnknownWarningGroup, "unknown-warning-group")
79-
GROUP(CompilationCaching, "compilation-caching")
80-
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(ConformanceIsolation, none, "conformance-isolation")
48+
GROUP(DeprecatedDeclaration, none, "deprecated-declaration")
49+
GROUP(DynamicCallable, none, "dynamic-callable-requirements")
50+
GROUP(EmbeddedRestrictions, DefaultIgnoreWarnings, "embedded-restrictions")
51+
GROUP(ErrorInFutureSwiftVersion, none, "error-in-future-swift-version")
52+
GROUP(ExclusivityViolation, none, "exclusivity-violation")
53+
GROUP(ExistentialAny, none, "existential-any")
54+
GROUP(ExistentialMemberAccess, none, "existential-member-access-limitations")
55+
GROUP(ImplementationOnlyDeprecated, none, "implementation-only-deprecated")
56+
GROUP(IsolatedConformances, none, "isolated-conformances")
57+
GROUP(MemberImportVisibility, none, "member-import-visibility")
58+
GROUP(MissingModuleOnKnownPaths, none, "missing-module-on-known-paths")
59+
GROUP(ModuleNotTestable, none, "module-not-testable")
60+
GROUP(ModuleVersionMissing, none, "module-version-missing")
61+
GROUP(MultipleInheritance, none, "multiple-inheritance")
62+
GROUP(MutableGlobalVariable, none, "mutable-global-variable")
63+
GROUP(NominalTypes, none, "nominal-types")
64+
GROUP(NonisolatedNonsendingByDefault, none, "nonisolated-nonsending-by-default")
65+
GROUP(OpaqueTypeInference, none, "opaque-type-inference")
66+
GROUP(PreconcurrencyImport, DefaultIgnoreWarnings, "preconcurrency-import")
67+
GROUP(PropertyWrappers, none, "property-wrapper-requirements")
68+
GROUP(ProtocolTypeNonConformance, none, "protocol-type-non-conformance")
69+
GROUP(ResultBuilderMethods, none, "result-builder-methods")
70+
GROUP(SendableClosureCaptures, none, "sendable-closure-captures")
71+
GROUP(SendableMetatypes, none, "sendable-metatypes")
72+
GROUP(SendingRisksDataRace, none, "sending-risks-data-race")
73+
GROUP(StrictLanguageFeatures, none, "strict-language-features")
74+
GROUP(UnrecognizedStrictLanguageFeatures, DefaultIgnoreWarnings, "strict-language-features")
75+
GROUP_LINK(StrictLanguageFeatures, UnrecognizedStrictLanguageFeatures)
76+
GROUP(StrictMemorySafety, none, "strict-memory-safety")
77+
GROUP(StringInterpolationConformance, none, "string-interpolation-conformance")
78+
GROUP(TemporaryPointers, none, "temporary-pointers")
79+
GROUP(TrailingClosureMatching, none, "trailing-closure-matching")
80+
GROUP(UnknownWarningGroup, none, "unknown-warning-group")
81+
GROUP(CompilationCaching, none, "compilation-caching")
82+
GROUP(WeakMutability, none, "weak-mutability")
8183

82-
GROUP(PerformanceHints, "performance-hints")
83-
GROUP(ReturnTypeImplicitCopy, "return-type-implicit-copy")
84+
GROUP(PerformanceHints, DefaultIgnoreWarnings, "performance-hints")
85+
GROUP(ReturnTypeImplicitCopy, none, "return-type-implicit-copy")
8486
GROUP_LINK(PerformanceHints, ReturnTypeImplicitCopy)
85-
GROUP(ExistentialType, "existential-type")
87+
GROUP(ExistentialType, none, "existential-type")
8688
GROUP_LINK(PerformanceHints, ExistentialType)
8789

8890
#define UNDEFINE_DIAGNOSTIC_GROUPS_MACROS

include/swift/AST/DiagnosticGroups.h

Lines changed: 33 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, Options, Version) 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, Options, Version) ++count;
3746
#include "DiagnosticGroups.def"
3847
return count;
3948
}();
@@ -45,9 +54,29 @@ 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), supergroups(supergroups), subgroups(subgroups),
66+
diagnostics(diagnostics), defaultIgnoreWarnings(defaultIgnoreWarnings) {}
67+
68+
constexpr DiagGroupInfo(DiagGroupID groupID, std::string_view name,
69+
std::string_view documentationFile,
70+
DiagnosticGroupOptions opts,
71+
llvm::ArrayRef<DiagGroupID> supergroups,
72+
llvm::ArrayRef<DiagGroupID> subgroups,
73+
llvm::ArrayRef<DiagID> diagnostics)
74+
: DiagGroupInfo(groupID, name, documentationFile, supergroups,
75+
subgroups, diagnostics,
76+
opts == DiagnosticGroupOptions::DefaultIgnoreWarnings) {}
4877

4978
void traverseDepthFirst(
50-
llvm::function_ref<void(const DiagGroupInfo &)> func) const;
79+
llvm::function_ref<void(const DiagGroupInfo &)> func) const;
5180
};
5281

5382
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/DiagnosticsSema.def

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2842,7 +2842,7 @@ WARNING(add_predates_concurrency_import,none,
28422842
"'Sendable'-related %select{warnings|errors}0 from module %1"
28432843
"%select{| as warnings}0", (bool, Identifier))
28442844
GROUPED_WARNING(remove_predates_concurrency_import,PreconcurrencyImport,
2845-
DefaultIgnore,
2845+
none,
28462846
"'@preconcurrency' on module %0 has no effect", (Identifier))
28472847
WARNING(remove_public_import,none,
28482848
"public import of %0 was not used in public declarations or inlinable code",
@@ -8645,18 +8645,18 @@ GROUPED_ERROR(weak_unowned_in_embedded_swift, EmbeddedRestrictions, none,
86458645
(ReferenceOwnership))
86468646

86478647
GROUPED_WARNING(untyped_throws_in_embedded_swift, EmbeddedRestrictions,
8648-
DefaultIgnore,
8648+
none,
86498649
"untyped throws is not available in Embedded Swift; add a thrown error type with '(type)'", ())
86508650
GROUPED_WARNING(generic_nonfinal_in_embedded_swift, EmbeddedRestrictions,
8651-
DefaultIgnore,
8651+
none,
86528652
"generic %kind0 in a class %select{must be 'final'|cannot be 'required'}1 in Embedded Swift",
86538653
(const Decl *, bool))
86548654
GROUPED_WARNING(use_generic_member_of_existential_in_embedded_swift,
8655-
EmbeddedRestrictions, DefaultIgnore,
8655+
EmbeddedRestrictions, none,
86568656
"cannot use generic %kind0 on a value of type %1 in Embedded Swift",
86578657
(const Decl *, Type))
86588658
GROUPED_WARNING(dynamic_cast_involving_protocol_in_embedded_swift,
8659-
EmbeddedRestrictions, DefaultIgnore,
8659+
EmbeddedRestrictions, none,
86608660
"cannot perform a dynamic cast to a type involving %kind0 in Embedded Swift",
86618661
(const Decl *))
86628662

@@ -8975,33 +8975,33 @@ ERROR(conformance_repression_only_on_struct_class_enum,none,
89758975
// MARK: Swift Performance hints
89768976
//===----------------------------------------------------------------------===//
89778977

8978-
GROUPED_WARNING(perf_hint_function_returns_array,ReturnTypeImplicitCopy,DefaultIgnore,
8978+
GROUPED_WARNING(perf_hint_function_returns_array,ReturnTypeImplicitCopy,none,
89798979
"Performance: %0 returns a%select{ dictionary|n array}1, leading to implicit copies. "
89808980
"Consider using an 'inout' parameter instead.", (const FuncDecl *, bool))
8981-
GROUPED_WARNING(perf_hint_closure_returns_array,ReturnTypeImplicitCopy,DefaultIgnore,
8981+
GROUPED_WARNING(perf_hint_closure_returns_array,ReturnTypeImplicitCopy,none,
89828982
"Performance: closure returns a%select{ dictionary|n array}0, leading to implicit copies. "
89838983
"Consider using an 'inout' parameter instead.", (bool))
89848984

8985-
GROUPED_WARNING(perf_hint_param_expects_existential,ExistentialType,DefaultIgnore,
8985+
GROUPED_WARNING(perf_hint_param_expects_existential,ExistentialType,none,
89868986
"Performance: %0 expects an existential, leading to heap allocation, reference counting, "
89878987
"and dynamic dispatch. Consider using generic constraints or concrete types instead.",
89888988
(const ParamDecl*))
8989-
GROUPED_WARNING(perf_hint_func_returns_existential,ExistentialType,DefaultIgnore,
8989+
GROUPED_WARNING(perf_hint_func_returns_existential,ExistentialType,none,
89908990
"Performance: %0 returns an existential, leading to heap allocation, reference counting, "
89918991
"and dynamic dispatch. Consider using generic constraints or concrete types instead.",
89928992
(const FuncDecl*))
8993-
GROUPED_WARNING(perf_hint_closure_returns_existential,ExistentialType,DefaultIgnore,
8993+
GROUPED_WARNING(perf_hint_closure_returns_existential,ExistentialType,none,
89948994
"Performance: closure returns an existential, leading to heap allocation, reference counting, "
89958995
"and dynamic dispatch. Consider using generic constraints or concrete types instead.", ())
8996-
GROUPED_WARNING(perf_hint_var_uses_existential,ExistentialType,DefaultIgnore,
8996+
GROUPED_WARNING(perf_hint_var_uses_existential,ExistentialType,none,
89978997
"Performance: %0 uses an existential, leading to heap allocation, reference counting, "
89988998
"and dynamic dispatch. Consider using generic constraints or concrete types instead.",
89998999
(const VarDecl *))
9000-
GROUPED_WARNING(perf_hint_any_pattern_uses_existential,ExistentialType,DefaultIgnore,
9000+
GROUPED_WARNING(perf_hint_any_pattern_uses_existential,ExistentialType,none,
90019001
"Performance: declaration uses an existential, leading to heap allocation, reference counting, "
90029002
"and dynamic dispatch. Consider using generic constraints or concrete types instead.",
90039003
())
9004-
GROUPED_WARNING(perf_hint_typealias_uses_existential,ExistentialType,DefaultIgnore,
9004+
GROUPED_WARNING(perf_hint_typealias_uses_existential,ExistentialType,none,
90059005
"Performance: %0 aliases an existential type, leading to heap allocation, reference counting, "
90069006
"and dynamic dispatch. Consider using generic constraints or concrete types instead.",
90079007
(const TypeAliasDecl *))

0 commit comments

Comments
 (0)