Skip to content

Commit a061f4f

Browse files
authored
Merge pull request swiftlang#78500 from DougGregor/preconcurrency-import-unused-suppress
Introduce the notion of a warning that is ignored by default, but enabled by -Wwarning/-Werror
2 parents c44bfa5 + 63c9882 commit a061f4f

File tree

7 files changed

+44
-10
lines changed

7 files changed

+44
-10
lines changed

include/swift/AST/DiagnosticEngine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ namespace swift {
5454

5555
enum class CXXStdlibKind : uint8_t;
5656
enum class DescriptivePatternKind : uint8_t;
57+
enum class DiagGroupID : uint16_t;
5758
enum class SelfAccessKind : uint8_t;
5859
enum class ReferenceOwnership : uint8_t;
5960
enum class StaticSpellingKind : uint8_t;

include/swift/AST/DiagnosticGroups.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ GROUP(no_group, "")
2525
GROUP(DeprecatedDeclaration, "DeprecatedDeclaration.md")
2626
GROUP(Unsafe, "Unsafe.md")
2727
GROUP(UnknownWarningGroup, "UnknownWarningGroup.md")
28+
GROUP(PreconcurrencyImport, "PreconcurrencyImport.md")
2829

2930
#define UNDEFINE_DIAGNOSTIC_GROUPS_MACROS
3031
#include "swift/AST/DefineDiagnosticGroupsMacros.h"

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,8 +2710,9 @@ WARNING(add_predates_concurrency_import,none,
27102710
"add '@preconcurrency' to %select{suppress|treat}0 "
27112711
"'Sendable'-related %select{warnings|errors}0 from module %1"
27122712
"%select{| as warnings}0", (bool, Identifier))
2713-
WARNING(remove_predates_concurrency_import,none,
2714-
"'@preconcurrency' attribute on module %0 has no effect", (Identifier))
2713+
GROUPED_WARNING(remove_predates_concurrency_import,PreconcurrencyImport,
2714+
DefaultIgnore,
2715+
"'@preconcurrency' attribute on module %0 has no effect", (Identifier))
27152716
NOTE(add_preconcurrency_to_conformance,none,
27162717
"add '@preconcurrency' to the %0 conformance to defer isolation checking to run time", (DeclName))
27172718
WARNING(remove_public_import,none,

lib/AST/DiagnosticEngine.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ enum class DiagnosticOptions {
7474

7575
/// A diagnostic warning about an unused element.
7676
NoUsage,
77+
78+
/// The diagnostic should be ignored by default, but will be re-enabled
79+
/// by various warning options (-Wwarning, -Werror). This only makes sense
80+
/// for warnings.
81+
DefaultIgnore,
7782
};
7883
struct StoredDiagnosticInfo {
7984
DiagnosticKind kind : 2;
@@ -82,23 +87,27 @@ struct StoredDiagnosticInfo {
8287
bool isAPIDigesterBreakage : 1;
8388
bool isDeprecation : 1;
8489
bool isNoUsage : 1;
90+
bool defaultIgnore : 1;
8591
DiagGroupID groupID;
8692

8793
constexpr StoredDiagnosticInfo(DiagnosticKind k, bool firstBadToken,
8894
bool fatal, bool isAPIDigesterBreakage,
8995
bool deprecation, bool noUsage,
90-
DiagGroupID groupID)
96+
bool defaultIgnore, DiagGroupID groupID)
9197
: kind(k), pointsToFirstBadToken(firstBadToken), isFatal(fatal),
9298
isAPIDigesterBreakage(isAPIDigesterBreakage),
93-
isDeprecation(deprecation), isNoUsage(noUsage), groupID(groupID) {}
99+
isDeprecation(deprecation), isNoUsage(noUsage),
100+
defaultIgnore(defaultIgnore), groupID(groupID) {}
94101
constexpr StoredDiagnosticInfo(DiagnosticKind k, DiagnosticOptions opts,
95102
DiagGroupID groupID)
96103
: StoredDiagnosticInfo(k,
97104
opts == DiagnosticOptions::PointsToFirstBadToken,
98105
opts == DiagnosticOptions::Fatal,
99106
opts == DiagnosticOptions::APIDigesterBreakage,
100107
opts == DiagnosticOptions::Deprecation,
101-
opts == DiagnosticOptions::NoUsage, groupID) {}
108+
opts == DiagnosticOptions::NoUsage,
109+
opts == DiagnosticOptions::DefaultIgnore,
110+
groupID) {}
102111
};
103112
} // end anonymous namespace
104113

@@ -168,8 +177,12 @@ static constexpr EducationalNotes<NumDiagIDs> _EducationalNotes =
168177
static constexpr auto educationalNotes = _EducationalNotes.value;
169178

170179
DiagnosticState::DiagnosticState() {
171-
// Initialize our ignored diagnostics to default
172-
ignoredDiagnostics.resize(NumDiagIDs);
180+
// Initialize our ignored diagnostics to defaults
181+
ignoredDiagnostics.reserve(NumDiagIDs);
182+
for (const auto &info : storedDiagnosticInfos) {
183+
ignoredDiagnostics.push_back(info.defaultIgnore);
184+
}
185+
173186
// Initialize warningsAsErrors to default
174187
warningsAsErrors.resize(DiagGroupsCount);
175188
}
@@ -547,6 +560,9 @@ void DiagnosticEngine::setWarningsAsErrorsRules(
547560
groupID && *groupID != DiagGroupID::no_group) {
548561
getDiagGroupInfoByID(*groupID).traverseDepthFirst([&](auto group) {
549562
state.setWarningsAsErrorsForDiagGroupID(*groupID, isEnabled);
563+
for (DiagID diagID : group.diagnostics) {
564+
state.setIgnoredDiagnostic(diagID, false);
565+
}
550566
});
551567
} else {
552568
unknownGroups.push_back(std::string(name));

test/Concurrency/predates_concurrency_import.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/NonStrictModule.swiftmodule -module-name NonStrictModule %S/Inputs/NonStrictModule.swift
44
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/OtherActors.swiftmodule -module-name OtherActors %S/Inputs/OtherActors.swift -target %target-swift-5.1-abi-triple
55

6-
// RUN: %target-swift-frontend -I %t %s -emit-sil -o /dev/null -verify -parse-as-library -enable-upcoming-feature GlobalConcurrency
7-
// RUN: %target-swift-frontend -I %t %s -emit-sil -o /dev/null -verify -strict-concurrency=targeted -parse-as-library -enable-upcoming-feature GlobalConcurrency
8-
// RUN: %target-swift-frontend -I %t %s -emit-sil -o /dev/null -verify -strict-concurrency=complete -parse-as-library -enable-upcoming-feature GlobalConcurrency
6+
// RUN: %target-swift-frontend -I %t %s -emit-sil -o /dev/null -verify -parse-as-library -enable-upcoming-feature GlobalConcurrency -Wwarning PreconcurrencyImport
7+
// RUN: %target-swift-frontend -I %t %s -emit-sil -o /dev/null -verify -strict-concurrency=targeted -parse-as-library -enable-upcoming-feature GlobalConcurrency -Wwarning PreconcurrencyImport
8+
// RUN: %target-swift-frontend -I %t %s -emit-sil -o /dev/null -verify -strict-concurrency=complete -parse-as-library -enable-upcoming-feature GlobalConcurrency -Wwarning PreconcurrencyImport
99

1010
// REQUIRES: concurrency
1111
// REQUIRES: swift_feature_GlobalConcurrency
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/OtherActors.swiftmodule -module-name OtherActors %S/Inputs/OtherActors.swift -target %target-swift-5.1-abi-triple
4+
5+
// RUN: %target-swift-frontend -I %t %s -emit-sil -o /dev/null -verify -parse-as-library
6+
7+
// REQUIRES: concurrency
8+
9+
@preconcurrency import OtherActors
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Extraneous @preconcurrency imports
2+
3+
4+
This diagnostic group includes warnings that diagnose `@preconcurrency import`
5+
declarations that don't need `@preconcurrency`. It is an experimental warning
6+
that is currently disabled.

0 commit comments

Comments
 (0)