@@ -5104,46 +5104,18 @@ Expr *ExprRewriter::coerceTupleToTuple(Expr *expr, TupleType *fromTuple,
5104
5104
auto *fromTupleExpr = dyn_cast<TupleExpr>(innerExpr);
5105
5105
5106
5106
// / Check each of the tuple elements in the destination.
5107
- bool hasVariadic = false ;
5108
- unsigned variadicParamIdx = toTuple->getNumElements ();
5109
5107
bool anythingShuffled = false ;
5110
- bool hasInits = false ;
5111
5108
SmallVector<TupleTypeElt, 4 > toSugarFields;
5112
5109
SmallVector<TupleTypeElt, 4 > fromTupleExprFields (
5113
5110
fromTuple->getElements ().size ());
5114
- SmallVector<Expr *, 2 > callerDefaultArgs;
5115
- ConcreteDeclRef callee =
5116
- findCalleeDeclRef (cs, solution, cs.getConstraintLocator (locator));
5117
5111
5118
5112
for (unsigned i = 0 , n = toTuple->getNumElements (); i != n; ++i) {
5113
+ assert (sources[i] != TupleShuffleExpr::DefaultInitialize &&
5114
+ sources[i] != TupleShuffleExpr::Variadic);
5115
+
5119
5116
const auto &toElt = toTuple->getElement (i);
5120
5117
auto toEltType = toElt.getType ();
5121
5118
5122
- // If we're default-initializing this member, there's nothing to do.
5123
- if (sources[i] == TupleShuffleExpr::DefaultInitialize) {
5124
- anythingShuffled = true ;
5125
- hasInits = true ;
5126
- toSugarFields.push_back (toElt);
5127
-
5128
- // Create a caller-side default argument, if we need one.
5129
- if (auto defArg = getCallerDefaultArg (cs, dc, expr->getLoc (),
5130
- callee, i).first ) {
5131
- callerDefaultArgs.push_back (defArg);
5132
- sources[i] = TupleShuffleExpr::CallerDefaultInitialize;
5133
- }
5134
- continue ;
5135
- }
5136
-
5137
- // If this is the variadic argument, note it.
5138
- if (sources[i] == TupleShuffleExpr::Variadic) {
5139
- assert (!hasVariadic && " two variadic parameters?" );
5140
- toSugarFields.push_back (toElt);
5141
- hasVariadic = true ;
5142
- variadicParamIdx = i;
5143
- anythingShuffled = true ;
5144
- continue ;
5145
- }
5146
-
5147
5119
// If the source and destination index are different, we'll be shuffling.
5148
5120
if ((unsigned )sources[i] != i) {
5149
5121
anythingShuffled = true ;
@@ -5200,51 +5172,6 @@ Expr *ExprRewriter::coerceTupleToTuple(Expr *expr, TupleType *fromTuple,
5200
5172
fromElt.getWithType (cs.getType (convertedElt));
5201
5173
}
5202
5174
5203
- // Convert all of the variadic arguments to the destination type.
5204
- ArraySliceType *arrayType = nullptr ;
5205
- if (hasVariadic) {
5206
- Type toEltType = toTuple->getElements ()[variadicParamIdx].getVarargBaseTy ();
5207
- for (int fromFieldIdx : variadicArgs) {
5208
- const auto &fromElt = fromTuple->getElement (fromFieldIdx);
5209
- Type fromEltType = fromElt.getType ();
5210
-
5211
- // If the source and destination types match, there's nothing to do.
5212
- if (toEltType->isEqual (fromEltType)) {
5213
- fromTupleExprFields[fromFieldIdx] = fromElt;
5214
- continue ;
5215
- }
5216
-
5217
- // We need to convert the source element to the destination type.
5218
- if (!fromTupleExpr) {
5219
- // FIXME: Lame! We can't express this in the AST.
5220
- tc.diagnose (expr->getLoc (),
5221
- diag::tuple_conversion_not_expressible,
5222
- fromTuple, toTuple);
5223
- return nullptr ;
5224
- }
5225
-
5226
- // Actually convert the source element.
5227
- auto convertedElt = coerceToType (
5228
- fromTupleExpr->getElement (fromFieldIdx),
5229
- toEltType,
5230
- locator.withPathElement (
5231
- LocatorPathElt::getTupleElement (fromFieldIdx)));
5232
- if (!convertedElt)
5233
- return nullptr ;
5234
-
5235
- fromTupleExpr->setElement (fromFieldIdx, convertedElt);
5236
-
5237
- fromTupleExprFields[fromFieldIdx] =
5238
- fromElt.getWithType (cs.getType (convertedElt));
5239
- }
5240
-
5241
- // Find the appropriate injection function.
5242
- if (tc.requireArrayLiteralIntrinsics (expr->getStartLoc ()))
5243
- return nullptr ;
5244
- arrayType = cast<ArraySliceType>(
5245
- toTuple->getElements ()[variadicParamIdx].getType ().getPointer ());
5246
- }
5247
-
5248
5175
// Compute the updated 'from' tuple type, since we may have
5249
5176
// performed some conversions in place.
5250
5177
Type fromTupleType = TupleType::get (fromTupleExprFields, tc.Context );
@@ -5256,8 +5183,7 @@ Expr *ExprRewriter::coerceTupleToTuple(Expr *expr, TupleType *fromTuple,
5256
5183
}
5257
5184
5258
5185
// Compute the re-sugared tuple type.
5259
- Type toSugarType = hasInits? toTuple
5260
- : TupleType::get (toSugarFields, tc.Context );
5186
+ Type toSugarType = TupleType::get (toSugarFields, tc.Context );
5261
5187
5262
5188
// If we don't have to shuffle anything, we're done.
5263
5189
if (!anythingShuffled && fromTupleExpr) {
@@ -5272,13 +5198,10 @@ Expr *ExprRewriter::coerceTupleToTuple(Expr *expr, TupleType *fromTuple,
5272
5198
// Create the tuple shuffle.
5273
5199
return
5274
5200
cs.cacheType (TupleShuffleExpr::create (tc.Context ,
5275
- expr, sources,
5276
- TupleShuffleExpr::TupleToTuple,
5277
- callee,
5278
- variadicArgs,
5279
- arrayType,
5280
- callerDefaultArgs,
5281
- toSugarType));
5201
+ expr, sources,
5202
+ TupleShuffleExpr::TupleToTuple,
5203
+ ConcreteDeclRef (), {}, Type (), {},
5204
+ toSugarType));
5282
5205
}
5283
5206
5284
5207
static Type getMetatypeSuperclass (Type t, TypeChecker &tc) {
0 commit comments