@@ -159,18 +159,21 @@ void *operator new(size_t bytes, ConstraintSystem& cs,
159
159
return cs.getAllocator ().Allocate (bytes, alignment);
160
160
}
161
161
162
- bool constraints::computeTupleShuffle (ArrayRef<TupleTypeElt> fromTuple,
163
- ArrayRef<TupleTypeElt> toTuple,
162
+ bool constraints::computeTupleShuffle (TupleType * fromTuple,
163
+ TupleType * toTuple,
164
164
SmallVectorImpl<unsigned > &sources) {
165
165
const unsigned unassigned = -1 ;
166
166
167
- SmallVector<bool , 4 > consumed (fromTuple.size (), false );
167
+ auto fromElts = fromTuple->getElements ();
168
+ auto toElts = toTuple->getElements ();
169
+
170
+ SmallVector<bool , 4 > consumed (fromElts.size (), false );
168
171
sources.clear ();
169
- sources.assign (toTuple .size (), unassigned);
172
+ sources.assign (toElts .size (), unassigned);
170
173
171
174
// Match up any named elements.
172
- for (unsigned i = 0 , n = toTuple .size (); i != n; ++i) {
173
- const auto &toElt = toTuple [i];
175
+ for (unsigned i = 0 , n = toElts .size (); i != n; ++i) {
176
+ const auto &toElt = toElts [i];
174
177
175
178
// Skip unnamed elements.
176
179
if (!toElt.hasName ())
@@ -180,7 +183,7 @@ bool constraints::computeTupleShuffle(ArrayRef<TupleTypeElt> fromTuple,
180
183
int matched = -1 ;
181
184
{
182
185
int index = 0 ;
183
- for (auto field : fromTuple ) {
186
+ for (auto field : fromElts ) {
184
187
if (field.getName () == toElt.getName () && !consumed[index]) {
185
188
matched = index;
186
189
break ;
@@ -197,14 +200,14 @@ bool constraints::computeTupleShuffle(ArrayRef<TupleTypeElt> fromTuple,
197
200
}
198
201
199
202
// Resolve any unmatched elements.
200
- unsigned fromNext = 0 , fromLast = fromTuple .size ();
203
+ unsigned fromNext = 0 , fromLast = fromElts .size ();
201
204
auto skipToNextAvailableInput = [&] {
202
205
while (fromNext != fromLast && consumed[fromNext])
203
206
++fromNext;
204
207
};
205
208
skipToNextAvailableInput ();
206
209
207
- for (unsigned i = 0 , n = toTuple .size (); i != n; ++i) {
210
+ for (unsigned i = 0 , n = toElts .size (); i != n; ++i) {
208
211
// Check whether we already found a value for this element.
209
212
if (sources[i] != unassigned)
210
213
continue ;
@@ -215,11 +218,11 @@ bool constraints::computeTupleShuffle(ArrayRef<TupleTypeElt> fromTuple,
215
218
}
216
219
217
220
// Otherwise, assign this input to the next output element.
218
- const auto &elt2 = toTuple [i];
221
+ const auto &elt2 = toElts [i];
219
222
220
223
// Fail if the input element is named and we're trying to match it with
221
224
// something with a different label.
222
- if (fromTuple [fromNext].hasName () && elt2.hasName ())
225
+ if (fromElts [fromNext].hasName () && elt2.hasName ())
223
226
return true ;
224
227
225
228
sources[i] = fromNext;
0 commit comments