Skip to content

Commit 60c7261

Browse files
committed
[Completion] Complete .isolation for @isolated(any) functions
This was added in SE-0431. rdar://124615036
1 parent a13c9d2 commit 60c7261

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

include/swift/IDE/CompletionLookup.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
510510

511511
bool tryTupleExprCompletions(Type ExprType);
512512

513+
/// Try add the completion for '.isolation' for @isolated(any) function types.
514+
void tryFunctionIsolationCompletion(Type ExprType);
515+
513516
bool tryFunctionCallCompletions(
514517
Type ExprType, const ValueDecl *VD,
515518
std::optional<SemanticContextKind> SemanticContext = std::nullopt);

lib/IDE/CompletionLookup.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,6 +2301,18 @@ bool CompletionLookup::tryTupleExprCompletions(Type ExprType) {
23012301
return true;
23022302
}
23032303

2304+
void CompletionLookup::tryFunctionIsolationCompletion(Type ExprType) {
2305+
auto *FT = ExprType->getAs<FunctionType>();
2306+
if (!FT || !FT->getIsolation().isErased())
2307+
return;
2308+
2309+
// The type of `.isolation` is `(any Actor)?`
2310+
auto *actorProto = Ctx.getProtocol(KnownProtocolKind::Actor);
2311+
auto memberTy = OptionalType::get(actorProto->getDeclaredExistentialType());
2312+
2313+
addBuiltinMemberRef(Ctx.Id_isolation.str(), memberTy);
2314+
}
2315+
23042316
bool CompletionLookup::tryFunctionCallCompletions(
23052317
Type ExprType, const ValueDecl *VD,
23062318
std::optional<SemanticContextKind> SemanticContext) {
@@ -2378,6 +2390,9 @@ bool CompletionLookup::tryUnwrappedCompletions(Type ExprType, bool isIUO) {
23782390
}
23792391
if (NumBytesToEraseForOptionalUnwrap <=
23802392
CodeCompletionResult::MaxNumBytesToErase) {
2393+
// Add '.isolation' to @isolated(any) functions.
2394+
tryFunctionIsolationCompletion(Unwrapped);
2395+
23812396
if (!tryTupleExprCompletions(Unwrapped)) {
23822397
lookupVisibleMemberDecls(*this, Unwrapped, DotLoc,
23832398
CurrDeclContext,
@@ -2453,6 +2468,10 @@ void CompletionLookup::getValueExprCompletions(Type ExprType, ValueDecl *VD,
24532468
ExprType = OptionalType::get(ExprType);
24542469

24552470
// Handle special cases
2471+
2472+
// Add '.isolation' to @isolated(any) functions.
2473+
tryFunctionIsolationCompletion(ExprType);
2474+
24562475
bool isIUO = VD && VD->isImplicitlyUnwrappedOptional();
24572476
if (tryFunctionCallCompletions(ExprType, IsDeclUnapplied ? VD : nullptr))
24582477
return;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %batch-code-completion
2+
3+
// REQUIRES: concurrency
4+
5+
func test1(_ x: () -> Void) {
6+
x.#^NORMAL_FN^#
7+
// NORMAL_FN: Begin completions, 2 items
8+
// NORMAL_FN-DAG: Keyword[self]/CurrNominal: self[#() -> Void#]; name=self
9+
// NORMAL_FN-DAG: Pattern/CurrModule/Flair[ArgLabels]/Erase[1]: ()[#Void#]; name=()
10+
}
11+
12+
func test2(_ x: @isolated(any) () -> Void) {
13+
x.#^ISOLATED_ANY_FN^#
14+
// ISOLATED_ANY_FN: Begin completions, 3 items
15+
// ISOLATED_ANY_FN-DAG: Pattern/CurrNominal: isolation[#(any Actor)?#]; name=isolation
16+
// ISOLATED_ANY_FN-DAG: Keyword[self]/CurrNominal: self[#@isolated(any) () -> Void#]; name=self
17+
// ISOLATED_ANY_FN-DAG: Pattern/CurrModule/Flair[ArgLabels]/Erase[1]: ()[#Void#]; name=()
18+
}
19+
20+
func test3(_ x: (@isolated(any) () -> Void)?) {
21+
x.#^ISOLATED_ANY_OPTIONAL_FN^#
22+
// ISOLATED_ANY_OPTIONAL_FN-DAG: Pattern/CurrNominal/Erase[1]: ?.isolation[#(any Actor)?#]; name=isolation
23+
// ISOLATED_ANY_OPTIONAL_FN-DAG: Keyword[self]/CurrNominal: self[#(@isolated(any) () -> Void)?#]; name=self
24+
}

0 commit comments

Comments
 (0)