Skip to content

Commit ca6cde6

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.
1 parent 5e27999 commit ca6cde6

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
@@ -1625,12 +1625,37 @@ bool ReferencedActor::isKnownToBeLocal() const {
16251625
}
16261626
}
16271627

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

16361661
static bool isStoredProperty(ValueDecl const *member) {
@@ -6467,40 +6492,6 @@ bool swift::completionContextUsesConcurrencyFeatures(const DeclContext *dc) {
64676492
});
64686493
}
64696494

6470-
AbstractFunctionDecl const *swift::isActorInitOrDeInitContext(
6471-
const DeclContext *dc,
6472-
llvm::function_ref<bool(const AbstractClosureExpr *)> isSendable) {
6473-
while (true) {
6474-
// Non-Sendable closures are considered part of the enclosing context.
6475-
if (auto *closure = dyn_cast<AbstractClosureExpr>(dc)) {
6476-
if (isSendable(closure))
6477-
return nullptr;
6478-
6479-
dc = dc->getParent();
6480-
continue;
6481-
}
6482-
6483-
if (auto func = dyn_cast<AbstractFunctionDecl>(dc)) {
6484-
// If this is an initializer or deinitializer of an actor, we're done.
6485-
if ((isa<ConstructorDecl>(func) || isa<DestructorDecl>(func)) &&
6486-
getSelfActorDecl(dc->getParent()))
6487-
return func;
6488-
6489-
// Non-Sendable local functions are considered part of the enclosing
6490-
// context.
6491-
if (func->getDeclContext()->isLocalContext()) {
6492-
if (func->isSendable())
6493-
return nullptr;
6494-
6495-
dc = dc->getParent();
6496-
continue;
6497-
}
6498-
}
6499-
6500-
return nullptr;
6501-
}
6502-
}
6503-
65046495
/// Find the directly-referenced parameter or capture of a parameter for
65056496
/// for the given expression.
65066497
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)