Skip to content

Sema: Simplify IsActorRequest::evaluate() to avoid creating a GSB #37798

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

Merged
merged 1 commit into from
Jun 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,12 @@ void swift::addAsyncNotes(AbstractFunctionDecl const* func) {

bool IsActorRequest::evaluate(
Evaluator &evaluator, NominalTypeDecl *nominal) const {
// Protocols are actors if their `Self` type conforms to `Actor`.
// Protocols are actors if they inherit from `Actor`.
if (auto protocol = dyn_cast<ProtocolDecl>(nominal)) {
// Simple case: we have the Actor protocol itself.
if (protocol->isSpecificProtocol(KnownProtocolKind::Actor))
return true;

auto actorProto = nominal->getASTContext().getProtocol(
KnownProtocolKind::Actor);
if (!actorProto)
return false;

auto selfType = Type(protocol->getProtocolSelfType());
auto genericSig = protocol->getGenericSignature();
if (!genericSig)
return false;

return genericSig->requiresProtocol(selfType, actorProto);
auto &ctx = protocol->getASTContext();
auto *actorProtocol = ctx.getProtocol(KnownProtocolKind::Actor);
return (protocol == actorProtocol ||
protocol->inheritsFrom(actorProtocol));
}

// Class declarations are actors if they were declared with "actor".
Expand Down