Skip to content

Commit 7bb76be

Browse files
committed
[sending] Fix type reconstruction of sending parameters.
(cherry picked from commit f45a87c)
1 parent f39041d commit 7bb76be

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
@@ -177,6 +177,14 @@ class ImplFunctionParam {
177177
return {};
178178
}
179179

180+
static OptionsType getSending() {
181+
OptionsType result;
182+
183+
result |= ImplParameterInfoFlags::Sending;
184+
185+
return result;
186+
}
187+
180188
ImplFunctionParam(BuiltType type, ImplParameterConvention convention,
181189
OptionsType options)
182190
: Type(type), Convention(convention), Options(options) {}
@@ -247,6 +255,12 @@ class ImplFunctionResult {
247255
return {};
248256
}
249257

258+
static OptionsType getSending() {
259+
OptionsType result;
260+
result |= ImplResultInfoFlags::IsSending;
261+
return result;
262+
}
263+
250264
ImplFunctionResult(BuiltType type, ImplResultConvention convention,
251265
ImplResultInfoOptions options = {})
252266
: Type(type), Convention(convention), Options(options) {}
@@ -1571,8 +1585,9 @@ class TypeDecoder {
15711585
if (depth > TypeDecoder::MaxDepth)
15721586
return true;
15731587

1574-
// Children: `convention, differentiability?, type`
1575-
if (node->getNumChildren() != 2 && node->getNumChildren() != 3)
1588+
// Children: `convention, differentiability?, sending?, type`
1589+
if (node->getNumChildren() != 2 && node->getNumChildren() != 3 &&
1590+
node->getNumChildren() != 4)
15761591
return true;
15771592

15781593
auto *conventionNode = node->getChild(0);
@@ -1590,7 +1605,7 @@ class TypeDecoder {
15901605
return true;
15911606

15921607
typename T::OptionsType options;
1593-
if (node->getNumChildren() == 3) {
1608+
if (node->getNumChildren() == 3 || node->getNumChildren() == 4) {
15941609
auto diffKindNode = node->getChild(1);
15951610
if (diffKindNode->getKind() !=
15961611
Node::Kind::ImplParameterResultDifferentiability)
@@ -1602,6 +1617,13 @@ class TypeDecoder {
16021617
options |= *optDiffOptions;
16031618
}
16041619

1620+
if (node->getNumChildren() == 4) {
1621+
auto sendingKindNode = node->getChild(2);
1622+
if (sendingKindNode->getKind() != Node::Kind::ImplParameterSending)
1623+
return true;
1624+
options |= T::getSending();
1625+
}
1626+
16051627
results.emplace_back(result.getType(), *convention, options);
16061628

16071629
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)