@@ -1142,6 +1142,8 @@ void SILGenFunction::emitPatternBinding(PatternBindingDecl *PBD,
1142
1142
auto initialization = emitPatternBindingInitialization (PBD->getPattern (idx),
1143
1143
JumpDest::invalid ());
1144
1144
1145
+ // TODO: need to allocate the variable, stackalloc it? pass the address to the start()
1146
+
1145
1147
// If this is an async let, create a child task to compute the initializer
1146
1148
// value.
1147
1149
if (PBD->isAsyncLet ()) {
@@ -1157,11 +1159,35 @@ void SILGenFunction::emitPatternBinding(PatternBindingDecl *PBD,
1157
1159
" Could not find async let autoclosure" );
1158
1160
bool isThrowing = init->getType ()->castTo <AnyFunctionType>()->isThrowing ();
1159
1161
1162
+ // TODO: there's a builtin to make an address into a raw pointer
1163
+ // --- note dont need that; just have the builtin take it inout?
1164
+ // --- the builtin can take the address (for start())
1165
+
1166
+ // TODO: make a builtin start async let
1167
+ // Builtin.startAsyncLet -- and in the builtin create the async let record
1168
+
1169
+ // TODO: make a builtin for end async let
1170
+
1171
+ // TODO: IRGen would make a local allocation for the builtins
1172
+
1173
+ // TODO: remember if we did an await already?
1174
+
1175
+ // TODO: force in typesystem that we always await; then end aysnc let does not have to be async
1176
+ // the local let variable is actually owning the result
1177
+ // - but since throwing we can't know; maybe we didnt await on a thing yet
1178
+ // so we do need the tracking if we waited on a thing
1179
+
1180
+ // TODO: awaiting an async let should be able to take ownership
1181
+ // that means we will not await on this async let again, maybe?
1182
+ // it means that the async let destroy should not destroy the result anymore
1183
+
1160
1184
// Emit the closure for the child task.
1161
1185
SILValue childTask;
1162
1186
{
1163
1187
FullExpr Scope (Cleanups, CleanupLocation (init));
1164
1188
SILLocation loc (PBD);
1189
+ // TODO: opaque object in the async context that represents the async let
1190
+ //
1165
1191
childTask = emitRunChildTask (
1166
1192
loc,
1167
1193
init->getType (),
@@ -1173,7 +1199,7 @@ void SILGenFunction::emitPatternBinding(PatternBindingDecl *PBD,
1173
1199
enterDestroyCleanup (childTask);
1174
1200
1175
1201
// Push a cleanup that will cancel the child task at the end of the scope.
1176
- enterCancelAsyncTaskCleanup (childTask);
1202
+ enterCancelAsyncTaskCleanup (childTask); // TODO: this is "went out scope" rather than just a cancel
1177
1203
1178
1204
// Save the child task so we can await it as needed.
1179
1205
AsyncLetChildTasks[{PBD, idx}] = { childTask, isThrowing };
0 commit comments