@@ -106,25 +106,28 @@ void FormalEvaluationScope::popImpl() {
106
106
" popping formal-evaluation scopes out of order" );
107
107
context.innermostScope = previous;
108
108
109
- // Check to see if there is anything going on here.
110
-
111
- using iterator = FormalEvaluationContext::iterator;
112
- using stable_iterator = FormalEvaluationContext::stable_iterator;
109
+ auto endDepth = *savedDepth;
113
110
114
- iterator unwrappedSavedDepth = context.find (savedDepth.getValue ());
115
- iterator iter = context.begin ();
116
- if (iter == unwrappedSavedDepth)
111
+ // Check to see if there is anything going on here.
112
+ if (endDepth == context.stable_begin ())
117
113
return ;
118
114
115
+ #ifndef NDEBUG
116
+ // Verify that all the accesses are valid.
117
+ for (auto i = context.begin (), e = context.find (endDepth); i != e; ++i) {
118
+ i->verify (SGF);
119
+ }
120
+ #endif
121
+
119
122
// Save our start point to make sure that we are not adding any new cleanups
120
123
// to the front of the stack.
121
- stable_iterator originalBegin = context.stable_begin ();
122
- (void )originalBegin;
124
+ auto originalBegin = context.stable_begin ();
123
125
124
126
// Then working down the stack until we visit unwrappedSavedDepth...
125
- for (; iter != unwrappedSavedDepth; ++iter) {
126
- // Grab the next evaluation...
127
- FormalAccess &access = *iter;
127
+ auto i = originalBegin;
128
+ do {
129
+ // Grab the next evaluation.
130
+ FormalAccess &access = context.findAndAdvance (i);
128
131
129
132
// If this access was already finished, continue. This can happen if an
130
133
// owned formal access was forwarded.
@@ -149,10 +152,9 @@ void FormalEvaluationScope::popImpl() {
149
152
// code. We do a simple N^2 comparison here to detect this because it is
150
153
// extremely unlikely more than a few writebacks are active at once.
151
154
if (access.getKind () == FormalAccess::Exclusive) {
152
- iterator j = iter;
153
- ++j;
154
-
155
- for (; j != unwrappedSavedDepth; ++j) {
155
+ // Note that we already advanced 'iter' above, so we can just start
156
+ // iterating from there. Also, this doesn't invalidate the iterators.
157
+ for (auto j = context.find (i), je = context.find (endDepth); j != je; ++j){
156
158
FormalAccess &other = *j;
157
159
if (other.getKind () != FormalAccess::Exclusive)
158
160
continue ;
@@ -167,33 +169,25 @@ void FormalEvaluationScope::popImpl() {
167
169
//
168
170
// This evaluates arbitrary code, so it's best to be paranoid
169
171
// about iterators on the context.
170
- access.finish (SGF);
171
- }
172
+ DiverseValueBuffer<FormalAccess> copiedAccess (access);
173
+ copiedAccess.getCopy ().finish (SGF);
174
+
175
+ } while (i != endDepth);
172
176
173
177
// Then check that we did not add any additional cleanups to the beginning of
174
178
// the stack...
175
179
assert (originalBegin == context.stable_begin () &&
176
- " more formal eval cleanups placed onto context during formal eval scope pop ?!" );
180
+ " pushed more formal evaluations while popping formal evaluations ?!" );
177
181
178
182
// And then pop off all stack elements until we reach the savedDepth.
179
- context.pop (savedDepth. getValue () );
183
+ context.pop (endDepth );
180
184
}
181
185
182
186
void FormalEvaluationScope::verify () const {
183
- // Check to see if there is anything going on here .
187
+ // Walk up the stack to the saved depth .
184
188
auto &context = SGF.FormalEvalContext ;
185
- using iterator = FormalEvaluationContext::iterator;
186
-
187
- iterator unwrappedSavedDepth = context.find (savedDepth.getValue ());
188
- iterator iter = context.begin ();
189
- if (iter == unwrappedSavedDepth)
190
- return ;
191
-
192
- // Then working down the stack until we visit unwrappedSavedDepth...
193
- for (; iter != unwrappedSavedDepth; ++iter) {
194
- // Grab the next evaluation verify that we can successfully access this
195
- // formal access.
196
- (*iter).verify (SGF);
189
+ for (auto i = context.begin (), e = context.find (*savedDepth); i != e; ++i) {
190
+ i->verify (SGF);
197
191
}
198
192
}
199
193
0 commit comments