Skip to content

Commit 9e1dcd6

Browse files
committed
[RemoteMirror] Handle UnsafeContinuation
UnsafeContinuations can be stored in variables or properties, so it's important for RemoteMirror to be able to at least minimally recognize them. This just treats an UnsafeContinuation as a refcounted pointer. Which might be "good enough" for now. Working towards rdar://110351406
1 parent 541ee12 commit 9e1dcd6

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-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+
// FIXME: This is a bad approximation
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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
12+
import SwiftReflectionTest
13+
14+
struct MyValue {
15+
let u: UInt
16+
}
17+
18+
struct MyError: Error {
19+
let i: Int
20+
}
21+
22+
@available(SwiftStdlib 5.1, *)
23+
class MyClass {
24+
let cont: UnsafeContinuation<MyValue, any Error>
25+
26+
init(cont: UnsafeContinuation<MyValue, any Error>) {
27+
self.cont = cont
28+
}
29+
}
30+
31+
if #available(SwiftStdlib 5.1, *) {
32+
_ = try await withUnsafeThrowingContinuation { unsafeContinuation in
33+
let myClass = MyClass(cont: unsafeContinuation)
34+
reflect(object: myClass)
35+
unsafeContinuation.resume(returning: MyValue(u: 1))
36+
}
37+
}
38+
39+
// CHECK: Reflecting an object.
40+
// CHECK-NEXT: Instance pointer in child address space: 0x{{[0-9a-fA-F]+}}
41+
// CHECK-NEXT: Type reference:
42+
// CHECK-NEXT: (class reflect_UnsafeContinuation.MyClass)
43+
44+
// CHECK-64: Type info:
45+
// CHECK-64-NEXT: (class_instance size=24 alignment=8 stride=24 num_extra_inhabitants=0 bitwise_takable=1
46+
// CHECK-64-NEXT: (field name=cont offset=16
47+
// CHECK-64-NEXT: (struct size=8 alignment=8 stride=8 num_extra_inhabitants=2147483647 bitwise_takable=1
48+
// CHECK-64-NEXT: (field name=context offset=0
49+
// CHECK-64-NEXT: (reference kind=strong refcounting=native)))))
50+
51+
// TODO: 32-bit layout
52+
53+
doneReflecting()
54+
55+
// CHECK-64: Done.
56+
57+
// CHECK-32: Done.

0 commit comments

Comments
 (0)