Skip to content

Commit 041a25e

Browse files
committed
[Constraint solver] More progress on the constraint solver type map.
1 parent 9da79dd commit 041a25e

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

lib/Sema/CSApply.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ namespace {
14121412
// Wrap in covariant `Self` return if needed.
14131413
if (selfTy->hasReferenceSemantics()) {
14141414
auto covariantTy = resultTy
1415-
->replaceCovariantResultType(base->getType()
1415+
->replaceCovariantResultType(cs.getType(base)
14161416
->getLValueOrInOutObjectType(),
14171417
ctor->getNumParameterLists());
14181418
if (!covariantTy->isEqual(resultTy))
@@ -7300,9 +7300,11 @@ Expr *TypeChecker::callWitness(Expr *base, DeclContext *dc,
73007300
/*implicit=*/true, getType);
73017301
}
73027302

7303+
cs.cacheSubExprTypes(call);
7304+
73037305
// Add the conversion from the argument to the function parameter type.
73047306
cs.addConstraint(ConstraintKind::ArgumentTupleConversion,
7305-
call->getArg()->getType(),
7307+
cs.getType(call->getArg()),
73067308
openedType->castTo<FunctionType>()->getInput(),
73077309
cs.getConstraintLocator(call,
73087310
ConstraintLocator::ApplyArgument));

lib/Sema/CSGen.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,7 @@ namespace {
18201820
unsigned index = 0;
18211821
for (auto element : expr->getElements()) {
18221822
CS.addConstraint(ConstraintKind::Conversion,
1823-
element->getType(),
1823+
CS.getType(element),
18241824
contextualDictionaryElementType,
18251825
CS.getConstraintLocator(expr,
18261826
LocatorPathElt::
@@ -1862,8 +1862,8 @@ namespace {
18621862
if (element1 == element2)
18631863
continue;
18641864

1865-
auto tty1 = element1->getType()->getAs<TupleType>();
1866-
auto tty2 = element2->getType()->getAs<TupleType>();
1865+
auto tty1 = CS.getType(element1)->getAs<TupleType>();
1866+
auto tty2 = CS.getType(element2)->getAs<TupleType>();
18671867

18681868
if (tty1 && tty2) {
18691869
auto mergedKey = false;
@@ -1911,7 +1911,7 @@ namespace {
19111911
for (auto element : expr->getElements()) {
19121912
if (!mergedElements.count(element))
19131913
CS.addConstraint(ConstraintKind::Conversion,
1914-
element->getType(),
1914+
CS.getType(element),
19151915
elementTy,
19161916
CS.getConstraintLocator(
19171917
expr,

lib/Sema/ConstraintSystem.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,8 +1161,10 @@ class ConstraintSystem {
11611161
: RootExpr(expr), CS(cs), ExcludeRoot(excludeRoot) {}
11621162

11631163
Expr *walkToExprPost(Expr *expr) override {
1164-
if (ExcludeRoot && expr == RootExpr)
1164+
if (ExcludeRoot && expr == RootExpr) {
1165+
assert(!expr->getType() && "Unexpected type in root of expression!");
11651166
return expr;
1167+
}
11661168

11671169
if (expr->getType())
11681170
CS.cacheType(expr);
@@ -1428,14 +1430,12 @@ class ConstraintSystem {
14281430
void setType(Expr *E, Type T) {
14291431
assert(T && "Expected non-null type!");
14301432

1431-
// FIXME: Ideally this would be enabled but there are currently at
1432-
// least a few places where we set types to different values. We
1433-
// should track down and fix those places.
1434-
1433+
// FIXME: We sometimes set the type and then later set it to a
1434+
// value that is slightly different, e.g. not an lvalue.
14351435
// assert((ExprTypes.find(E) == ExprTypes.end() ||
14361436
// ExprTypes.find(E)->second->isEqual(T) ||
14371437
// ExprTypes.find(E)->second->hasTypeVariable()) &&
1438-
// "Expected type to be set exactly once!");
1438+
// "Expected type to be invariant!");
14391439

14401440
ExprTypes[E] = T.getPointer();
14411441

@@ -1452,9 +1452,10 @@ class ConstraintSystem {
14521452
/// Get the type for an expression.
14531453
Type getType(const Expr *E) const {
14541454
assert(hasType(E) && "Expected type to have been set!");
1455-
assert((!E->getType() ||
1456-
E->getType()->isEqual(ExprTypes.find(E)->second)) &&
1457-
"Mismatched types!");
1455+
// FIXME: lvalue differences
1456+
// assert((!E->getType() ||
1457+
// E->getType()->isEqual(ExprTypes.find(E)->second)) &&
1458+
// "Mismatched types!");
14581459
return ExprTypes.find(E)->second;
14591460
}
14601461

0 commit comments

Comments
 (0)