-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Diagnostics] Add -no-warning-as-error to except a specific warning from being treated as an error #74466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Diagnostics] Add -no-warning-as-error to except a specific warning from being treated as an error #74466
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//===--- DefineDiagnosticGroupsMacros.def -----------------------*- C++ -*-===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file defines macros defining diagnostic groups. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// Define macros | ||
#if defined(DEFINE_DIAGNOSTIC_GROUPS_MACROS) && \ | ||
!defined(UNDEFINE_DIAGNOSTIC_GROUPS_MACROS) | ||
|
||
#undef DEFINE_DIAGNOSTIC_GROUPS_MACROS | ||
|
||
#if !(defined(GROUP) || defined(GROUP_LINK)) | ||
#error No reqired macros defined. Define at least one of the following macros: GROUP(Name, DocsFile), GROUP_LINK(Parent, Child) | ||
#endif | ||
|
||
// GROUP macro: | ||
// Declares a diagnostic group. | ||
// Parameters: | ||
// Name - group name as it appears in DiagGroupID enum and DiagGroupInfo.name | ||
// DocsFile - file with a human readable description for the group located in | ||
// userdocs/diagnostic_groups | ||
#ifndef GROUP | ||
#define GROUP(Name, DocsFile) | ||
#endif | ||
|
||
// GROUP_LINK macro: | ||
// Establishes an edge in the diagnostic group graph between | ||
// a supergroup(Parent) and its subgroup(Child). | ||
// Parameters: | ||
// Parent - parent group name | ||
// Child - child group name | ||
#ifndef GROUP_LINK | ||
#define GROUP_LINK(Parent, Child) | ||
#endif | ||
|
||
// Undefine macros | ||
#elif defined(UNDEFINE_DIAGNOSTIC_GROUPS_MACROS) && \ | ||
!defined(DEFINE_DIAGNOSTIC_GROUPS_MACROS) | ||
|
||
#undef UNDEFINE_DIAGNOSTIC_GROUPS_MACROS | ||
|
||
#ifdef GROUP | ||
#undef GROUP | ||
#else | ||
#error Trying to undefine the diagnostic groups macros, but GROUP macro wasn't defined | ||
#endif | ||
|
||
#ifdef GROUP_LINK | ||
#undef GROUP_LINK | ||
#else | ||
#error Trying to undefine the diagnostic groups macros, but GROUP_LINK macro wasn't defined | ||
#endif | ||
|
||
#else | ||
#error Invalid DefineDiagnosticGroupsMacros.h inclusion | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
#include "swift/AST/TypeLoc.h" | ||
#include "swift/Basic/Statistic.h" | ||
#include "swift/Basic/Version.h" | ||
#include "swift/Basic/WarningAsErrorRule.h" | ||
#include "swift/Localization/LocalizationFormat.h" | ||
#include "llvm/ADT/BitVector.h" | ||
#include "llvm/ADT/StringRef.h" | ||
|
@@ -851,8 +852,8 @@ namespace swift { | |
/// Don't emit any remarks | ||
bool suppressRemarks = false; | ||
|
||
/// Emit all warnings as errors | ||
bool warningsAsErrors = false; | ||
/// Treat these warnings as errors. Indicies here corespond to DiagID enum | ||
llvm::BitVector warningsAsErrors; | ||
|
||
/// Whether a fatal error has occurred | ||
bool fatalErrorOccurred = false; | ||
|
@@ -893,9 +894,22 @@ namespace swift { | |
void setSuppressRemarks(bool val) { suppressRemarks = val; } | ||
bool getSuppressRemarks() const { return suppressRemarks; } | ||
|
||
/// Whether to treat warnings as errors | ||
void setWarningsAsErrors(bool val) { warningsAsErrors = val; } | ||
bool getWarningsAsErrors() const { return warningsAsErrors; } | ||
/// Whether a warning should be upgraded to an error or not | ||
void setWarningAsErrorForDiagID(DiagID id, bool value) { | ||
warningsAsErrors[(unsigned)id] = value; | ||
} | ||
bool getWarningAsErrorForDiagID(DiagID id) { | ||
return warningsAsErrors[(unsigned)id]; | ||
} | ||
|
||
/// Whether all warnings should be upgraded to errors or not | ||
void setAllWarningsAsErrors(bool value) { | ||
if (value) { | ||
warningsAsErrors.set(); | ||
} else { | ||
warningsAsErrors.reset(); | ||
} | ||
} | ||
|
||
void resetHadAnyError() { | ||
anyErrorOccurred = false; | ||
|
@@ -1105,11 +1119,13 @@ namespace swift { | |
return state.getSuppressRemarks(); | ||
} | ||
|
||
/// Whether to treat warnings as errors | ||
void setWarningsAsErrors(bool val) { state.setWarningsAsErrors(val); } | ||
bool getWarningsAsErrors() const { | ||
return state.getWarningsAsErrors(); | ||
} | ||
/// Apply rules specifing what warnings should or shouldn't be treated as | ||
/// errors. For group rules the string is either a group name defined by | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no "or" to go with the "either here". |
||
/// DiagnosticGroups.def | ||
/// Rules are applied in order they appear in the vector. | ||
/// In case the vector contains rules affecting the same diagnostic ID | ||
/// the last rule wins. | ||
void setWarningsAsErrorsRules(const std::vector<WarningAsErrorRule> &rules); | ||
|
||
/// Whether to print diagnostic names after their messages | ||
void setPrintDiagnosticNames(bool val) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//===--- DiagnosticGroups.def - Diagnostic Groups ---------------*- C++ -*-===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file defines diagnostic groups and links between them. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#define DEFINE_DIAGNOSTIC_GROUPS_MACROS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not critical now, but at some point we'd want a big comment here documenting what it means to define a new group. |
||
#include "swift/AST/DefineDiagnosticGroupsMacros.h" | ||
|
||
// GROUP(Name, DocsFile) | ||
// GROUP_LINK(Parent, Child) | ||
|
||
GROUP(no_group, "") | ||
|
||
GROUP(deprecated, "deprecated.md") | ||
GROUP_LINK(deprecated, availability_deprecated) | ||
|
||
GROUP(availability_deprecated, "availability_deprecated.md") | ||
|
||
GROUP(unknown_warning_group, "unknown_warning_group.md") | ||
|
||
#define UNDEFINE_DIAGNOSTIC_GROUPS_MACROS | ||
#include "swift/AST/DefineDiagnosticGroupsMacros.h" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//===--- DiagnosticGroups.h - Diagnostic Groups -----------------*- C++ -*-===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file defines the diagnostic groups enumaration, group graph | ||
// and auxilary functions. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef SWIFT_DIAGNOSTICGROUPS_H | ||
#define SWIFT_DIAGNOSTICGROUPS_H | ||
|
||
#include "swift/AST/DiagnosticList.h" | ||
#include "llvm/ADT/ArrayRef.h" | ||
#include <array> | ||
#include <string_view> | ||
#include <unordered_map> | ||
|
||
namespace swift { | ||
|
||
enum class DiagGroupID : uint16_t { | ||
#define GROUP(Name, Version) Name, | ||
#include "swift/AST/DiagnosticGroups.def" | ||
}; | ||
|
||
constexpr const auto DiagGroupsCount = [] { | ||
size_t count = 0; | ||
#define GROUP(Name, Version) count++; | ||
#include "DiagnosticGroups.def" | ||
return count; | ||
}(); | ||
|
||
struct DiagGroupInfo { | ||
DiagGroupID id; | ||
std::string_view name; | ||
DmT021 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
std::string_view version; | ||
llvm::ArrayRef<DiagGroupID> supergroups; | ||
llvm::ArrayRef<DiagGroupID> subgroups; | ||
llvm::ArrayRef<DiagID> diagnostics; | ||
|
||
void traverseDepthFirst( | ||
llvm::function_ref<void(const DiagGroupInfo &)> func) const; | ||
}; | ||
|
||
extern const std::array<DiagGroupInfo, DiagGroupsCount> diagnosticGroupsInfo; | ||
const DiagGroupInfo &getDiagGroupInfoByID(DiagGroupID id); | ||
std::optional<DiagGroupID> getDiagGroupIDByName(std::string_view name); | ||
|
||
} // end namespace swift | ||
|
||
#endif /* SWIFT_DIAGNOSTICGROUPS_H */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//===--- DiagnosticList.h - Diagnostic Definitions --------------*- C++ -*-===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file defines all of the diagnostics emitted by Swift. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef SWIFT_DIAGNOSTICLIST_H | ||
#define SWIFT_DIAGNOSTICLIST_H | ||
|
||
#include <cstdint> | ||
|
||
namespace swift { | ||
|
||
/// Enumeration describing all of possible diagnostics. | ||
/// | ||
/// Each of the diagnostics described in Diagnostics.def has an entry in | ||
/// this enumeration type that uniquely identifies it. | ||
enum class DiagID : uint32_t { | ||
#define DIAG(KIND, ID, Group, Options, Text, Signature) ID, | ||
#include "swift/AST/DiagnosticsAll.def" | ||
}; | ||
static_assert(static_cast<uint32_t>(swift::DiagID::invalid_diagnostic) == 0, | ||
"0 is not the invalid diagnostic ID"); | ||
|
||
enum class FixItID : uint32_t { | ||
#define DIAG(KIND, ID, Group, Options, Text, Signature) | ||
#define FIXIT(ID, Text, Signature) ID, | ||
#include "swift/AST/DiagnosticsAll.def" | ||
}; | ||
|
||
} // end namespace swift | ||
|
||
#endif /* SWIFT_DIAGNOSTICLIST_H */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typos "indicies" (for indices) and "corespond"