Skip to content

Commit f075e4e

Browse files
committed
Change DiagnosticBehavior into a struct enum so we can put methods on it.
The reason why I am making this change is because I want to put a merge operation on DiagnosticBehavior. This merge operation allows for DiagnosticBehavior to work like a lattice. When one merges, one moves potentially from fatal, error to things like note, ignore.
1 parent 8139450 commit f075e4e

File tree

4 files changed

+31
-20
lines changed

4 files changed

+31
-20
lines changed

include/swift/AST/DiagnosticEngine.h

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -428,14 +428,29 @@ namespace swift {
428428

429429
/// Describes the current behavior to take with a diagnostic.
430430
/// Ordered from most severe to least.
431-
enum class DiagnosticBehavior : uint8_t {
432-
Unspecified = 0,
433-
Fatal,
434-
Error,
435-
Warning,
436-
Remark,
437-
Note,
438-
Ignore,
431+
struct DiagnosticBehavior {
432+
enum Kind : uint8_t {
433+
Unspecified = 0,
434+
Fatal,
435+
Error,
436+
Warning,
437+
Remark,
438+
Note,
439+
Ignore,
440+
};
441+
442+
Kind kind;
443+
444+
DiagnosticBehavior() : kind(Unspecified) {}
445+
DiagnosticBehavior(Kind kind) : kind(kind) {}
446+
operator Kind() const { return kind; }
447+
448+
/// Move up the lattice returning the max value.
449+
DiagnosticBehavior merge(DiagnosticBehavior other) const {
450+
auto value = std::max(std::underlying_type<Kind>::type(*this),
451+
std::underlying_type<Kind>::type(other));
452+
return Kind(value);
453+
}
439454
};
440455

441456
struct DiagnosticFormatOptions {

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@
4545

4646
namespace swift {
4747

48-
enum class DiagnosticBehavior : uint8_t;
48+
struct DiagnosticBehavior;
4949

5050
/// Kind of implicit platform conditions.
5151
enum class PlatformConditionKind {
52-
#define PLATFORM_CONDITION(LABEL, IDENTIFIER) LABEL,
53-
#include "swift/AST/PlatformConditionKinds.def"
52+
#define PLATFORM_CONDITION(LABEL, IDENTIFIER) LABEL,
53+
#include "swift/AST/PlatformConditionKinds.def"
5454
};
5555

5656
/// Describes how strict concurrency checking should be.

include/swift/Sema/Concurrency.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class SourceFile;
2929
class NominalTypeDecl;
3030
class VarDecl;
3131

32-
enum class DiagnosticBehavior: uint8_t;
32+
struct DiagnosticBehavior;
3333

3434
/// If any of the imports in this source file was @preconcurrency but there were
3535
/// no diagnostics downgraded or suppressed due to that @preconcurrency, suggest

lib/SILOptimizer/Mandatory/TransferNonSendable.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,12 @@ getDiagnosticBehaviorLimitForCapturedValue(CapturedValue value) {
122122
static std::optional<DiagnosticBehavior>
123123
getDiagnosticBehaviorLimitForCapturedValues(
124124
ArrayRef<CapturedValue> capturedValues) {
125-
using UnderlyingType = std::underlying_type<DiagnosticBehavior>::type;
126-
127125
std::optional<DiagnosticBehavior> diagnosticBehavior;
128126
for (auto value : capturedValues) {
129-
auto lhs = UnderlyingType(
130-
diagnosticBehavior.value_or(DiagnosticBehavior::Unspecified));
131-
auto rhs = UnderlyingType(
132-
getDiagnosticBehaviorLimitForCapturedValue(value).value_or(
133-
DiagnosticBehavior::Unspecified));
134-
auto result = DiagnosticBehavior(std::max(lhs, rhs));
127+
auto lhs = diagnosticBehavior.value_or(DiagnosticBehavior::Unspecified);
128+
auto rhs = getDiagnosticBehaviorLimitForCapturedValue(value).value_or(
129+
DiagnosticBehavior::Unspecified);
130+
auto result = lhs.merge(rhs);
135131
if (result != DiagnosticBehavior::Unspecified)
136132
diagnosticBehavior = result;
137133
}

0 commit comments

Comments
 (0)