@@ -68,6 +68,11 @@ private func tryPromoteAlloc(_ allocRef: AllocRefInstBase,
68
68
return false
69
69
}
70
70
71
+ // The most important check: does the object escape the current function?
72
+ if allocRef. isEscaping ( context) {
73
+ return false
74
+ }
75
+
71
76
if deadEndBlocks. isDeadEnd ( allocRef. parentBlock) {
72
77
73
78
// Allocations inside a code region which ends up in a no-return block may missing their
@@ -77,11 +82,8 @@ private func tryPromoteAlloc(_ allocRef: AllocRefInstBase,
77
82
// ...
78
83
// unreachable // The end of %k's lifetime
79
84
//
80
- // Also, such an allocation cannot escape the function, because the function does not
81
- // return after the point of allocation. So we can stack-promote it unconditionally.
82
- //
83
85
// There is one exception: if it's in a loop (within the dead-end region) we must not
84
- // extend its lifetime. On the other hand we can be sure that its final release is not
86
+ // extend its lifetime. In this case we can be sure that its final release is not
85
87
// missing, because otherwise the object would be leaking. For example:
86
88
//
87
89
// bb1:
@@ -93,20 +95,12 @@ private func tryPromoteAlloc(_ allocRef: AllocRefInstBase,
93
95
//
94
96
// Therefore, if the allocation is inside a loop, we can treat it like allocations in
95
97
// non dead-end regions.
96
- if !isInLoop( block: allocRef. parentBlock, context) ,
97
- // TODO: for some reason this doesn't work for aysnc functions.
98
- // Maybe a problem with co-routine splitting in LLVM?
99
- !allocRef. parentFunction. isAsync {
98
+ if !isInLoop( block: allocRef. parentBlock, context) {
100
99
allocRef. setIsStackAllocatable ( context)
101
100
return true
102
101
}
103
102
}
104
103
105
- // The most important check: does the object escape the current function?
106
- if allocRef. isEscaping ( context) {
107
- return false
108
- }
109
-
110
104
// Try to find the top most dominator block which dominates all use points.
111
105
// * This block can be located "earlier" than the actual allocation block, in case the
112
106
// promoted object is stored into an "outer" object, e.g.
0 commit comments