Skip to content

Commit e30afe9

Browse files
committed
Further updates to cache/set types in the constraint system.
1 parent 0a8678c commit e30afe9

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

lib/Sema/CSApply.cpp

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,9 +1476,10 @@ namespace {
14761476
(ConformanceCheckFlags::InExpression|
14771477
ConformanceCheckFlags::Used))) {
14781478
// Form the call.
1479-
return tc.callWitness(value, cs.DC, bridgedProto, *conformance,
1480-
tc.Context.Id_bridgeToObjectiveC,
1481-
{ }, diag::broken_bridged_to_objc_protocol);
1479+
return cs.cacheType(
1480+
tc.callWitness(value, cs.DC, bridgedProto, *conformance,
1481+
tc.Context.Id_bridgeToObjectiveC,
1482+
{ }, diag::broken_bridged_to_objc_protocol));
14821483
}
14831484

14841485
// If there is an Error conformance, try bridging as an error.
@@ -2066,8 +2067,9 @@ namespace {
20662067

20672068
// Build a reference to the init(stringInterpolation:) initializer.
20682069
// FIXME: This location info is bogus.
2069-
auto typeRef = TypeExpr::createImplicitHack(expr->getStartLoc(),
2070-
type, tc.Context);
2070+
auto *typeRef =
2071+
cs.cacheType(TypeExpr::createImplicitHack(expr->getStartLoc(),
2072+
type, tc.Context));
20712073
Expr *memberRef =
20722074
new (tc.Context) MemberRefExpr(typeRef,
20732075
expr->getStartLoc(),
@@ -2107,6 +2109,7 @@ namespace {
21072109
tc.Context, memberRef,
21082110
{ segment },
21092111
{ tc.Context.Id_stringInterpolationSegment });
2112+
cs.cacheType(apply->getArg());
21102113

21112114
auto converted = finishApply(apply, openedType, locatorBuilder);
21122115
if (!converted)
@@ -4640,15 +4643,17 @@ Expr *ExprRewriter::coerceOptionalToOptional(Expr *expr, Type toType,
46404643
}
46414644
}
46424645

4643-
expr = new (tc.Context) BindOptionalExpr(expr, expr->getSourceRange().End,
4644-
/*depth*/ 0, fromValueType);
4646+
expr =
4647+
cs.cacheType(new (tc.Context) BindOptionalExpr(expr,
4648+
expr->getSourceRange().End,
4649+
/*depth*/ 0, fromValueType));
46454650
expr->setImplicit(true);
46464651
expr = coerceToType(expr, toValueType, locator, typeFromPattern);
46474652
if (!expr) return nullptr;
46484653

4649-
expr = new (tc.Context) InjectIntoOptionalExpr(expr, toType);
4654+
expr = cs.cacheType(new (tc.Context) InjectIntoOptionalExpr(expr, toType));
46504655

4651-
expr = new (tc.Context) OptionalEvaluationExpr(expr, toType);
4656+
expr = cs.cacheType(new (tc.Context) OptionalEvaluationExpr(expr, toType));
46524657
expr->setImplicit(true);
46534658
return expr;
46544659
}
@@ -4957,12 +4962,13 @@ Expr *ExprRewriter::coerceCallArguments(
49574962
if (anyChanged || !cs.getType(argTuple)->isEqual(argTupleType)) {
49584963
auto EltNames = argTuple->getElementNames();
49594964
auto EltNameLocs = argTuple->getElementNameLocs();
4960-
argTuple = TupleExpr::create(tc.Context, argTuple->getLParenLoc(),
4961-
fromTupleExpr, EltNames, EltNameLocs,
4962-
argTuple->getRParenLoc(),
4963-
argTuple->hasTrailingClosure(),
4964-
argTuple->isImplicit(),
4965-
argTupleType);
4965+
argTuple =
4966+
cs.cacheType(TupleExpr::create(tc.Context, argTuple->getLParenLoc(),
4967+
fromTupleExpr, EltNames, EltNameLocs,
4968+
argTuple->getRParenLoc(),
4969+
argTuple->hasTrailingClosure(),
4970+
argTuple->isImplicit(),
4971+
argTupleType));
49664972
arg = argTuple;
49674973
}
49684974
}
@@ -5937,8 +5943,9 @@ Expr *ExprRewriter::convertLiteral(Expr *literal,
59375943

59385944
// Convert the resulting expression to the final literal type.
59395945
// FIXME: Bogus location info.
5940-
Expr *base = TypeExpr::createImplicitHack(literal->getLoc(), type,
5941-
tc.Context);
5946+
Expr *base =
5947+
cs.cacheType(TypeExpr::createImplicitHack(literal->getLoc(), type,
5948+
tc.Context));
59425949
literal = tc.callWitness(base, dc,
59435950
protocol, *conformance, literalFuncName,
59445951
literal, brokenProtocolDiag);
@@ -5989,8 +5996,9 @@ Expr *ExprRewriter::convertLiteralInPlace(Expr *literal,
59895996

59905997
// Form a reference to the builtin conversion function.
59915998
// FIXME: Bogus location info.
5992-
Expr *base = TypeExpr::createImplicitHack(literal->getLoc(), type,
5993-
tc.Context);
5999+
Expr *base =
6000+
cs.cacheType(TypeExpr::createImplicitHack(literal->getLoc(), type,
6001+
tc.Context));
59946002
Expr *unresolvedDot = new (tc.Context) UnresolvedDotExpr(
59956003
base, SourceLoc(),
59966004
witness->getFullName(),
@@ -6917,6 +6925,9 @@ Expr *TypeChecker::callWitness(Expr *base, DeclContext *dc,
69176925
ConstraintSystem cs(*this, dc, ConstraintSystemOptions());
69186926

69196927
cs.cacheExprTypes(base);
6928+
for (auto *e : arguments) {
6929+
cs.cacheExprTypes(e);
6930+
}
69206931

69216932
// Find the witness we need to use.
69226933
auto type = cs.getType(base);

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,11 +2694,11 @@ namespace {
26942694
CS.addConstraint(ConstraintKind::Defaultable,
26952695
placeholderTy, TupleType::getEmpty(CS.getASTContext()),
26962696
locator);
2697-
CS.setType(E, placeholderTy);
2697+
return placeholderTy;
26982698
}
26992699
// NOTE: The type loc may be there but have failed to validate, in which
27002700
// case we return the null type.
2701-
return CS.getType(E);
2701+
return E->getType();
27022702
}
27032703

27042704
Type visitObjCSelectorExpr(ObjCSelectorExpr *E) {

0 commit comments

Comments
 (0)