Skip to content

Commit 2f7ff6a

Browse files
committed
[Concurrency] Allow ActorIsolation in diagnostic messages.
ActorIsolation is rendered as a descriptive phrase before an entity, e.g, "actor-independent" or "global actor 'UIActor'-isolated" when used in diagnostics.
1 parent f089ba9 commit 2f7ff6a

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

include/swift/AST/ActorIsolation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#ifndef SWIFT_AST_ACTORISOLATIONSTATE_H
1717
#define SWIFT_AST_ACTORISOLATIONSTATE_H
1818

19+
#include "swift/AST/Type.h"
1920
#include "llvm/ADT/Hashing.h"
2021

2122
namespace llvm {

include/swift/AST/DiagnosticEngine.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef SWIFT_BASIC_DIAGNOSTICENGINE_H
1919
#define SWIFT_BASIC_DIAGNOSTICENGINE_H
2020

21+
#include "swift/AST/ActorIsolation.h"
2122
#include "swift/AST/DeclNameLoc.h"
2223
#include "swift/AST/DiagnosticConsumer.h"
2324
#include "swift/AST/TypeLoc.h"
@@ -93,6 +94,7 @@ namespace swift {
9394
DeclAttribute,
9495
VersionTuple,
9596
LayoutConstraint,
97+
ActorIsolation,
9698
};
9799

98100
namespace diag {
@@ -122,6 +124,7 @@ namespace swift {
122124
const DeclAttribute *DeclAttributeVal;
123125
llvm::VersionTuple VersionVal;
124126
LayoutConstraint LayoutConstraintVal;
127+
ActorIsolation ActorIsolationVal;
125128
};
126129

127130
public:
@@ -209,6 +212,12 @@ namespace swift {
209212
DiagnosticArgument(LayoutConstraint L)
210213
: Kind(DiagnosticArgumentKind::LayoutConstraint), LayoutConstraintVal(L) {
211214
}
215+
216+
DiagnosticArgument(ActorIsolation AI)
217+
: Kind(DiagnosticArgumentKind::ActorIsolation),
218+
ActorIsolationVal(AI) {
219+
}
220+
212221
/// Initializes a diagnostic argument using the underlying type of the
213222
/// given enum.
214223
template<
@@ -299,6 +308,11 @@ namespace swift {
299308
assert(Kind == DiagnosticArgumentKind::LayoutConstraint);
300309
return LayoutConstraintVal;
301310
}
311+
312+
ActorIsolation getAsActorIsolation() const {
313+
assert(Kind == DiagnosticArgumentKind::ActorIsolation);
314+
return ActorIsolationVal;
315+
}
302316
};
303317

304318
struct DiagnosticFormatOptions {

lib/AST/DiagnosticEngine.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,26 @@ static void formatDiagnosticArgument(StringRef Modifier,
660660
Out << FormatOpts.OpeningQuotationMark << Arg.getAsLayoutConstraint()
661661
<< FormatOpts.ClosingQuotationMark;
662662
break;
663+
case DiagnosticArgumentKind::ActorIsolation:
664+
switch (auto isolation = Arg.getAsActorIsolation()) {
665+
case ActorIsolation::ActorInstance:
666+
Out << "actor-isolated";
667+
break;
668+
669+
case ActorIsolation::GlobalActor:
670+
Out << "global actor " << FormatOpts.OpeningQuotationMark
671+
<< isolation.getGlobalActor().getString()
672+
<< FormatOpts.ClosingQuotationMark << "-isolated";
673+
break;
674+
675+
case ActorIsolation::Independent:
676+
Out << "actor-independent";
677+
break;
678+
679+
case ActorIsolation::Unspecified:
680+
Out << "non-actor-isolated";
681+
break;
682+
}
663683
}
664684
}
665685

0 commit comments

Comments
 (0)