Skip to content

Commit 51c5d05

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 2ee9b16 commit 51c5d05

File tree

11 files changed

+203
-130
lines changed

11 files changed

+203
-130
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: 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: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35,57 +35,58 @@
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(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, none, "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, none, "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

9091
GROUP_LINK(PerformanceHints, ExistentialType)
9192
GROUP_LINK(PerformanceHints, ReturnTypeImplicitCopy)

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
@@ -2845,7 +2845,7 @@ WARNING(add_predates_concurrency_import,none,
28452845
"'Sendable'-related %select{warnings|errors}0 from module %1"
28462846
"%select{| as warnings}0", (bool, Identifier))
28472847
GROUPED_WARNING(remove_predates_concurrency_import,PreconcurrencyImport,
2848-
DefaultIgnore,
2848+
none,
28492849
"'@preconcurrency' on module %0 has no effect", (Identifier))
28502850
WARNING(remove_public_import,none,
28512851
"public import of %0 was not used in public declarations or inlinable code",
@@ -8648,18 +8648,18 @@ GROUPED_ERROR(weak_unowned_in_embedded_swift, EmbeddedRestrictions, none,
86488648
(ReferenceOwnership))
86498649

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

@@ -8978,33 +8978,33 @@ ERROR(conformance_repression_only_on_struct_class_enum,none,
89788978
// MARK: Swift Performance hints
89798979
//===----------------------------------------------------------------------===//
89808980

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

8988-
GROUPED_WARNING(perf_hint_param_expects_existential,ExistentialType,DefaultIgnore,
8988+
GROUPED_WARNING(perf_hint_param_expects_existential,ExistentialType,none,
89898989
"Performance: %0 expects an existential, leading to heap allocation, reference counting, "
89908990
"and dynamic dispatch. Consider using generic constraints or concrete types instead.",
89918991
(const ParamDecl*))
8992-
GROUPED_WARNING(perf_hint_func_returns_existential,ExistentialType,DefaultIgnore,
8992+
GROUPED_WARNING(perf_hint_func_returns_existential,ExistentialType,none,
89938993
"Performance: %0 returns an existential, leading to heap allocation, reference counting, "
89948994
"and dynamic dispatch. Consider using generic constraints or concrete types instead.",
89958995
(const FuncDecl*))
8996-
GROUPED_WARNING(perf_hint_closure_returns_existential,ExistentialType,DefaultIgnore,
8996+
GROUPED_WARNING(perf_hint_closure_returns_existential,ExistentialType,none,
89978997
"Performance: closure returns an existential, leading to heap allocation, reference counting, "
89988998
"and dynamic dispatch. Consider using generic constraints or concrete types instead.", ())
8999-
GROUPED_WARNING(perf_hint_var_uses_existential,ExistentialType,DefaultIgnore,
8999+
GROUPED_WARNING(perf_hint_var_uses_existential,ExistentialType,none,
90009000
"Performance: %0 uses an existential, leading to heap allocation, reference counting, "
90019001
"and dynamic dispatch. Consider using generic constraints or concrete types instead.",
90029002
(const VarDecl *))
9003-
GROUPED_WARNING(perf_hint_any_pattern_uses_existential,ExistentialType,DefaultIgnore,
9003+
GROUPED_WARNING(perf_hint_any_pattern_uses_existential,ExistentialType,none,
90049004
"Performance: declaration uses an existential, leading to heap allocation, reference counting, "
90059005
"and dynamic dispatch. Consider using generic constraints or concrete types instead.",
90069006
())
9007-
GROUPED_WARNING(perf_hint_typealias_uses_existential,ExistentialType,DefaultIgnore,
9007+
GROUPED_WARNING(perf_hint_typealias_uses_existential,ExistentialType,none,
90089008
"Performance: %0 aliases an existential type, leading to heap allocation, reference counting, "
90099009
"and dynamic dispatch. Consider using generic constraints or concrete types instead.",
90109010
(const TypeAliasDecl *))

0 commit comments

Comments
 (0)