Skip to content

Commit 6e9eb59

Browse files
committed
[CodeCompletion] Remove warning for 'async in non-concurrency context'
This warnings don't give much benefits for developers. Code completion UI tends to show them unusable. But usually, developers can modify the context to accept async calls, e.g. by wrapping it with `Task { }` rdar://126737530
1 parent 35cda47 commit 6e9eb59

10 files changed

+58
-70
lines changed

include/swift/IDE/CodeCompletionResult.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ enum class NotRecommendedReason : uint8_t {
261261
RedundantImportIndirect, // contextual
262262
Deprecated, // context-free
263263
SoftDeprecated, // context-free
264-
InvalidAsyncContext, // contextual
265264
CrossActorReference, // contextual
266265
VariableUsedInOwnDefinition, // contextual
267266
NonAsyncAlternativeUsedInAsyncContext, // contextual
@@ -300,8 +299,6 @@ enum class ContextualNotRecommendedReason : uint8_t {
300299
None = 0,
301300
RedundantImport,
302301
RedundantImportIndirect,
303-
/// A method that is async is being used in a non-async context.
304-
InvalidAsyncContext,
305302
CrossActorReference,
306303
VariableUsedInOwnDefinition,
307304
/// A method that is sync and has an async alternative is used in an async
@@ -716,8 +713,6 @@ class CodeCompletionResult {
716713
return NotRecommendedReason::RedundantImport;
717714
case ContextualNotRecommendedReason::RedundantImportIndirect:
718715
return NotRecommendedReason::RedundantImportIndirect;
719-
case ContextualNotRecommendedReason::InvalidAsyncContext:
720-
return NotRecommendedReason::InvalidAsyncContext;
721716
case ContextualNotRecommendedReason::NonAsyncAlternativeUsedInAsyncContext:
722717
return NotRecommendedReason::NonAsyncAlternativeUsedInAsyncContext;
723718
case ContextualNotRecommendedReason::CrossActorReference:

lib/IDE/CodeCompletionDiagnostics.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,6 @@ bool swift::ide::getContextualCompletionDiagnostics(
166166
const ASTContext &Ctx) {
167167
CodeCompletionDiagnostics Diag(Ctx);
168168
switch (Reason) {
169-
case ContextualNotRecommendedReason::InvalidAsyncContext:
170-
// FIXME: Could we use 'diag::async_in_nonasync_function'?
171-
return Diag.getDiagnostics(
172-
Severity, Out, diag::ide_async_in_nonasync_context, NameForDiagnostics);
173169
case ContextualNotRecommendedReason::CrossActorReference:
174170
return Diag.getDiagnostics(Severity, Out,
175171
diag::ide_cross_actor_reference_swift5,

lib/IDE/CodeCompletionResult.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,6 @@ ContextFreeCodeCompletionResult::calculateContextualNotRecommendedReason(
399399
if (explicitReason != ContextualNotRecommendedReason::None) {
400400
return explicitReason;
401401
}
402-
if (IsAsync && !canCurrDeclContextHandleAsync) {
403-
return ContextualNotRecommendedReason::InvalidAsyncContext;
404-
}
405402
if (HasAsyncAlternative && canCurrDeclContextHandleAsync) {
406403
return ContextualNotRecommendedReason::
407404
NonAsyncAlternativeUsedInAsyncContext;

test/IDE/complete_actorisolation.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,37 @@ extension MyActor {
2020
// IN_SYNCFUNC-DAG: Decl[InstanceMethod]/CurrNominal: syncFunc()[#Int#];
2121
// IN_SYNCFUNC-DAG: Decl[InstanceMethod]/CurrNominal: syncNonSendable({#arg: MyNonSendable#})[#Int#];
2222
// IN_SYNCFUNC-DAG: Decl[InstanceMethod]/CurrNominal: syncSendable({#arg: MySendable#})[#Int#];
23-
// IN_SYNCFUNC-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended: asyncFunc()[' async'][#Int#];
23+
// IN_SYNCFUNC-DAG: Decl[InstanceMethod]/CurrNominal: asyncFunc()[' async'][#Int#];
2424

2525
let _ = self.#^IN_SYNCFUNC_SELF_DOT^#
2626
// IN_SYNCFUNC_SELF_DOT-DAG: Decl[InstanceVar]/CurrNominal: property[#Int#];
2727
// IN_SYNCFUNC_SELF_DOT-DAG: Decl[InstanceMethod]/CurrNominal: syncFunc()[#Int#];
2828
// IN_SYNCFUNC_SELF_DOT-DAG: Decl[InstanceMethod]/CurrNominal: syncNonSendable({#arg: MyNonSendable#})[#Int#];
2929
// IN_SYNCFUNC_SELF_DOT-DAG: Decl[InstanceMethod]/CurrNominal: syncSendable({#arg: MySendable#})[#Int#];
30-
// IN_SYNCFUNC_SELF_DOT-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended: asyncFunc()[' async'][#Int#];
30+
// IN_SYNCFUNC_SELF_DOT-DAG: Decl[InstanceMethod]/CurrNominal: asyncFunc()[' async'][#Int#];
3131

3232
let _ = self#^IN_SYNCFUNC_SELF_NODOT^#
3333
// IN_SYNCFUNC_SELF_NODOT-DAG: Decl[InstanceVar]/CurrNominal: .property[#Int#];
3434
// IN_SYNCFUNC_SELF_NODOT-DAG: Decl[InstanceMethod]/CurrNominal: .syncFunc()[#Int#];
3535
// IN_SYNCFUNC_SELF_NODOT-DAG: Decl[InstanceMethod]/CurrNominal: .syncNonSendable({#arg: MyNonSendable#})[#Int#];
3636
// IN_SYNCFUNC_SELF_NODOT-DAG: Decl[InstanceMethod]/CurrNominal: .syncSendable({#arg: MySendable#})[#Int#];
37-
// IN_SYNCFUNC_SELF_NODOT-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended: .asyncFunc()[' async'][#Int#];
37+
// IN_SYNCFUNC_SELF_NODOT-DAG: Decl[InstanceMethod]/CurrNominal: .asyncFunc()[' async'][#Int#];
3838
// IN_SYNCFUNC_SELF_NODOT-DAG: Decl[Subscript]/CurrNominal: [{#(idx): Int#}][#Int#];
3939

4040
let _ = other.#^IN_SYNCFUNC_OTHER_DOT^#
41-
// IN_SYNCFUNC_OTHER_DOT-DAG: Decl[InstanceVar]/CurrNominal/NotRecommended: property[#Int#][' async'];
42-
// IN_SYNCFUNC_OTHER_DOT-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended: syncFunc()[' async'][#Int#];
41+
// IN_SYNCFUNC_OTHER_DOT-DAG: Decl[InstanceVar]/CurrNominal: property[#Int#][' async'];
42+
// IN_SYNCFUNC_OTHER_DOT-DAG: Decl[InstanceMethod]/CurrNominal: syncFunc()[' async'][#Int#];
4343
// IN_SYNCFUNC_OTHER_DOT-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended: syncNonSendable({#arg: MyNonSendable#})[' async'][#Int#];
44-
// IN_SYNCFUNC_OTHER_DOT-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended: syncSendable({#arg: MySendable#})[' async'][#Int#];
45-
// IN_SYNCFUNC_OTHER_DOT-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended: asyncFunc()[' async'][#Int#];
44+
// IN_SYNCFUNC_OTHER_DOT-DAG: Decl[InstanceMethod]/CurrNominal: syncSendable({#arg: MySendable#})[' async'][#Int#];
45+
// IN_SYNCFUNC_OTHER_DOT-DAG: Decl[InstanceMethod]/CurrNominal: asyncFunc()[' async'][#Int#];
4646

4747
let _ = other#^IN_SYNCFUNC_OTHER_NODOT^#
48-
// IN_SYNCFUNC_OTHER_NODOT-DAG: Decl[InstanceVar]/CurrNominal/NotRecommended: .property[#Int#][' async'];
49-
// IN_SYNCFUNC_OTHER_NODOT-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended: .syncFunc()[' async'][#Int#];
48+
// IN_SYNCFUNC_OTHER_NODOT-DAG: Decl[InstanceVar]/CurrNominal: .property[#Int#][' async'];
49+
// IN_SYNCFUNC_OTHER_NODOT-DAG: Decl[InstanceMethod]/CurrNominal: .syncFunc()[' async'][#Int#];
5050
// IN_SYNCFUNC_OTHER_NODOT-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended: .syncNonSendable({#arg: MyNonSendable#})[' async'][#Int#];
51-
// IN_SYNCFUNC_OTHER_NODOT-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended: .syncSendable({#arg: MySendable#})[' async'][#Int#];
52-
// IN_SYNCFUNC_OTHER_NODOT-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended: .asyncFunc()[' async'][#Int#];
53-
// IN_SYNCFUNC_OTHER_NODOT-DAG: Decl[Subscript]/CurrNominal/NotRecommended: [{#(idx): Int#}][' async'][#Int#];
51+
// IN_SYNCFUNC_OTHER_NODOT-DAG: Decl[InstanceMethod]/CurrNominal: .syncSendable({#arg: MySendable#})[' async'][#Int#];
52+
// IN_SYNCFUNC_OTHER_NODOT-DAG: Decl[InstanceMethod]/CurrNominal: .asyncFunc()[' async'][#Int#];
53+
// IN_SYNCFUNC_OTHER_NODOT-DAG: Decl[Subscript]/CurrNominal: [{#(idx): Int#}][' async'][#Int#];
5454
}
5555
func testAsyncFunc(other: MyActor) async {
5656
let _ = #^IN_ASYNCFUNC^#

test/IDE/complete_async_context.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ func throwingTask() async throws -> String {
2828
}
2929

3030
// CHECK_syncContext-DAG: Decl[FreeFunction]/CurrModule: funcThrows()[' throws'][#Void#];
31-
// CHECK_syncContext-DAG: Decl[FreeFunction]/CurrModule/NotRecommended: asyncRethrows({#fn: () async throws -> Int##() async throws -> Int#})[' async'][' rethrows'][#Int#];
32-
// CHECK_syncContext-DAG: Decl[FreeFunction]/CurrModule/NotRecommended: asyncRethrows({#fn: () async throws -> String##() async throws -> String#})[' async'][' rethrows'][#String#];
33-
// CHECK_syncContext-DAG: Decl[FreeFunction]/CurrModule/NotRecommended: invokeAuto({#(val): T#})[' async'][' rethrows'][#T#];
34-
// CHECK_syncContext-DAG: Decl[FreeFunction]/CurrModule/NotRecommended: throwingTask()[' async'][' throws'][#String#];
35-
// CHECK_syncContext-DAG: Decl[FreeFunction]/CurrModule/NotRecommended: invoke({#fn: () async throws -> T##() async throws -> T#})[' async'][' rethrows'][#T#];
36-
// CHECK_syncContext-DAG: Decl[FreeFunction]/CurrModule/NotRecommended: normalTask()[' async'][#Int#];
31+
// CHECK_syncContext-DAG: Decl[FreeFunction]/CurrModule: asyncRethrows({#fn: () async throws -> Int##() async throws -> Int#})[' async'][' rethrows'][#Int#];
32+
// CHECK_syncContext-DAG: Decl[FreeFunction]/CurrModule: asyncRethrows({#fn: () async throws -> String##() async throws -> String#})[' async'][' rethrows'][#String#];
33+
// CHECK_syncContext-DAG: Decl[FreeFunction]/CurrModule: invokeAuto({#(val): T#})[' async'][' rethrows'][#T#];
34+
// CHECK_syncContext-DAG: Decl[FreeFunction]/CurrModule: throwingTask()[' async'][' throws'][#String#];
35+
// CHECK_syncContext-DAG: Decl[FreeFunction]/CurrModule: invoke({#fn: () async throws -> T##() async throws -> T#})[' async'][' rethrows'][#T#];
36+
// CHECK_syncContext-DAG: Decl[FreeFunction]/CurrModule: normalTask()[' async'][#Int#];
3737

3838
// CHECK_asyncContext-DAG: Decl[FreeFunction]/CurrModule: funcThrows()[' throws'][#Void#];
3939
// CHECK_asyncContext-DAG: Decl[FreeFunction]/CurrModule: asyncRethrows({#fn: () async throws -> Int##() async throws -> Int#})[' async'][' rethrows'][#Int#];

test/IDE/complete_cache_notrecommended.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import MyModule
2020

2121
func testSync() -> Int{
2222
#^GLOBAL_IN_SYNC^#
23-
// GLOBAL_IN_SYNC-DAG: Decl[FreeFunction]/OtherModule[MyModule]/NotRecommended/TypeRelation[Convertible]: globalAsyncFunc()[' async'][#Int#];
23+
// GLOBAL_IN_SYNC-DAG: Decl[FreeFunction]/OtherModule[MyModule]/TypeRelation[Convertible]: globalAsyncFunc()[' async'][#Int#];
2424
// GLOBAL_IN_SYNC-DAG: Decl[FreeFunction]/OtherModule[MyModule]/NotRecommended: deprecatedFunc()[#Void#];
2525
// GLOBAL_IN_SYNC-DAG: Decl[Actor]/OtherModule[MyModule]: MyActor[#MyActor#];
2626
}
@@ -34,7 +34,7 @@ func testSyncMember(obj: MyActor) -> Int {
3434
obj.#^MEMBER_IN_SYNC^#
3535
// MEMBER_IN_SYNC: Begin completions, 9 items
3636
// MEMBER_IN_SYNC-DAG: Keyword[self]/CurrNominal: self[#MyActor#];
37-
// MEMBER_IN_SYNC-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended/TypeRelation[Convertible]: actorMethod()[' async'][#Int#];
37+
// MEMBER_IN_SYNC-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Convertible]: actorMethod()[' async'][#Int#];
3838
// MEMBER_IN_SYNC-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended: deprecatedMethod()[' async'][#Void#];
3939
// MEMBER_IN_SYNC-DAG: Decl[InstanceVar]/CurrNominal: unownedExecutor[#UnownedSerialExecutor#];
4040
// MEMBER_IN_SYNC-DAG: Decl[InstanceMethod]/Super/IsSystem: preconditionIsolated()[#Void#]; name=preconditionIsolated()

test/IDE/complete_diagnostics_concurrency.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ actor MyActor {
1717

1818
func testAsyncContext() {
1919
#^SYNC_CONTEXT^#
20-
// SYNC_CONTEXT-DAG: Decl[FreeFunction]/CurrModule/NotRecommended: asyncFunc()[' async'][#Void#]; name=asyncFunc(); diagnostics=error:async 'asyncFunc()' used in a context that does not support concurrency{{$}}
20+
// SYNC_CONTEXT-DAG: Decl[FreeFunction]/CurrModule: asyncFunc()[' async'][#Void#]; name=asyncFunc(){{$}}
2121
// SYNC_CONTEXT-DAG: Decl[FreeFunction]/CurrModule: syncFunc()[#Void#]; name=syncFunc(){{$}}
2222
}
2323

@@ -29,7 +29,7 @@ func testActor(obj: MyActor) async {
2929

3030
func testClosure(obj: (Int) async -> Void) {
3131
obj(#^CLOSURE_CALL^#)
32-
// CLOSURE_CALL-DAG: Pattern/Local/Flair[ArgLabels]/NotRecommended: ['(']{#Int#}[')'][' async'][#Void#]; name=; diagnostics=error:async function used in a context that does not support concurrency
32+
// CLOSURE_CALL-DAG: Pattern/Local/Flair[ArgLabels]: ['(']{#Int#}[')'][' async'][#Void#]; name={{$}}
3333
}
3434

3535
func test() {
@@ -45,9 +45,9 @@ func test() {
4545

4646
let foo = Foo()
4747
foo.#^EXPLICITLY_ASYNC_PROPERTY^#
48-
// EXPLICITLY_ASYNC_PROPERTY-DAG: Decl[InstanceVar]/CurrNominal/NotRecommended: value[#String?#][' async']; name=value; diagnostics=error:async 'value' used in a context that does not support concurrency
48+
// EXPLICITLY_ASYNC_PROPERTY-DAG: Decl[InstanceVar]/CurrNominal: value[#String?#][' async']; name=value{{$}}
4949

5050
#^EXPLICIT_GLOBAL_VAR^#
51-
// EXPLICIT_GLOBAL_VAR-DAG: Decl[LocalVar]/Local/NotRecommended: globalValue[#String?#][' async']; name=globalValue; diagnostics=error:async 'globalValue' used in a context that does not support concurrency
51+
// EXPLICIT_GLOBAL_VAR-DAG: Decl[LocalVar]/Local: globalValue[#String?#][' async']; name=globalValue{{$}}
5252

5353
}

0 commit comments

Comments
 (0)