@@ -1142,6 +1142,8 @@ void SILGenFunction::emitPatternBinding(PatternBindingDecl *PBD,
11421142 auto initialization = emitPatternBindingInitialization (PBD->getPattern (idx),
11431143 JumpDest::invalid ());
11441144
1145+ // TODO: need to allocate the variable, stackalloc it? pass the address to the start()
1146+
11451147 // If this is an async let, create a child task to compute the initializer
11461148 // value.
11471149 if (PBD->isAsyncLet ()) {
@@ -1157,11 +1159,35 @@ void SILGenFunction::emitPatternBinding(PatternBindingDecl *PBD,
11571159 " Could not find async let autoclosure" );
11581160 bool isThrowing = init->getType ()->castTo <AnyFunctionType>()->isThrowing ();
11591161
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+
11601184 // Emit the closure for the child task.
11611185 SILValue childTask;
11621186 {
11631187 FullExpr Scope (Cleanups, CleanupLocation (init));
11641188 SILLocation loc (PBD);
1189+ // TODO: opaque object in the async context that represents the async let
1190+ //
11651191 childTask = emitRunChildTask (
11661192 loc,
11671193 init->getType (),
@@ -1173,7 +1199,7 @@ void SILGenFunction::emitPatternBinding(PatternBindingDecl *PBD,
11731199 enterDestroyCleanup (childTask);
11741200
11751201 // 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
11771203
11781204 // Save the child task so we can await it as needed.
11791205 AsyncLetChildTasks[{PBD, idx}] = { childTask, isThrowing };
0 commit comments