Skip to content

Commit f45a87c

Browse files
committed
[sending] Fix type reconstruction of sending parameters.
1 parent a031884 commit f45a87c

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

include/swift/Demangling/TypeDecoder.h

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,14 @@ class ImplFunctionParam {
183183
return {};
184184
}
185185

186+
static OptionsType getSending() {
187+
OptionsType result;
188+
189+
result |= ImplParameterInfoFlags::Sending;
190+
191+
return result;
192+
}
193+
186194
ImplFunctionParam(BuiltType type, ImplParameterConvention convention,
187195
OptionsType options)
188196
: Type(type), Convention(convention), Options(options) {}
@@ -256,6 +264,12 @@ class ImplFunctionResult {
256264
return {};
257265
}
258266

267+
static OptionsType getSending() {
268+
OptionsType result;
269+
result |= ImplResultInfoFlags::IsSending;
270+
return result;
271+
}
272+
259273
ImplFunctionResult(BuiltType type, ImplResultConvention convention,
260274
ImplResultInfoOptions options = {})
261275
: Type(type), Convention(convention), Options(options) {}
@@ -1594,8 +1608,9 @@ class TypeDecoder {
15941608
if (depth > TypeDecoder::MaxDepth)
15951609
return true;
15961610

1597-
// Children: `convention, differentiability?, type`
1598-
if (node->getNumChildren() != 2 && node->getNumChildren() != 3)
1611+
// Children: `convention, differentiability?, sending?, type`
1612+
if (node->getNumChildren() != 2 && node->getNumChildren() != 3 &&
1613+
node->getNumChildren() != 4)
15991614
return true;
16001615

16011616
auto *conventionNode = node->getChild(0);
@@ -1613,7 +1628,7 @@ class TypeDecoder {
16131628
return true;
16141629

16151630
typename T::OptionsType options;
1616-
if (node->getNumChildren() == 3) {
1631+
if (node->getNumChildren() == 3 || node->getNumChildren() == 4) {
16171632
auto diffKindNode = node->getChild(1);
16181633
if (diffKindNode->getKind() !=
16191634
Node::Kind::ImplParameterResultDifferentiability)
@@ -1625,6 +1640,13 @@ class TypeDecoder {
16251640
options |= *optDiffOptions;
16261641
}
16271642

1643+
if (node->getNumChildren() == 4) {
1644+
auto sendingKindNode = node->getChild(2);
1645+
if (sendingKindNode->getKind() != Node::Kind::ImplParameterSending)
1646+
return true;
1647+
options |= T::getSending();
1648+
}
1649+
16281650
results.emplace_back(result.getType(), *convention, options);
16291651

16301652
return false;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %target-swift-frontend -emit-ir -g -o - -module-name test -strict-concurrency=complete -swift-version 5 -enable-upcoming-feature SendingArgsAndResults -disable-availability-checking %s | %FileCheck %s
2+
3+
// Test that we can properly reconstruct sending from various tests when
4+
// emitting debug info. Only place examples in here that have already failed.
5+
6+
public struct SendableStruct: Sendable {
7+
}
8+
9+
// This verifies that we can properly type reconstruct:
10+
//
11+
// $ss6ResultOy4test14SendableStructVs5Error_pGIeggT_D
12+
//
13+
// Which is:
14+
//
15+
// @escaping @callee_guaranteed (@guaranteed sending Swift.Result<test.SendableStruct, Swift.Error>) -> ()
16+
//
17+
// CHECK: !{{[0-9]+}} = !DICompositeType(tag: DW_TAG_structure_type, name: "$ss6ResultOy4test14SendableStructVs5Error_pGIeggT_D", flags: DIFlagFwdDecl, runtimeLang: DW_LANG_Swift)
18+
func testReconstructingEscapingClosureWithSendingParam() async throws -> SendableStruct {
19+
func callSendableFunction(_ x: @Sendable () -> ()) {}
20+
21+
func helper(_ completion: @escaping (Result<SendableStruct, Swift.Error>) -> Void) {
22+
fatalError()
23+
}
24+
25+
return try await withCheckedThrowingContinuation { continuation in
26+
callSendableFunction {
27+
helper(continuation.resume(with:))
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)