@@ -62,18 +62,28 @@ static bool isScopeAffectingInstructionDead(SILInstruction *inst,
62
62
return false ;
63
63
}
64
64
65
- // If inst has any owned move-only value as a result, deleting it may shorten
66
- // that value's lifetime which is illegal according to language rules.
67
- //
68
- // In particular, this check is needed before returning true when
69
- // getSingleValueCopyOrCast returns true. That function returns true for
70
- // move_value instructions. And `move_value %moveOnlyValue` must not be
71
- // deleted.
72
65
for (auto result : inst->getResults ()) {
66
+ // If inst has any owned move-only value as a result, deleting it may
67
+ // shorten that value's lifetime which is illegal according to language
68
+ // rules.
69
+ //
70
+ // In particular, this check is needed before returning true when
71
+ // getSingleValueCopyOrCast returns true. That function returns true for
72
+ // move_value instructions. And `move_value %moveOnlyValue` must not be
73
+ // deleted.
73
74
if (result->getType ().getASTType ()->isNoncopyable () &&
74
75
result->getOwnershipKind () == OwnershipKind::Owned) {
75
76
return false ;
76
77
}
78
+
79
+ // If result was lexical, lifetime shortening maybe observed, return.
80
+ if (result->isLexical ()) {
81
+ auto resultTy = result->getType ().getAs <SILFunctionType>();
82
+ // Allow deleted dead lexical values when they are trivial no escape types.
83
+ if (!resultTy || !resultTy->isTrivialNoEscape ()) {
84
+ return false ;
85
+ }
86
+ }
77
87
}
78
88
79
89
// If inst is a copy or beginning of scope, inst is dead, since we know that
0 commit comments