mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Introduce the notion of a warning that is ignored by default, but enabled by -Wwarning/-Werror
As an example, use this for the "`@preconcurrency` on import has no effect" warning, which is not yet working correctly. This disables it by default but leaves it in place for our testing.
This commit is contained in:
@@ -25,6 +25,7 @@ GROUP(no_group, "")
|
||||
GROUP(DeprecatedDeclaration, "DeprecatedDeclaration.md")
|
||||
GROUP(Unsafe, "Unsafe.md")
|
||||
GROUP(UnknownWarningGroup, "UnknownWarningGroup.md")
|
||||
GROUP(PreconcurrencyImport, "PreconcurrencyImport.md")
|
||||
|
||||
#define UNDEFINE_DIAGNOSTIC_GROUPS_MACROS
|
||||
#include "swift/AST/DefineDiagnosticGroupsMacros.h"
|
||||
|
||||
@@ -2710,8 +2710,9 @@ WARNING(add_predates_concurrency_import,none,
|
||||
"add '@preconcurrency' to %select{suppress|treat}0 "
|
||||
"'Sendable'-related %select{warnings|errors}0 from module %1"
|
||||
"%select{| as warnings}0", (bool, Identifier))
|
||||
WARNING(remove_predates_concurrency_import,none,
|
||||
"'@preconcurrency' attribute on module %0 has no effect", (Identifier))
|
||||
GROUPED_WARNING(remove_predates_concurrency_import,PreconcurrencyImport,
|
||||
DefaultIgnore,
|
||||
"'@preconcurrency' attribute on module %0 has no effect", (Identifier))
|
||||
NOTE(add_preconcurrency_to_conformance,none,
|
||||
"add '@preconcurrency' to the %0 conformance to defer isolation checking to run time", (DeclName))
|
||||
WARNING(remove_public_import,none,
|
||||
|
||||
@@ -74,6 +74,11 @@ enum class DiagnosticOptions {
|
||||
|
||||
/// A diagnostic warning about an unused element.
|
||||
NoUsage,
|
||||
|
||||
/// The diagnostic should be ignored by default, but will be re-enabled
|
||||
/// by various warning options (-Wwarning, -Werror). This only makes sense
|
||||
/// for warnings.
|
||||
DefaultIgnore,
|
||||
};
|
||||
struct StoredDiagnosticInfo {
|
||||
DiagnosticKind kind : 2;
|
||||
@@ -82,15 +87,17 @@ struct StoredDiagnosticInfo {
|
||||
bool isAPIDigesterBreakage : 1;
|
||||
bool isDeprecation : 1;
|
||||
bool isNoUsage : 1;
|
||||
bool defaultIgnore : 1;
|
||||
DiagGroupID groupID;
|
||||
|
||||
constexpr StoredDiagnosticInfo(DiagnosticKind k, bool firstBadToken,
|
||||
bool fatal, bool isAPIDigesterBreakage,
|
||||
bool deprecation, bool noUsage,
|
||||
DiagGroupID groupID)
|
||||
bool defaultIgnore, DiagGroupID groupID)
|
||||
: kind(k), pointsToFirstBadToken(firstBadToken), isFatal(fatal),
|
||||
isAPIDigesterBreakage(isAPIDigesterBreakage),
|
||||
isDeprecation(deprecation), isNoUsage(noUsage), groupID(groupID) {}
|
||||
isDeprecation(deprecation), isNoUsage(noUsage),
|
||||
defaultIgnore(defaultIgnore), groupID(groupID) {}
|
||||
constexpr StoredDiagnosticInfo(DiagnosticKind k, DiagnosticOptions opts,
|
||||
DiagGroupID groupID)
|
||||
: StoredDiagnosticInfo(k,
|
||||
@@ -98,7 +105,9 @@ struct StoredDiagnosticInfo {
|
||||
opts == DiagnosticOptions::Fatal,
|
||||
opts == DiagnosticOptions::APIDigesterBreakage,
|
||||
opts == DiagnosticOptions::Deprecation,
|
||||
opts == DiagnosticOptions::NoUsage, groupID) {}
|
||||
opts == DiagnosticOptions::NoUsage,
|
||||
opts == DiagnosticOptions::DefaultIgnore,
|
||||
groupID) {}
|
||||
};
|
||||
} // end anonymous namespace
|
||||
|
||||
@@ -168,8 +177,12 @@ static constexpr EducationalNotes<NumDiagIDs> _EducationalNotes =
|
||||
static constexpr auto educationalNotes = _EducationalNotes.value;
|
||||
|
||||
DiagnosticState::DiagnosticState() {
|
||||
// Initialize our ignored diagnostics to default
|
||||
ignoredDiagnostics.resize(NumDiagIDs);
|
||||
// Initialize our ignored diagnostics to defaults
|
||||
ignoredDiagnostics.reserve(NumDiagIDs);
|
||||
for (const auto &info : storedDiagnosticInfos) {
|
||||
ignoredDiagnostics.push_back(info.defaultIgnore);
|
||||
}
|
||||
|
||||
// Initialize warningsAsErrors to default
|
||||
warningsAsErrors.resize(DiagGroupsCount);
|
||||
}
|
||||
@@ -547,6 +560,9 @@ void DiagnosticEngine::setWarningsAsErrorsRules(
|
||||
groupID && *groupID != DiagGroupID::no_group) {
|
||||
getDiagGroupInfoByID(*groupID).traverseDepthFirst([&](auto group) {
|
||||
state.setWarningsAsErrorsForDiagGroupID(*groupID, isEnabled);
|
||||
for (DiagID diagID : group.diagnostics) {
|
||||
state.setIgnoredDiagnostic(diagID, false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
unknownGroups.push_back(std::string(name));
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/NonStrictModule.swiftmodule -module-name NonStrictModule %S/Inputs/NonStrictModule.swift
|
||||
// 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
|
||||
|
||||
// RUN: %target-swift-frontend -I %t %s -emit-sil -o /dev/null -verify -parse-as-library -enable-upcoming-feature GlobalConcurrency
|
||||
// RUN: %target-swift-frontend -I %t %s -emit-sil -o /dev/null -verify -strict-concurrency=targeted -parse-as-library -enable-upcoming-feature GlobalConcurrency
|
||||
// RUN: %target-swift-frontend -I %t %s -emit-sil -o /dev/null -verify -strict-concurrency=complete -parse-as-library -enable-upcoming-feature GlobalConcurrency
|
||||
// RUN: %target-swift-frontend -I %t %s -emit-sil -o /dev/null -verify -parse-as-library -enable-upcoming-feature GlobalConcurrency -Wwarning PreconcurrencyImport
|
||||
// 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
|
||||
// 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
|
||||
|
||||
// REQUIRES: concurrency
|
||||
// REQUIRES: swift_feature_GlobalConcurrency
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
|
||||
// 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
|
||||
|
||||
// RUN: %target-swift-frontend -I %t %s -emit-sil -o /dev/null -verify -parse-as-library
|
||||
|
||||
// REQUIRES: concurrency
|
||||
|
||||
@preconcurrency import OtherActors
|
||||
6
userdocs/diagnostic_groups/PreconcurrencyImport.md
Normal file
6
userdocs/diagnostic_groups/PreconcurrencyImport.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# Extraneous @preconcurrency imports
|
||||
|
||||
|
||||
This diagnostic group includes warnings that diagnose `@preconcurrency import`
|
||||
declarations that don't need `@preconcurrency`. It is an experimental warning
|
||||
that is currently disabled.
|
||||
Reference in New Issue
Block a user