Skip to content

Commit 2bb098c

Browse files
authored
Merge pull request #79560 from stzn/fix-subscript-sending-result
Add sending to subscript sending result
2 parents 76171bd + 98209cd commit 2bb098c

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4517,6 +4517,13 @@ void PrintAST::visitSubscriptDecl(SubscriptDecl *decl) {
45174517
Printer.printDeclResultTypePre(decl, elementTy);
45184518
Printer.callPrintStructurePre(PrintStructureKind::FunctionReturnType);
45194519

4520+
if (!Options.SuppressSendingArgsAndResults) {
4521+
if (auto typeRepr = decl->getElementTypeRepr()) {
4522+
if (isa<SendingTypeRepr>(decl->getResultTypeRepr()))
4523+
Printer << "sending ";
4524+
}
4525+
}
4526+
45204527
PrintWithOpaqueResultTypeKeywordRAII x(Options);
45214528
printTypeLocForImplicitlyUnwrappedOptional(
45224529
elementTy, decl->isImplicitlyUnwrappedOptional());

lib/AST/Decl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11017,6 +11017,9 @@ AccessorDecl *AccessorDecl::createParsed(
1101711017

1101811018
newParams.push_back(param);
1101911019
}
11020+
11021+
if (isa<SendingTypeRepr>(SD->getElementTypeRepr()))
11022+
accessor->setSendingResult();
1102011023
}
1102111024
accessor->setParameters(
1102211025
ParameterList::create(ctx, paramsStart, newParams, paramsEnd));

lib/Sema/TypeCheckDecl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,6 +2656,10 @@ InterfaceTypeRequest::evaluate(Evaluator &eval, ValueDecl *D) const {
26562656
AnyFunctionType::ExtInfoBuilder infoBuilder;
26572657
maybeAddParameterIsolation(infoBuilder, argTy);
26582658

2659+
if (auto typeRepr = SD->getElementTypeRepr())
2660+
if (isa<SendingTypeRepr>(typeRepr))
2661+
infoBuilder = infoBuilder.withSendingResult();
2662+
26592663
Type funcTy;
26602664
// FIXME: Verify ExtInfo state is correct, not working by accident.
26612665
auto info = infoBuilder.build();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %target-swift-frontend -swift-version 6 %s -emit-silgen | %FileCheck %s
2+
3+
// REQUIRES: concurrency
4+
5+
class NonSendableKlass {}
6+
7+
// CHECK-DAG: subscript(_: sending NonSendableKlass) -> sending NonSendableKlass { get }
8+
9+
// CHECK-DAG: sil hidden [ossa] @$s17sending_subscript1SVyAA16NonSendableKlassCAEncig : $@convention(method) (@sil_sending @owned NonSendableKlass, S) -> @sil_sending @owned NonSendableKlass {
10+
struct S {
11+
subscript(_: sending NonSendableKlass) -> sending NonSendableKlass { NonSendableKlass() }
12+
}
13+
14+
// CHECK-DAG: subscript(_: sending NonSendableKlass) -> sending (NonSendableKlass, NonSendableKlass) { get }
15+
16+
// CHECK-DAG: sil hidden [ossa] @$s17sending_subscript2S2VyAA16NonSendableKlassC_AEtAEncig : $@convention(method) (@sil_sending @owned NonSendableKlass, S2) -> (@sil_sending @owned NonSendableKlass, @sil_sending @owned NonSendableKlass) {
17+
struct S2 {
18+
subscript(_: sending NonSendableKlass) -> sending (NonSendableKlass, NonSendableKlass) {
19+
(NonSendableKlass(), NonSendableKlass())
20+
}
21+
}
22+

0 commit comments

Comments
 (0)