Skip to content

Commit

Permalink
[Concurrency] Allow ActorIsolation in diagnostic messages.
Browse files Browse the repository at this point in the history
ActorIsolation is rendered as a descriptive phrase before an entity,
e.g, "actor-independent" or "global actor 'UIActor'-isolated" when
used in diagnostics.
  • Loading branch information
DougGregor committed Oct 14, 2020
1 parent f089ba9 commit 2f7ff6a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/swift/AST/ActorIsolation.h
Expand Up @@ -16,6 +16,7 @@
#ifndef SWIFT_AST_ACTORISOLATIONSTATE_H
#define SWIFT_AST_ACTORISOLATIONSTATE_H

#include "swift/AST/Type.h"
#include "llvm/ADT/Hashing.h"

namespace llvm {
Expand Down
14 changes: 14 additions & 0 deletions include/swift/AST/DiagnosticEngine.h
Expand Up @@ -18,6 +18,7 @@
#ifndef SWIFT_BASIC_DIAGNOSTICENGINE_H
#define SWIFT_BASIC_DIAGNOSTICENGINE_H

#include "swift/AST/ActorIsolation.h"
#include "swift/AST/DeclNameLoc.h"
#include "swift/AST/DiagnosticConsumer.h"
#include "swift/AST/TypeLoc.h"
Expand Down Expand Up @@ -93,6 +94,7 @@ namespace swift {
DeclAttribute,
VersionTuple,
LayoutConstraint,
ActorIsolation,
};

namespace diag {
Expand Down Expand Up @@ -122,6 +124,7 @@ namespace swift {
const DeclAttribute *DeclAttributeVal;
llvm::VersionTuple VersionVal;
LayoutConstraint LayoutConstraintVal;
ActorIsolation ActorIsolationVal;
};

public:
Expand Down Expand Up @@ -209,6 +212,12 @@ namespace swift {
DiagnosticArgument(LayoutConstraint L)
: Kind(DiagnosticArgumentKind::LayoutConstraint), LayoutConstraintVal(L) {
}

DiagnosticArgument(ActorIsolation AI)
: Kind(DiagnosticArgumentKind::ActorIsolation),
ActorIsolationVal(AI) {
}

/// Initializes a diagnostic argument using the underlying type of the
/// given enum.
template<
Expand Down Expand Up @@ -299,6 +308,11 @@ namespace swift {
assert(Kind == DiagnosticArgumentKind::LayoutConstraint);
return LayoutConstraintVal;
}

ActorIsolation getAsActorIsolation() const {
assert(Kind == DiagnosticArgumentKind::ActorIsolation);
return ActorIsolationVal;
}
};

struct DiagnosticFormatOptions {
Expand Down
20 changes: 20 additions & 0 deletions lib/AST/DiagnosticEngine.cpp
Expand Up @@ -660,6 +660,26 @@ static void formatDiagnosticArgument(StringRef Modifier,
Out << FormatOpts.OpeningQuotationMark << Arg.getAsLayoutConstraint()
<< FormatOpts.ClosingQuotationMark;
break;
case DiagnosticArgumentKind::ActorIsolation:
switch (auto isolation = Arg.getAsActorIsolation()) {
case ActorIsolation::ActorInstance:
Out << "actor-isolated";
break;

case ActorIsolation::GlobalActor:
Out << "global actor " << FormatOpts.OpeningQuotationMark
<< isolation.getGlobalActor().getString()
<< FormatOpts.ClosingQuotationMark << "-isolated";
break;

case ActorIsolation::Independent:
Out << "actor-independent";
break;

case ActorIsolation::Unspecified:
Out << "non-actor-isolated";
break;
}
}
}

Expand Down

0 comments on commit 2f7ff6a

Please sign in to comment.