Skip to content

Commit 9debfbc

Browse files
authored
Merge pull request #75607 from tbkka/tbkka-remotemirror-unsafecontinuation
[RemoteMirror] Handle UnsafeContinuation
2 parents 713aafe + 4bad739 commit 9debfbc

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

include/swift/RemoteInspection/TypeLowering.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ class TypeConverter {
428428
const TypeInfo *getThickFunctionTypeInfo();
429429
const TypeInfo *getAnyMetatypeTypeInfo();
430430
const TypeInfo *getDefaultActorStorageTypeInfo();
431+
const TypeInfo *getRawUnsafeContinuationTypeInfo();
431432
const TypeInfo *getEmptyTypeInfo();
432433

433434
template <typename TypeInfoTy, typename... Args>

stdlib/public/RemoteInspection/TypeLowering.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,6 +1602,12 @@ const TypeInfo *TypeConverter::getDefaultActorStorageTypeInfo() {
16021602
return DefaultActorStorageTI;
16031603
}
16041604

1605+
const TypeInfo *TypeConverter::getRawUnsafeContinuationTypeInfo() {
1606+
// An UnsafeContinuation is (essentially) a strong pointer to heap data
1607+
return getReferenceTypeInfo(ReferenceKind::Strong,
1608+
ReferenceCounting::Native);
1609+
}
1610+
16051611
const TypeInfo *TypeConverter::getEmptyTypeInfo() {
16061612
if (EmptyTI != nullptr)
16071613
return EmptyTI;
@@ -2208,6 +2214,8 @@ class LowerType
22082214
ReferenceCounting::Unknown);
22092215
} else if (B->getMangledName() == "BD") {
22102216
return TC.getDefaultActorStorageTypeInfo();
2217+
} else if (B->getMangledName() == "Bc") {
2218+
return TC.getRawUnsafeContinuationTypeInfo();
22112219
}
22122220

22132221
/// Otherwise, get the fixed layout information from reflection
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift -lswiftSwiftReflectionTest %s -o %t/reflect_UnsafeContinuation
3+
// RUN: %target-codesign %t/reflect_UnsafeContinuation
4+
5+
// RUN: %target-run %target-swift-reflection-test %t/reflect_UnsafeContinuation | %FileCheck %s --check-prefix=CHECK-%target-ptrsize
6+
7+
// REQUIRES: reflection_test_support
8+
// REQUIRES: executable_test
9+
// UNSUPPORTED: use_os_stdlib
10+
// UNSUPPORTED: ASAN
11+
// UNSUPPORTED: back_deployment_runtime
12+
13+
import SwiftReflectionTest
14+
15+
struct MyValue {
16+
let u: UInt
17+
}
18+
19+
struct MyError: Error {
20+
let i: Int
21+
}
22+
23+
@available(SwiftStdlib 5.1, *)
24+
class MyClass {
25+
let cont: UnsafeContinuation<MyValue, any Error>
26+
27+
init(cont: UnsafeContinuation<MyValue, any Error>) {
28+
self.cont = cont
29+
}
30+
}
31+
32+
if #available(SwiftStdlib 5.1, *) {
33+
_ = try await withUnsafeThrowingContinuation { unsafeContinuation in
34+
let myClass = MyClass(cont: unsafeContinuation)
35+
reflect(object: myClass)
36+
unsafeContinuation.resume(returning: MyValue(u: 1))
37+
}
38+
}
39+
40+
// CHECK: Reflecting an object.
41+
// CHECK-NEXT: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}
42+
// CHECK-NEXT: Type reference:
43+
// CHECK-NEXT: (class reflect_UnsafeContinuation.MyClass)
44+
45+
// CHECK-64: Type info:
46+
// CHECK-64-NEXT: (class_instance size=24 alignment=8 stride=24 num_extra_inhabitants=0 bitwise_takable=1
47+
// CHECK-64-NEXT: (field name=cont offset=16
48+
// CHECK-64-NEXT: (struct size=8 alignment=8 stride=8 num_extra_inhabitants=2147483647 bitwise_takable=1
49+
// CHECK-64-NEXT: (field name=context offset=0
50+
// CHECK-64-NEXT: (reference kind=strong refcounting=native)))))
51+
52+
// TODO: 32-bit layout
53+
54+
doneReflecting()
55+
56+
// CHECK-64: Done.
57+
58+
// CHECK-32: Done.

0 commit comments

Comments
 (0)