@@ -34,11 +34,83 @@ SerialExecutorRef swift_getMainExecutor() {
34
34
}
35
35
#endif
36
36
37
+ extern " C" SWIFT_CC(swift)
38
+ void _swift_task_checkIsolatedSwift (
39
+ HeapObject *executor,
40
+ const Metadata *executorType,
41
+ const SerialExecutorWitnessTable *witnessTable
42
+ );
43
+
37
44
extern " C" SWIFT_CC(swift)
38
45
void _swift_task_checkIsolatedSwift (HeapObject *executor,
39
46
const Metadata *executorType,
40
47
const SerialExecutorWitnessTable *witnessTable);
41
48
49
+ extern " C" SWIFT_CC(swift)
50
+ bool _swift_task_isIsolatingCurrentContextSwift (
51
+ HeapObject *executor,
52
+ const Metadata *executorType,
53
+ const SerialExecutorWitnessTable *witnessTable
54
+ );
55
+
56
+ extern " C" SWIFT_CC(swift)
57
+ bool _swift_task_isMainExecutorSwift (
58
+ HeapObject *executor,
59
+ const Metadata *executorType,
60
+ const SerialExecutorWitnessTable *witnessTable
61
+ );
62
+
63
+ extern " C" SWIFT_CC(swift)
64
+ void swift_task_checkIsolatedImpl (SerialExecutorRef executor) {
65
+ HeapObject *identity = executor.getIdentity ();
66
+
67
+ // We might be being called with an actor rather than a "proper"
68
+ // SerialExecutor; in that case, we won't have a SerialExecutor witness
69
+ // table.
70
+ if (executor.hasSerialExecutorWitnessTable ()) {
71
+ _swift_task_checkIsolatedSwift (identity,
72
+ swift_getObjectType (identity),
73
+ executor.getSerialExecutorWitnessTable ());
74
+ } else {
75
+ const Metadata *objectType = swift_getObjectType (executor.getIdentity ());
76
+ auto typeName = swift_getTypeName (objectType, true );
77
+
78
+ swift_Concurrency_fatalError (
79
+ 0 , " Incorrect actor executor assumption; expected '%.*s' executor.\n " ,
80
+ (int )typeName.length , typeName.data );
81
+ }
82
+ }
83
+
84
+ extern " C" SWIFT_CC(swift)
85
+ bool swift_task_isIsolatingCurrentContextImpl (SerialExecutorRef executor) {
86
+ HeapObject *identity = executor.getIdentity ();
87
+
88
+ // We might be being called with an actor rather than a "proper"
89
+ // SerialExecutor; in that case, we won't have a SerialExecutor witness
90
+ // table.
91
+ if (executor.hasSerialExecutorWitnessTable ()) {
92
+ return _swift_task_isIsolatingCurrentContextSwift (identity,
93
+ swift_getObjectType (identity),
94
+ executor.getSerialExecutorWitnessTable ());
95
+ } else {
96
+ const Metadata *objectType = swift_getObjectType (executor.getIdentity ());
97
+ auto typeName = swift_getTypeName (objectType, true );
98
+
99
+ swift_Concurrency_fatalError (
100
+ 0 , " Incorrect actor executor assumption; expected '%.*s' executor.\n " ,
101
+ (int )typeName.length , typeName.data );
102
+ }
103
+ }
104
+
105
+ extern " C" SWIFT_CC(swift)
106
+ bool swift_task_isMainExecutorImpl (SerialExecutorRef executor) {
107
+ HeapObject *identity = executor.getIdentity ();
108
+ return executor.hasSerialExecutorWitnessTable ()
109
+ && _swift_task_isMainExecutorSwift (identity,
110
+ swift_getObjectType (identity),
111
+ executor.getSerialExecutorWitnessTable ());
112
+ }
113
+
42
114
extern " C" SWIFT_CC(swift)
43
115
uint8_t swift_job_getPriority (Job *job) {
44
116
return (uint8_t )(job->getPriority ());
0 commit comments