Skip to content

Commit f7cae0d

Browse files
committed
Remove an unneeded function parameter by inlining its body.
There is only one call site of this helper function, so we are not gaining any flexibility by doing this. It only makes it harder to reason about what the function actually does without providing any benefit. I am doing this before I make in the next commit an actual semantic changing commit to ease review. (cherry picked from commit 0027229)
1 parent 76602e4 commit f7cae0d

File tree

2 files changed

+32
-43
lines changed

2 files changed

+32
-43
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,12 +1624,37 @@ bool ReferencedActor::isKnownToBeLocal() const {
16241624
}
16251625
}
16261626

1627-
static AbstractFunctionDecl const *
1628-
isActorInitOrDeInitContext(const DeclContext *dc) {
1629-
return swift::isActorInitOrDeInitContext(
1630-
dc, [](const AbstractClosureExpr *closure) {
1631-
return isSendableClosure(closure, /*forActorIsolation=*/false);
1632-
});
1627+
const AbstractFunctionDecl *
1628+
swift::isActorInitOrDeInitContext(const DeclContext *dc) {
1629+
while (true) {
1630+
// Non-Sendable closures are considered part of the enclosing context.
1631+
if (auto *closure = dyn_cast<AbstractClosureExpr>(dc)) {
1632+
if (isSendableClosure(closure, /*for actor isolation*/ false))
1633+
return nullptr;
1634+
1635+
dc = dc->getParent();
1636+
continue;
1637+
}
1638+
1639+
if (auto func = dyn_cast<AbstractFunctionDecl>(dc)) {
1640+
// If this is an initializer or deinitializer of an actor, we're done.
1641+
if ((isa<ConstructorDecl>(func) || isa<DestructorDecl>(func)) &&
1642+
getSelfActorDecl(dc->getParent()))
1643+
return func;
1644+
1645+
// Non-Sendable local functions are considered part of the enclosing
1646+
// context.
1647+
if (func->getDeclContext()->isLocalContext()) {
1648+
if (func->isSendable())
1649+
return nullptr;
1650+
1651+
dc = dc->getParent();
1652+
continue;
1653+
}
1654+
}
1655+
1656+
return nullptr;
1657+
}
16331658
}
16341659

16351660
static bool isStoredProperty(ValueDecl const *member) {
@@ -6452,40 +6477,6 @@ bool swift::completionContextUsesConcurrencyFeatures(const DeclContext *dc) {
64526477
});
64536478
}
64546479

6455-
AbstractFunctionDecl const *swift::isActorInitOrDeInitContext(
6456-
const DeclContext *dc,
6457-
llvm::function_ref<bool(const AbstractClosureExpr *)> isSendable) {
6458-
while (true) {
6459-
// Non-Sendable closures are considered part of the enclosing context.
6460-
if (auto *closure = dyn_cast<AbstractClosureExpr>(dc)) {
6461-
if (isSendable(closure))
6462-
return nullptr;
6463-
6464-
dc = dc->getParent();
6465-
continue;
6466-
}
6467-
6468-
if (auto func = dyn_cast<AbstractFunctionDecl>(dc)) {
6469-
// If this is an initializer or deinitializer of an actor, we're done.
6470-
if ((isa<ConstructorDecl>(func) || isa<DestructorDecl>(func)) &&
6471-
getSelfActorDecl(dc->getParent()))
6472-
return func;
6473-
6474-
// Non-Sendable local functions are considered part of the enclosing
6475-
// context.
6476-
if (func->getDeclContext()->isLocalContext()) {
6477-
if (func->isSendable())
6478-
return nullptr;
6479-
6480-
dc = dc->getParent();
6481-
continue;
6482-
}
6483-
}
6484-
6485-
return nullptr;
6486-
}
6487-
}
6488-
64896480
/// Find the directly-referenced parameter or capture of a parameter for
64906481
/// for the given expression.
64916482
VarDecl *swift::getReferencedParamOrCapture(

lib/Sema/TypeCheckConcurrency.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,9 +591,7 @@ ProtocolConformance *deriveImplicitSendableConformance(Evaluator &evaluator,
591591
/// Check whether we are in an actor's initializer or deinitializer.
592592
/// \returns nullptr iff we are not in such a declaration. Otherwise,
593593
/// returns a pointer to the declaration.
594-
AbstractFunctionDecl const *isActorInitOrDeInitContext(
595-
const DeclContext *dc,
596-
llvm::function_ref<bool(const AbstractClosureExpr *)> isSendable);
594+
const AbstractFunctionDecl *isActorInitOrDeInitContext(const DeclContext *dc);
597595

598596
/// Determine whether this declaration is always accessed asynchronously.
599597
bool isAsyncDecl(ConcreteDeclRef declRef);

0 commit comments

Comments
 (0)