@@ -127,27 +127,50 @@ class LinearLifetimeError {
127
127
}
128
128
};
129
129
130
- // / Returns true if:
130
+ // / A class used to validate linear lifetime with respect to an SSA-like
131
+ // / definition.
131
132
// /
132
- // / 1. No consuming uses are reachable from any other consuming use, from any
133
- // / non-consuming uses, or from the producer instruction.
134
- // / 2. The consuming use set jointly post dominates producers and all non
135
- // / consuming uses.
133
+ // / This class is able to both validate that a linear lifetime has been properly
134
+ // / constructed (for verification and safety purposes) as well as return to the
135
+ // / caller upon failure, what the failure was. In certain cases (for instance if
136
+ // / there exists a path without a non-consuming use), the class will report back
137
+ // / the specific insertion points needed to insert these compensating releases.
136
138
// /
137
- // / \p value The value whose lifetime we are checking.
138
- // / \p consumingUses the array of users that destroy or consume a value.
139
- // / \p nonConsumingUses regular uses
140
- // / \p deadEndBlocks a cache for the dead end block computation
141
- // / \p errorBehavior If we detect an error, should we return false or hard
142
- // / error.
143
- // / \p leakingBlocks If non-null a list of blocks where the value was detected
144
- // / to leak. Can be used to insert missing destroys.
145
- LinearLifetimeError valueHasLinearLifetime (
146
- SILValue value, ArrayRef<BranchPropagatedUser> consumingUses,
147
- ArrayRef<BranchPropagatedUser> nonConsumingUses,
148
- SmallPtrSetImpl<SILBasicBlock *> &visitedBlocks,
149
- DeadEndBlocks &deadEndBlocks, ownership::ErrorBehaviorKind errorBehavior,
150
- SmallVectorImpl<SILBasicBlock *> *leakingBlocks = nullptr );
139
+ // / DISCUSSION: A linear lifetime consists of a starting block or instruction
140
+ // / and a list of non-consuming uses and a set of consuming uses. The consuming
141
+ // / uses must not be reachable from each other and jointly post-dominate all
142
+ // / consuming uses as well as the defining block/instruction.
143
+ class LinearLifetimeChecker {
144
+ SmallPtrSetImpl<SILBasicBlock *> &visitedBlocks;
145
+ DeadEndBlocks &deadEndBlocks;
146
+
147
+ public:
148
+ LinearLifetimeChecker (SmallPtrSetImpl<SILBasicBlock *> &visitedBlocks,
149
+ DeadEndBlocks &deadEndBlocks)
150
+ : visitedBlocks(visitedBlocks), deadEndBlocks(deadEndBlocks) {}
151
+
152
+ // / Returns true if:
153
+ // /
154
+ // / 1. No consuming uses are reachable from any other consuming use, from any
155
+ // / non-consuming uses, or from the producer instruction.
156
+ // / 2. The consuming use set jointly post dominates producers and all non
157
+ // / consuming uses.
158
+ // /
159
+ // / Returns false otherwise.
160
+ // /
161
+ // / \p value The value whose lifetime we are checking.
162
+ // / \p consumingUses the array of users that destroy or consume a value.
163
+ // / \p nonConsumingUses regular uses
164
+ // / \p errorBehavior If we detect an error, should we return false or hard
165
+ // / error.
166
+ // / \p leakingBlocks If non-null a list of blocks where the value was detected
167
+ // / to leak. Can be used to insert missing destroys.
168
+ LinearLifetimeError
169
+ checkValue (SILValue value, ArrayRef<BranchPropagatedUser> consumingUses,
170
+ ArrayRef<BranchPropagatedUser> nonConsumingUses,
171
+ ownership::ErrorBehaviorKind errorBehavior,
172
+ SmallVectorImpl<SILBasicBlock *> *leakingBlocks = nullptr );
173
+ };
151
174
152
175
// / Returns true if v is an address or trivial.
153
176
bool isValueAddressOrTrivial (SILValue v);
0 commit comments