Skip to content

Commit 43e6030

Browse files
committed
Add sending to subscript getter sending result
1 parent 2ceb8f1 commit 43e6030

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

lib/AST/ASTPrinter.cpp

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

4453+
if (!Options.SuppressSendingArgsAndResults) {
4454+
if (auto typeRepr = decl->getElementTypeRepr()) {
4455+
if (isa<SendingTypeRepr>(decl->getResultTypeRepr()))
4456+
Printer << "sending ";
4457+
}
4458+
}
4459+
44534460
PrintWithOpaqueResultTypeKeywordRAII x(Options);
44544461
printTypeLocForImplicitlyUnwrappedOptional(
44554462
elementTy, decl->isImplicitlyUnwrappedOptional());

lib/AST/Decl.cpp

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

1075510755
newParams.push_back(param);
1075610756
}
10757+
10758+
if (isa<SendingTypeRepr>(SD->getElementTypeRepr()))
10759+
accessor->setSendingResult();
1075710760
}
1075810761
accessor->setParameters(
1075910762
ParameterList::create(ctx, paramsStart, newParams, paramsEnd));

lib/Sema/TypeCheckDecl.cpp

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

2641+
if (auto typeRepr = SD->getElementTypeRepr())
2642+
if (isa<SendingTypeRepr>(typeRepr))
2643+
infoBuilder = infoBuilder.withSendingResult();
2644+
26412645
Type funcTy;
26422646
// FIXME: Verify ExtInfo state is correct, not working by accident.
26432647
auto info = infoBuilder.build();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-swift-frontend -swift-version 6 %s -emit-silgen | %FileCheck %s
2+
3+
// REQUIRES: concurrency
4+
5+
class NonSendableKlass {}
6+
7+
// CHECK: subscript(_: sending NonSendableKlass) -> sending NonSendableKlass { get }
8+
9+
// CHECK: 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+

0 commit comments

Comments
 (0)