@@ -470,9 +470,8 @@ namespace {
470
470
471
471
// Build a reference to the protocol requirement.
472
472
Expr *base =
473
- cs.cacheType (TypeExpr::createImplicitHack (loc.getBaseNameLoc (),
474
- baseTy,
475
- ctx));
473
+ TypeExpr::createImplicitHack (loc.getBaseNameLoc (), baseTy, ctx);
474
+ cs.cacheExprTypes (base);
476
475
477
476
return buildMemberRef (base, openedType, SourceLoc (), decl,
478
477
loc, openedFnType->getResult (),
@@ -778,6 +777,7 @@ namespace {
778
777
// If the member is a constructor, verify that it can be legally
779
778
// referenced from this base.
780
779
if (auto ctor = dyn_cast<ConstructorDecl>(member)) {
780
+ cs.setExprTypes (base);
781
781
if (!tc.diagnoseInvalidDynamicConstructorReferences (base, memberLoc,
782
782
baseMeta, ctor, SuppressDiagnostics))
783
783
return nullptr ;
@@ -1436,13 +1436,14 @@ namespace {
1436
1436
ConcreteDeclRef fnDeclRef (fn);
1437
1437
auto fnRef = new (tc.Context ) DeclRefExpr (fnDeclRef, DeclNameLoc (loc),
1438
1438
/* Implicit=*/ true );
1439
- cs. setType (fnRef, fn->getInterfaceType ());
1439
+ fnRef-> setType (fn->getInterfaceType ());
1440
1440
fnRef->setFunctionRefKind (FunctionRefKind::SingleApply);
1441
+ cs.setExprTypes (value);
1441
1442
Expr *call = CallExpr::createImplicit (tc.Context , fnRef, { value }, { });
1442
1443
if (tc.typeCheckExpressionShallow (call, dc))
1443
1444
return nullptr ;
1444
1445
1445
- cs.cacheType (call);
1446
+ cs.cacheExprTypes (call);
1446
1447
1447
1448
// The return type of _bridgeErrorToNSError is formally
1448
1449
// 'AnyObject' to avoid stdlib-to-Foundation dependencies, but it's
@@ -1477,11 +1478,18 @@ namespace {
1477
1478
tc.conformsToProtocol (valueType, bridgedProto, cs.DC ,
1478
1479
(ConformanceCheckFlags::InExpression|
1479
1480
ConformanceCheckFlags::Used))) {
1481
+ cs.setExprTypes (value);
1482
+
1480
1483
// Form the call.
1481
- return cs. cacheType (
1484
+ auto result =
1482
1485
tc.callWitness (value, cs.DC , bridgedProto, *conformance,
1483
1486
tc.Context .Id_bridgeToObjectiveC ,
1484
- { }, diag::broken_bridged_to_objc_protocol));
1487
+ { }, diag::broken_bridged_to_objc_protocol);
1488
+
1489
+ if (result)
1490
+ cs.cacheExprTypes (result);
1491
+
1492
+ return result;
1485
1493
}
1486
1494
1487
1495
// If there is an Error conformance, try bridging as an error.
@@ -1626,6 +1634,9 @@ namespace {
1626
1634
// Form the call and type-check it.
1627
1635
Expr *call = CallExpr::createImplicit (tc.Context , fnRef, args,
1628
1636
{ Identifier (), Identifier () });
1637
+ cs.cacheSubExprTypes (call);
1638
+ cs.setSubExprTypes (call);
1639
+
1629
1640
if (tc.typeCheckExpressionShallow (call, dc))
1630
1641
return nullptr ;
1631
1642
@@ -2078,6 +2089,8 @@ namespace {
2078
2089
member,
2079
2090
DeclNameLoc (expr->getStartLoc ()),
2080
2091
/* Implicit=*/ true );
2092
+ cs.cacheSubExprTypes (memberRef);
2093
+ cs.setSubExprTypes (memberRef);
2081
2094
bool failed = tc.typeCheckExpressionShallow (memberRef, cs.DC );
2082
2095
cs.cacheExprTypes (memberRef);
2083
2096
assert (!failed && " Could not reference string interpolation witness" );
@@ -2189,12 +2202,21 @@ namespace {
2189
2202
if (!isa<TupleExpr>(expr->getArg ()))
2190
2203
return nullptr ;
2191
2204
auto tupleArg = cast<TupleExpr>(expr->getArg ());
2192
- for (auto elt : tupleArg->getElements ())
2205
+ for (auto elt : tupleArg->getElements ()) {
2206
+ cs.setExprTypes (elt);
2193
2207
args.push_back (elt);
2208
+ }
2194
2209
DeclName constrName (tc.getObjectLiteralConstructorName (expr));
2210
+
2211
+ cs.cacheExprTypes (base);
2212
+ cs.setExprTypes (base);
2213
+
2195
2214
Expr *semanticExpr = tc.callWitness (base, dc, proto, *conformance,
2196
2215
constrName, args,
2197
2216
diag::object_literal_broken_proto);
2217
+ if (semanticExpr)
2218
+ cs.cacheExprTypes (semanticExpr);
2219
+
2198
2220
expr->setSemanticExpr (semanticExpr);
2199
2221
return expr;
2200
2222
}
@@ -2661,22 +2683,27 @@ namespace {
2661
2683
}
2662
2684
2663
2685
Type argType = TupleType::get (typeElements, tc.Context );
2664
- Expr *arg = cs. cacheType (
2686
+ Expr *arg =
2665
2687
TupleExpr::create (tc.Context , SourceLoc (),
2666
2688
expr->getElements (),
2667
2689
names,
2668
2690
{ },
2669
2691
SourceLoc (), /* HasTrailingClosure=*/ false ,
2670
2692
/* Implicit=*/ true ,
2671
- argType));
2693
+ argType);
2694
+
2695
+ cs.cacheExprTypes (typeRef);
2696
+ cs.setExprTypes (typeRef);
2697
+
2672
2698
Expr *result = tc.callWitness (typeRef, dc, arrayProto, *conformance,
2673
2699
name, arg, diag::array_protocol_broken);
2674
2700
if (!result)
2675
2701
return nullptr ;
2676
2702
2703
+ cs.cacheExprTypes (result);
2704
+
2677
2705
expr->setSemanticExpr (result);
2678
2706
cs.setType (expr, arrayTy);
2679
- cs.cacheSubExprTypes (expr);
2680
2707
2681
2708
// If the array element type was defaulted, note that in the expression.
2682
2709
if (solution.DefaultedConstraints .count (cs.getConstraintLocator (expr)))
@@ -2734,25 +2761,28 @@ namespace {
2734
2761
2735
2762
Type argType = TupleType::get (typeElements, tc.Context );
2736
2763
Expr *arg =
2737
- cs.cacheType (
2738
2764
TupleExpr::create (tc.Context , expr->getLBracketLoc (),
2739
2765
expr->getElements (),
2740
2766
names,
2741
2767
{ },
2742
2768
expr->getRBracketLoc (),
2743
2769
/* HasTrailingClosure=*/ false ,
2744
2770
/* Implicit=*/ false ,
2745
- argType));
2771
+ argType);
2772
+
2773
+ cs.cacheExprTypes (typeRef);
2774
+ cs.setExprTypes (typeRef);
2746
2775
2747
2776
Expr *result = tc.callWitness (typeRef, dc, dictionaryProto,
2748
2777
*conformance, name, arg,
2749
2778
diag::dictionary_protocol_broken);
2750
2779
if (!result)
2751
2780
return nullptr ;
2752
2781
2782
+ cs.cacheExprTypes (result);
2783
+
2753
2784
expr->setSemanticExpr (result);
2754
2785
cs.setType (expr, dictionaryTy);
2755
- cs.cacheSubExprTypes (expr);
2756
2786
2757
2787
// If the dictionary key or value type was defaulted, note that in the
2758
2788
// expression.
@@ -3244,8 +3274,11 @@ namespace {
3244
3274
if (*choice == 0 ) {
3245
3275
// Convert the subexpression.
3246
3276
Expr *sub = expr->getSubExpr ();
3277
+
3278
+ cs.setExprTypes (sub);
3247
3279
if (tc.convertToType (sub, toType, cs.DC ))
3248
3280
return nullptr ;
3281
+ cs.cacheExprTypes (sub);
3249
3282
3250
3283
expr->setSubExpr (sub);
3251
3284
cs.setType (expr, toType);
@@ -3528,11 +3561,11 @@ namespace {
3528
3561
bool invalid = tc.typeCheckExpression (callExpr, cs.DC ,
3529
3562
TypeLoc::withoutLoc (valueType),
3530
3563
CTP_CannotFail);
3564
+ cs.cacheExprTypes (callExpr);
3565
+
3531
3566
(void ) invalid;
3532
3567
assert (!invalid && " conversion cannot fail" );
3533
3568
3534
- cs.cacheExprTypes (callExpr);
3535
-
3536
3569
E->setSemanticExpr (callExpr);
3537
3570
return E;
3538
3571
}
@@ -4211,11 +4244,11 @@ getCallerDefaultArg(ConstraintSystem &cs, DeclContext *dc,
4211
4244
bool invalid = tc.typeCheckExpression (init, dc,
4212
4245
TypeLoc::withoutLoc (defArgType),
4213
4246
CTP_CannotFail);
4247
+ cs.cacheExprTypes (init);
4248
+
4214
4249
assert (!invalid && " conversion cannot fail" );
4215
4250
(void )invalid;
4216
4251
4217
- cs.cacheExprTypes (init);
4218
-
4219
4252
return {init, defArg.first };
4220
4253
}
4221
4254
@@ -4812,7 +4845,7 @@ Expr *ExprRewriter::coerceCallArguments(
4812
4845
// Total hack: In Swift 3 mode, argument labels are ignored when calling
4813
4846
// function type with a single Any parameter.
4814
4847
if (paramType->isAny ()) {
4815
- if (auto tupleArgType = dyn_cast<TupleType>(arg-> getType ().getPointer ())) {
4848
+ if (auto tupleArgType = dyn_cast<TupleType>(cs. getType (arg ).getPointer ())) {
4816
4849
if (tupleArgType->getNumElements () == 1 ) {
4817
4850
matchCanFail = true ;
4818
4851
}
@@ -6022,15 +6055,20 @@ Expr *ExprRewriter::convertLiteral(Expr *literal,
6022
6055
// Call the builtin conversion operation.
6023
6056
// FIXME: Bogus location info.
6024
6057
Expr *base =
6025
- cs.cacheType (TypeExpr::createImplicitHack (literal->getLoc (), type,
6026
- tc.Context ));
6058
+ TypeExpr::createImplicitHack (literal->getLoc (), type, tc.Context );
6059
+
6060
+ cs.cacheExprTypes (base);
6061
+ cs.setExprTypes (base);
6062
+ cs.setExprTypes (literal);
6063
+
6027
6064
Expr *result = tc.callWitness (base, dc,
6028
6065
builtinProtocol, *builtinConformance,
6029
6066
builtinLiteralFuncName,
6030
6067
literal,
6031
6068
brokenBuiltinProtocolDiag);
6032
6069
if (result)
6033
- cs.setType (result, type);
6070
+ cs.cacheExprTypes (result);
6071
+
6034
6072
return result;
6035
6073
}
6036
6074
@@ -6081,14 +6119,18 @@ Expr *ExprRewriter::convertLiteral(Expr *literal,
6081
6119
6082
6120
// Convert the resulting expression to the final literal type.
6083
6121
// FIXME: Bogus location info.
6084
- Expr *base =
6085
- cs.cacheType (TypeExpr::createImplicitHack (literal->getLoc (), type,
6086
- tc.Context ));
6122
+ Expr *base = TypeExpr::createImplicitHack (literal->getLoc (), type,
6123
+ tc.Context );
6124
+ cs.cacheExprTypes (base);
6125
+ cs.setExprTypes (base);
6126
+ cs.setExprTypes (literal);
6127
+
6087
6128
literal = tc.callWitness (base, dc,
6088
6129
protocol, *conformance, literalFuncName,
6089
6130
literal, brokenProtocolDiag);
6090
6131
if (literal)
6091
- cs.setType (literal, type);
6132
+ cs.cacheExprTypes (literal);
6133
+
6092
6134
return literal;
6093
6135
}
6094
6136
@@ -6321,7 +6363,7 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
6321
6363
assert (arg->getNumElements () == 2 && " should have two arguments" );
6322
6364
auto nonescaping = arg->getElements ()[0 ];
6323
6365
auto body = arg->getElements ()[1 ];
6324
- auto bodyFnTy = body-> getType ()->castTo <FunctionType>();
6366
+ auto bodyFnTy = cs. getType (body )->castTo <FunctionType>();
6325
6367
auto escapableType = bodyFnTy->getInput ();
6326
6368
auto resultType = bodyFnTy->getResult ();
6327
6369
@@ -6418,7 +6460,9 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
6418
6460
cs.setType (apply, fnType->getResult ());
6419
6461
apply->setIsSuper (isSuper);
6420
6462
6463
+ cs.setExprTypes (apply);
6421
6464
Expr *result = tc.substituteInputSugarTypeForResult (apply);
6465
+ cs.cacheExprTypes (result);
6422
6466
6423
6467
// Try closing the existential, if there is one.
6424
6468
closeExistential (result, locator);
@@ -7131,13 +7175,8 @@ Expr *TypeChecker::callWitness(Expr *base, DeclContext *dc,
7131
7175
// Construct an empty constraint system and solution.
7132
7176
ConstraintSystem cs (*this , dc, ConstraintSystemOptions ());
7133
7177
7134
- cs.cacheExprTypes (base);
7135
- for (auto *e : arguments) {
7136
- cs.cacheExprTypes (e);
7137
- }
7138
-
7139
7178
// Find the witness we need to use.
7140
- auto type = cs. getType (base );
7179
+ auto type = base-> getType ();
7141
7180
assert (!type->hasTypeVariable () &&
7142
7181
" Building call to witness with unresolved base type!" );
7143
7182
@@ -7164,7 +7203,7 @@ Expr *TypeChecker::callWitness(Expr *base, DeclContext *dc,
7164
7203
// Form a reference to the witness itself.
7165
7204
Type openedFullType, openedType;
7166
7205
std::tie (openedFullType, openedType)
7167
- = cs.getTypeOfMemberReference (cs. getType (base ), witness,
7206
+ = cs.getTypeOfMemberReference (base-> getType (), witness,
7168
7207
/* isTypeReference=*/ false ,
7169
7208
/* isDynamicResult=*/ false ,
7170
7209
FunctionRefKind::DoubleApply,
@@ -7177,7 +7216,7 @@ Expr *TypeChecker::callWitness(Expr *base, DeclContext *dc,
7177
7216
auto argLabels = witness->getFullName ().getArgumentNames ();
7178
7217
if (arguments.size () == 1 &&
7179
7218
(isVariadicWitness (witness) ||
7180
- argumentNamesMatch (cs. getType ( arguments[0 ]), argLabels))) {
7219
+ argumentNamesMatch (arguments[0 ]-> getType ( ), argLabels))) {
7181
7220
call = CallExpr::create (Context, unresolvedDot, arguments[0 ], { },
7182
7221
{ }, /* hasTrailingClosure=*/ false ,
7183
7222
/* implicit=*/ true );
@@ -7203,18 +7242,18 @@ Expr *TypeChecker::callWitness(Expr *base, DeclContext *dc,
7203
7242
/* implicit=*/ true );
7204
7243
}
7205
7244
7206
- cs.cacheExprTypes (call);
7207
-
7208
7245
// Add the conversion from the argument to the function parameter type.
7209
7246
cs.addConstraint (ConstraintKind::ArgumentTupleConversion,
7210
- cs. getType ( call->getArg ()),
7247
+ call->getArg ()-> getType ( ),
7211
7248
openedType->castTo <FunctionType>()->getInput (),
7212
7249
cs.getConstraintLocator (call,
7213
7250
ConstraintLocator::ApplyArgument));
7214
7251
7215
7252
// Solve the system.
7216
7253
SmallVector<Solution, 1 > solutions;
7217
7254
7255
+ cs.cacheExprTypes (call);
7256
+
7218
7257
// If the system failed to produce a solution, post any available diagnostics.
7219
7258
if (cs.solve (solutions) || solutions.size () != 1 ) {
7220
7259
cs.salvage (solutions, base);
@@ -7289,15 +7328,19 @@ Solution::convertBooleanTypeToBuiltinI1(Expr *expr, ConstraintLocator *locator)
7289
7328
builtinMethod,
7290
7329
DeclNameLoc (expr->getLoc ()),
7291
7330
/* Implicit=*/ true );
7331
+ cs.cacheSubExprTypes (memberRef);
7332
+ cs.setSubExprTypes (memberRef);
7292
7333
bool failed = tc.typeCheckExpressionShallow (memberRef, cs.DC );
7293
- cs.cacheType (memberRef);
7334
+ cs.cacheExprTypes (memberRef);
7294
7335
assert (!failed && " Could not reference witness?" );
7295
7336
(void )failed;
7296
7337
7297
7338
// Call the builtin method.
7298
7339
expr = CallExpr::createImplicit (ctx, memberRef, { }, { });
7340
+ cs.cacheSubExprTypes (expr);
7341
+ cs.setSubExprTypes (expr);
7299
7342
failed = tc.typeCheckExpressionShallow (expr, cs.DC );
7300
- cs.cacheType (expr);
7343
+ cs.cacheExprTypes (expr);
7301
7344
assert (!failed && " Could not call witness?" );
7302
7345
(void )failed;
7303
7346
0 commit comments