Skip to content

Commit f62ff9b

Browse files
authored
Merge pull request #73628 from rintaro/completion-async-not-async-rdar126737530
[CodeCompletion] Remove warning for 'async in non-concurrency context'
2 parents 59cb571 + 61eb531 commit f62ff9b

17 files changed

+80
-159
lines changed

include/swift/AST/DiagnosticsIDE.def

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@
1515

1616
//===----------------------------------------------------------------------===//
1717

18-
ERROR(ide_async_in_nonasync_context, none,
19-
"async %0 used in a context that does not support concurrency",
20-
(StringRef))
21-
22-
// NOTE: This is WARNING because this is emitted for cross actor references with
23-
// non-'Sendable' types. That is optionally ('-warn-concurrency') warning in
24-
// Swift 5.5.
25-
WARNING(ide_cross_actor_reference_swift5, none,
26-
"actor-isolated %0 should only be referenced from inside the actor",
27-
(StringRef))
28-
2918
WARNING(ide_has_async_alternative, none,
3019
"%0 has an async alternative that should be preferred in an async "
3120
"context", (StringRef))

include/swift/IDE/CodeCompletionResult.h

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,6 @@ enum class NotRecommendedReason : uint8_t {
261261
RedundantImportIndirect, // contextual
262262
Deprecated, // context-free
263263
SoftDeprecated, // context-free
264-
InvalidAsyncContext, // contextual
265-
CrossActorReference, // contextual
266264
VariableUsedInOwnDefinition, // contextual
267265
NonAsyncAlternativeUsedInAsyncContext, // contextual
268266

@@ -300,9 +298,6 @@ enum class ContextualNotRecommendedReason : uint8_t {
300298
None = 0,
301299
RedundantImport,
302300
RedundantImportIndirect,
303-
/// A method that is async is being used in a non-async context.
304-
InvalidAsyncContext,
305-
CrossActorReference,
306301
VariableUsedInOwnDefinition,
307302
/// A method that is sync and has an async alternative is used in an async
308303
/// context.
@@ -374,7 +369,6 @@ class ContextFreeCodeCompletionResult {
374369
CodeCompletionMacroRoles MacroRoles;
375370

376371
bool IsSystem : 1;
377-
bool IsAsync : 1;
378372
/// Whether the result has been annotated as having an async alternative that
379373
/// should be preferred in async contexts.
380374
bool HasAsyncAlternative : 1;
@@ -409,7 +403,7 @@ class ContextFreeCodeCompletionResult {
409403
ContextFreeCodeCompletionResult(
410404
CodeCompletionResultKind Kind, uint8_t AssociatedKind,
411405
CodeCompletionOperatorKind KnownOperatorKind,
412-
CodeCompletionMacroRoles MacroRoles, bool IsSystem, bool IsAsync,
406+
CodeCompletionMacroRoles MacroRoles, bool IsSystem,
413407
bool HasAsyncAlternative, CodeCompletionString *CompletionString,
414408
NullTerminatedStringRef ModuleName,
415409
NullTerminatedStringRef BriefDocComment,
@@ -421,7 +415,7 @@ class ContextFreeCodeCompletionResult {
421415
NullTerminatedStringRef FilterName,
422416
NullTerminatedStringRef NameForDiagnostics)
423417
: Kind(Kind), KnownOperatorKind(KnownOperatorKind),
424-
MacroRoles(MacroRoles), IsSystem(IsSystem), IsAsync(IsAsync),
418+
MacroRoles(MacroRoles), IsSystem(IsSystem),
425419
HasAsyncAlternative(HasAsyncAlternative),
426420
CompletionString(CompletionString), ModuleName(ModuleName),
427421
BriefDocComment(BriefDocComment), AssociatedUSRs(AssociatedUSRs),
@@ -438,8 +432,6 @@ class ContextFreeCodeCompletionResult {
438432
"Completion item should have diagnostic message iff the diagnostics "
439433
"severity is not none");
440434
assert(CompletionString && "Result should have a completion string");
441-
assert(!(HasAsyncAlternative && IsAsync) &&
442-
"A function shouldn't be both async and have an async alternative");
443435
if (isOperator() && KnownOperatorKind == CodeCompletionOperatorKind::None) {
444436
this->KnownOperatorKind = getCodeCompletionOperatorKind(CompletionString);
445437
}
@@ -456,7 +448,7 @@ class ContextFreeCodeCompletionResult {
456448
static ContextFreeCodeCompletionResult *createPatternOrBuiltInOperatorResult(
457449
CodeCompletionResultSink &Sink, CodeCompletionResultKind Kind,
458450
CodeCompletionString *CompletionString,
459-
CodeCompletionOperatorKind KnownOperatorKind, bool IsAsync,
451+
CodeCompletionOperatorKind KnownOperatorKin,
460452
NullTerminatedStringRef BriefDocComment,
461453
CodeCompletionResultType ResultType,
462454
ContextFreeNotRecommendedReason NotRecommended,
@@ -494,7 +486,7 @@ class ContextFreeCodeCompletionResult {
494486
static ContextFreeCodeCompletionResult *
495487
createDeclResult(CodeCompletionResultSink &Sink,
496488
CodeCompletionString *CompletionString,
497-
const Decl *AssociatedDecl, bool IsAsync,
489+
const Decl *AssociatedDecl,
498490
bool HasAsyncAlternative, NullTerminatedStringRef ModuleName,
499491
NullTerminatedStringRef BriefDocComment,
500492
ArrayRef<NullTerminatedStringRef> AssociatedUSRs,
@@ -533,8 +525,6 @@ class ContextFreeCodeCompletionResult {
533525

534526
bool isSystem() const { return IsSystem; };
535527

536-
bool isAsync() const { return IsAsync; };
537-
538528
bool hasAsyncAlternative() const { return HasAsyncAlternative; };
539529

540530
CodeCompletionString *getCompletionString() const { return CompletionString; }
@@ -716,12 +706,8 @@ class CodeCompletionResult {
716706
return NotRecommendedReason::RedundantImport;
717707
case ContextualNotRecommendedReason::RedundantImportIndirect:
718708
return NotRecommendedReason::RedundantImportIndirect;
719-
case ContextualNotRecommendedReason::InvalidAsyncContext:
720-
return NotRecommendedReason::InvalidAsyncContext;
721709
case ContextualNotRecommendedReason::NonAsyncAlternativeUsedInAsyncContext:
722710
return NotRecommendedReason::NonAsyncAlternativeUsedInAsyncContext;
723-
case ContextualNotRecommendedReason::CrossActorReference:
724-
return NotRecommendedReason::CrossActorReference;
725711
case ContextualNotRecommendedReason::VariableUsedInOwnDefinition:
726712
return NotRecommendedReason::VariableUsedInOwnDefinition;
727713
}

lib/IDE/CodeCompletionCache.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ CodeCompletionCache::~CodeCompletionCache() {}
104104
/// This should be incremented any time we commit a change to the format of the
105105
/// cached results. This isn't expected to change very often.
106106
static constexpr uint32_t onDiskCompletionCacheVersion =
107-
11; // Added macro roles
107+
12; // Removed 'IsAsync'.
108108

109109
/// Deserializes CodeCompletionResults from \p in and stores them in \p V.
110110
/// \see writeCacheModule.
@@ -236,7 +236,6 @@ static bool readCachedModule(llvm::MemoryBuffer *in,
236236
auto diagSeverity =
237237
static_cast<CodeCompletionDiagnosticSeverity>(*cursor++);
238238
auto isSystem = static_cast<bool>(*cursor++);
239-
auto isAsync = static_cast<bool>(*cursor++);
240239
auto hasAsyncAlternative = static_cast<bool>(*cursor++);
241240
auto chunkIndex = read32le(cursor);
242241
auto moduleIndex = read32le(cursor);
@@ -267,8 +266,8 @@ static bool readCachedModule(llvm::MemoryBuffer *in,
267266

268267
ContextFreeCodeCompletionResult *result =
269268
new (*V.Allocator) ContextFreeCodeCompletionResult(
270-
kind, associatedKind, opKind, roles, isSystem, isAsync,
271-
hasAsyncAlternative, string, moduleName, briefDocComment,
269+
kind, associatedKind, opKind, roles, isSystem,
270+
hasAsyncAlternative, string, moduleName, briefDocComment,
272271
llvm::ArrayRef(assocUSRs).copy(*V.Allocator),
273272
CodeCompletionResultType(resultTypes), notRecommended, diagSeverity,
274273
diagMessage, filterName, nameForDiagnostics);
@@ -428,7 +427,6 @@ static void writeCachedModule(llvm::raw_ostream &out,
428427
LE.write(static_cast<uint8_t>(R->getNotRecommendedReason()));
429428
LE.write(static_cast<uint8_t>(R->getDiagnosticSeverity()));
430429
LE.write(static_cast<uint8_t>(R->isSystem()));
431-
LE.write(static_cast<uint8_t>(R->isAsync()));
432430
LE.write(static_cast<uint8_t>(R->hasAsyncAlternative()));
433431
LE.write(
434432
static_cast<uint32_t>(addCompletionString(R->getCompletionString())));

lib/IDE/CodeCompletionDiagnostics.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +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);
173-
case ContextualNotRecommendedReason::CrossActorReference:
174-
return Diag.getDiagnostics(Severity, Out,
175-
diag::ide_cross_actor_reference_swift5,
176-
NameForDiagnostics);
177169
case ContextualNotRecommendedReason::RedundantImport:
178170
return Diag.getDiagnostics(Severity, Out, diag::ide_redundant_import,
179171
NameForDiagnostics);

lib/IDE/CodeCompletionResult.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ ContextFreeCodeCompletionResult *
121121
ContextFreeCodeCompletionResult::createPatternOrBuiltInOperatorResult(
122122
CodeCompletionResultSink &Sink, CodeCompletionResultKind Kind,
123123
CodeCompletionString *CompletionString,
124-
CodeCompletionOperatorKind KnownOperatorKind, bool IsAsync,
125-
NullTerminatedStringRef BriefDocComment,
124+
CodeCompletionOperatorKind KnownOperatorKind, NullTerminatedStringRef BriefDocComment,
126125
CodeCompletionResultType ResultType,
127126
ContextFreeNotRecommendedReason NotRecommended,
128127
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
@@ -138,7 +137,7 @@ ContextFreeCodeCompletionResult::createPatternOrBuiltInOperatorResult(
138137
}
139138
return new (Sink.getAllocator()) ContextFreeCodeCompletionResult(
140139
Kind, /*AssociatedKind=*/0, KnownOperatorKind, /*MacroRoles=*/{},
141-
/*IsSystem=*/false, IsAsync, /*HasAsyncAlternative=*/false,
140+
/*IsSystem=*/false, /*HasAsyncAlternative=*/false,
142141
CompletionString,
143142
/*ModuleName=*/"", BriefDocComment,
144143
/*AssociatedUSRs=*/{}, ResultType, NotRecommended, DiagnosticSeverity,
@@ -159,8 +158,7 @@ ContextFreeCodeCompletionResult::createKeywordResult(
159158
return new (Sink.getAllocator()) ContextFreeCodeCompletionResult(
160159
CodeCompletionResultKind::Keyword, static_cast<uint8_t>(Kind),
161160
CodeCompletionOperatorKind::None, /*MacroRoles=*/{},
162-
/*IsSystem=*/false, /*IsAsync=*/false,
163-
/*HasAsyncAlternative=*/false, CompletionString,
161+
/*IsSystem=*/false, /*HasAsyncAlternative=*/false, CompletionString,
164162
/*ModuleName=*/"", BriefDocComment,
165163
/*AssociatedUSRs=*/{}, ResultType, ContextFreeNotRecommendedReason::None,
166164
CodeCompletionDiagnosticSeverity::None, /*DiagnosticMessage=*/"",
@@ -179,7 +177,7 @@ ContextFreeCodeCompletionResult::createLiteralResult(
179177
return new (Sink.getAllocator()) ContextFreeCodeCompletionResult(
180178
CodeCompletionResultKind::Literal, static_cast<uint8_t>(LiteralKind),
181179
CodeCompletionOperatorKind::None, /*MacroRoles=*/{},
182-
/*IsSystem=*/false, /*IsAsync=*/false, /*HasAsyncAlternative=*/false,
180+
/*IsSystem=*/false, /*HasAsyncAlternative=*/false,
183181
CompletionString,
184182
/*ModuleName=*/"",
185183
/*BriefDocComment=*/"",
@@ -207,7 +205,7 @@ getDeclNameForDiagnostics(const Decl *D, CodeCompletionResultSink &Sink) {
207205
ContextFreeCodeCompletionResult *
208206
ContextFreeCodeCompletionResult::createDeclResult(
209207
CodeCompletionResultSink &Sink, CodeCompletionString *CompletionString,
210-
const Decl *AssociatedDecl, bool IsAsync, bool HasAsyncAlternative,
208+
const Decl *AssociatedDecl, bool HasAsyncAlternative,
211209
NullTerminatedStringRef ModuleName, NullTerminatedStringRef BriefDocComment,
212210
ArrayRef<NullTerminatedStringRef> AssociatedUSRs,
213211
CodeCompletionResultType ResultType,
@@ -222,7 +220,7 @@ ContextFreeCodeCompletionResult::createDeclResult(
222220
CodeCompletionResultKind::Declaration,
223221
static_cast<uint8_t>(getCodeCompletionDeclKind(AssociatedDecl)),
224222
CodeCompletionOperatorKind::None, getCompletionMacroRoles(AssociatedDecl),
225-
getDeclIsSystem(AssociatedDecl), IsAsync, HasAsyncAlternative,
223+
getDeclIsSystem(AssociatedDecl), HasAsyncAlternative,
226224
CompletionString, ModuleName, BriefDocComment, AssociatedUSRs, ResultType,
227225
NotRecommended, DiagnosticSeverity, DiagnosticMessage,
228226
getCodeCompletionResultFilterName(CompletionString, Sink.getAllocator()),
@@ -399,9 +397,6 @@ ContextFreeCodeCompletionResult::calculateContextualNotRecommendedReason(
399397
if (explicitReason != ContextualNotRecommendedReason::None) {
400398
return explicitReason;
401399
}
402-
if (IsAsync && !canCurrDeclContextHandleAsync) {
403-
return ContextualNotRecommendedReason::InvalidAsyncContext;
404-
}
405400
if (HasAsyncAlternative && canCurrDeclContextHandleAsync) {
406401
return ContextualNotRecommendedReason::
407402
NonAsyncAlternativeUsedInAsyncContext;

lib/IDE/CodeCompletionResultBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ CodeCompletionResult *CodeCompletionResultBuilder::takeResult() {
128128
}
129129

130130
ContextFreeResult = ContextFreeCodeCompletionResult::createDeclResult(
131-
Sink, CCS, AssociatedDecl, IsAsync, HasAsyncAlternative, ModuleName,
131+
Sink, CCS, AssociatedDecl, HasAsyncAlternative, ModuleName,
132132
NullTerminatedStringRef(BriefDocComment, Allocator),
133133
copyAssociatedUSRs(Allocator, AssociatedDecl), ResultType,
134134
ContextFreeNotRecReason, ContextFreeDiagnosticSeverity,
@@ -145,7 +145,7 @@ CodeCompletionResult *CodeCompletionResultBuilder::takeResult() {
145145
case CodeCompletionResultKind::Pattern:
146146
ContextFreeResult =
147147
ContextFreeCodeCompletionResult::createPatternOrBuiltInOperatorResult(
148-
Sink, Kind, CCS, CodeCompletionOperatorKind::None, IsAsync,
148+
Sink, Kind, CCS, CodeCompletionOperatorKind::None,
149149
NullTerminatedStringRef(BriefDocComment, Allocator), ResultType,
150150
ContextFreeNotRecReason, ContextFreeDiagnosticSeverity,
151151
ContextFreeDiagnosticMessage);

lib/IDE/CodeCompletionResultBuilder.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class CodeCompletionResultBuilder {
4343
CodeCompletionFlair Flair;
4444
unsigned NumBytesToErase = 0;
4545
const Decl *AssociatedDecl = nullptr;
46-
bool IsAsync = false;
4746
bool HasAsyncAlternative = false;
4847
std::optional<CodeCompletionLiteralKind> LiteralKind;
4948
CodeCompletionKeywordKind KeywordKind = CodeCompletionKeywordKind::None;
@@ -116,7 +115,6 @@ class CodeCompletionResultBuilder {
116115

117116
void setAssociatedDecl(const Decl *D);
118117

119-
void setIsAsync(bool IsAsync) { this->IsAsync = IsAsync; }
120118
void setHasAsyncAlternative(bool HasAsyncAlternative) {
121119
this->HasAsyncAlternative = HasAsyncAlternative;
122120
}

lib/IDE/CompletionLookup.cpp

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -807,32 +807,6 @@ void CompletionLookup::analyzeActorIsolation(
807807
case ActorIsolation::NonisolatedUnsafe:
808808
return;
809809
}
810-
811-
// If the reference is 'async', all types must be 'Sendable'.
812-
if (Ctx.LangOpts.StrictConcurrencyLevel >= StrictConcurrency::Complete &&
813-
implicitlyAsync && T) {
814-
if (isa<VarDecl>(VD)) {
815-
if (!T->isSendableType()) {
816-
NotRecommended = ContextualNotRecommendedReason::CrossActorReference;
817-
}
818-
} else {
819-
assert(isa<FuncDecl>(VD) || isa<SubscriptDecl>(VD));
820-
// Check if the result and the param types are all 'Sendable'.
821-
auto *AFT = T->castTo<AnyFunctionType>();
822-
if (!AFT->getResult()->isSendableType()) {
823-
NotRecommended = ContextualNotRecommendedReason::CrossActorReference;
824-
} else {
825-
for (auto &param : AFT->getParams()) {
826-
Type paramType = param.getPlainType();
827-
if (!paramType->isSendableType()) {
828-
NotRecommended =
829-
ContextualNotRecommendedReason::CrossActorReference;
830-
break;
831-
}
832-
}
833-
}
834-
}
835-
}
836810
}
837811

838812
void CompletionLookup::addVarDeclRef(const VarDecl *VD,
@@ -864,14 +838,9 @@ void CompletionLookup::addVarDeclRef(const VarDecl *VD,
864838
}
865839
bool implicitlyAsync = false;
866840
analyzeActorIsolation(VD, VarType, implicitlyAsync, NotRecommended);
867-
bool explicitlyAsync = false;
868-
if (auto accessor = VD->getEffectfulGetAccessor()) {
869-
explicitlyAsync = accessor->hasAsync();
870-
}
871841
CodeCompletionResultBuilder Builder =
872842
makeResultBuilder(CodeCompletionResultKind::Declaration,
873843
getSemanticContext(VD, Reason, dynamicLookupInfo));
874-
Builder.setIsAsync(explicitlyAsync || implicitlyAsync);
875844
Builder.setCanCurrDeclContextHandleAsync(CanCurrDeclContextHandleAsync);
876845
Builder.setAssociatedDecl(VD);
877846
addLeadingDot(Builder);
@@ -1272,7 +1241,6 @@ void CompletionLookup::addFunctionCallPattern(
12721241
else
12731242
addTypeAnnotation(Builder, AFT->getResult(), genericSig);
12741243

1275-
Builder.setIsAsync(AFT->hasExtInfo() && AFT->isAsync());
12761244
Builder.setCanCurrDeclContextHandleAsync(CanCurrDeclContextHandleAsync);
12771245
};
12781246

@@ -1394,7 +1362,6 @@ void CompletionLookup::addMethodCall(const FuncDecl *FD,
13941362
CodeCompletionResultBuilder Builder =
13951363
makeResultBuilder(CodeCompletionResultKind::Declaration,
13961364
getSemanticContext(FD, Reason, dynamicLookupInfo));
1397-
Builder.setIsAsync(implictlyAsync || (AFT->hasExtInfo() && AFT->isAsync()));
13981365
Builder.setHasAsyncAlternative(
13991366
FD->getAsyncAlternative() &&
14001367
!FD->getAsyncAlternative()->shouldHideFromEditor());
@@ -1591,8 +1558,6 @@ void CompletionLookup::addConstructorCall(const ConstructorDecl *CD,
15911558
addTypeAnnotation(Builder, *Result, CD->getGenericSignatureOfContext());
15921559
}
15931560

1594-
Builder.setIsAsync(ConstructorType->hasExtInfo() &&
1595-
ConstructorType->isAsync());
15961561
Builder.setCanCurrDeclContextHandleAsync(CanCurrDeclContextHandleAsync);
15971562
};
15981563

@@ -1655,7 +1620,6 @@ void CompletionLookup::addSubscriptCall(const SubscriptDecl *SD,
16551620
CodeCompletionResultBuilder Builder =
16561621
makeResultBuilder(CodeCompletionResultKind::Declaration,
16571622
getSemanticContext(SD, Reason, dynamicLookupInfo));
1658-
Builder.setIsAsync(implictlyAsync);
16591623
Builder.setCanCurrDeclContextHandleAsync(CanCurrDeclContextHandleAsync);
16601624
Builder.setAssociatedDecl(SD);
16611625

0 commit comments

Comments
 (0)