File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,20 @@ bool SILLoop::canDuplicate(SILInstruction *I) const {
78
78
return false ;
79
79
}
80
80
81
+ // The entire coroutine execution must be within the loop.
82
+ // Note that we don't have to worry about the reverse --- a loop which
83
+ // contains an end_apply or abort_apply of an external begin_apply ---
84
+ // because that wouldn't be structurally valid in the first place.
85
+ if (auto BAI = dyn_cast<BeginApplyInst>(I)) {
86
+ for (auto UI : BAI->getTokenResult ()->getUses ()) {
87
+ auto User = UI->getUser ();
88
+ assert (isa<EndApplyInst>(User) || isa<AbortApplyInst>(User));
89
+ if (!contains (User))
90
+ return false ;
91
+ }
92
+ return true ;
93
+ }
94
+
81
95
if (isa<ThrowInst>(I))
82
96
return false ;
83
97
Original file line number Diff line number Diff line change @@ -1178,6 +1178,8 @@ bool SILInstruction::isTriviallyDuplicatable() const {
1178
1178
if (isa<BeginApplyInst>(this ))
1179
1179
return false ;
1180
1180
1181
+ // If you add more cases here, you should also update SILLoop:canDuplicate.
1182
+
1181
1183
return true ;
1182
1184
}
1183
1185
You can’t perform that action at this time.
0 commit comments