Skip to content

Commit c8e1715

Browse files
committed
[Sema] Remove unneeded uses of TVO_CanBindToInOut
1 parent 99ccfb1 commit c8e1715

File tree

6 files changed

+59
-104
lines changed

6 files changed

+59
-104
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4802,7 +4802,6 @@ namespace {
48024802

48034803
auto tv = cs.createTypeVariable(inputLocator,
48044804
TVO_CanBindToLValue |
4805-
TVO_CanBindToInOut |
48064805
TVO_PrefersSubtypeBinding);
48074806

48084807
// In order to make this work, we pick the most general function type and
@@ -5254,10 +5253,9 @@ bool FailureDiagnosis::diagnoseTrailingClosureErrors(ApplyExpr *callExpr) {
52545253
cs.addConstraint(ConstraintKind::Conversion, fnType->getResult(),
52555254
expectedResultType, locator);
52565255
} else if (auto *typeVar = resultType->getAs<TypeVariableType>()) {
5257-
auto tv =
5258-
cs.createTypeVariable(cs.getConstraintLocator(expr),
5259-
TVO_CanBindToLValue | TVO_CanBindToInOut |
5260-
TVO_PrefersSubtypeBinding);
5256+
auto tv = cs.createTypeVariable(cs.getConstraintLocator(expr),
5257+
TVO_CanBindToLValue |
5258+
TVO_PrefersSubtypeBinding);
52615259

52625260
auto extInfo = FunctionType::ExtInfo().withThrows();
52635261
auto fTy = FunctionType::get(ParenType::get(cs.getASTContext(), tv),
@@ -7073,7 +7071,7 @@ bool FailureDiagnosis::visitKeyPathExpr(KeyPathExpr *KPE) {
70737071

70747072
bool builtConstraints(ConstraintSystem &cs, Expr *expr) override {
70757073
auto *locator = cs.getConstraintLocator(expr);
7076-
auto valueType = cs.createTypeVariable(locator, TVO_CanBindToInOut);
7074+
auto valueType = cs.createTypeVariable(locator, /*options*/0);
70777075

70787076
auto keyPathType =
70797077
BoundGenericClassType::get(Decl, ParentType, {RootType, valueType});

lib/Sema/CSGen.cpp

Lines changed: 36 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -985,8 +985,7 @@ namespace {
985985
auto baseTy = CS.getType(base);
986986
auto tv = CS.createTypeVariable(
987987
CS.getConstraintLocator(expr, ConstraintLocator::Member),
988-
TVO_CanBindToLValue |
989-
TVO_CanBindToInOut);
988+
TVO_CanBindToLValue);
990989
CS.addValueMemberConstraint(baseTy, name, tv, CurDC, functionRefKind,
991990
CS.getConstraintLocator(expr, ConstraintLocator::Member));
992991
return tv;
@@ -1006,9 +1005,7 @@ namespace {
10061005

10071006
auto memberLocator =
10081007
CS.getConstraintLocator(expr, ConstraintLocator::Member);
1009-
auto tv = CS.createTypeVariable(memberLocator,
1010-
TVO_CanBindToLValue |
1011-
TVO_CanBindToInOut);
1008+
auto tv = CS.createTypeVariable(memberLocator, TVO_CanBindToLValue);
10121009

10131010
OverloadChoice choice =
10141011
OverloadChoice(CS.getType(base), decl, functionRefKind);
@@ -1036,7 +1033,7 @@ namespace {
10361033
// I -> inout? O, where I and O are fresh type variables. The index
10371034
// expression must be convertible to I and the subscript expression
10381035
// itself has type inout? O, where O may or may not be an lvalue.
1039-
auto inputTv = CS.createTypeVariable(indexLocator, TVO_CanBindToInOut);
1036+
auto inputTv = CS.createTypeVariable(indexLocator, /*options*/0);
10401037

10411038
// For an integer subscript expression on an array slice type, instead of
10421039
// introducing a new type variable we can easily obtain the element type.
@@ -1083,9 +1080,7 @@ namespace {
10831080
}
10841081

10851082
if (outputTy.isNull()) {
1086-
outputTy = CS.createTypeVariable(resultLocator,
1087-
TVO_CanBindToLValue |
1088-
TVO_CanBindToInOut);
1083+
outputTy = CS.createTypeVariable(resultLocator, TVO_CanBindToLValue);
10891084
} else {
10901085
// TODO: Generalize this for non-subscript-expr anchors, so that e.g.
10911086
// keypath lookup benefits from the peephole as well.
@@ -1174,8 +1169,7 @@ namespace {
11741169

11751170

11761171
auto tv = CS.createTypeVariable(CS.getConstraintLocator(expr),
1177-
TVO_PrefersSubtypeBinding |
1178-
TVO_CanBindToInOut);
1172+
TVO_PrefersSubtypeBinding);
11791173
CS.addConstraint(ConstraintKind::LiteralConformsTo, tv,
11801174
protocol->getDeclaredType(),
11811175
CS.getConstraintLocator(expr));
@@ -1197,9 +1191,7 @@ namespace {
11971191
// The type of the expression must conform to the
11981192
// ExpressibleByStringInterpolation protocol.
11991193
auto locator = CS.getConstraintLocator(expr);
1200-
auto tv = CS.createTypeVariable(locator,
1201-
TVO_PrefersSubtypeBinding |
1202-
TVO_CanBindToInOut);
1194+
auto tv = CS.createTypeVariable(locator, TVO_PrefersSubtypeBinding);
12031195
CS.addConstraint(ConstraintKind::LiteralConformsTo, tv,
12041196
interpolationProto->getDeclaredType(),
12051197
locator);
@@ -1244,8 +1236,7 @@ namespace {
12441236
}
12451237

12461238
auto tv = CS.createTypeVariable(CS.getConstraintLocator(expr),
1247-
TVO_PrefersSubtypeBinding |
1248-
TVO_CanBindToInOut);
1239+
TVO_PrefersSubtypeBinding);
12491240

12501241
CS.addConstraint(ConstraintKind::LiteralConformsTo, tv,
12511242
protocol->getDeclaredType(),
@@ -1288,8 +1279,7 @@ namespace {
12881279
if (VD->hasInterfaceType() &&
12891280
VD->getInterfaceType()->is<UnresolvedType>()) {
12901281
return CS.createTypeVariable(CS.getConstraintLocator(E),
1291-
TVO_CanBindToLValue |
1292-
TVO_CanBindToInOut);
1282+
TVO_CanBindToLValue);
12931283
}
12941284
}
12951285

@@ -1375,9 +1365,7 @@ namespace {
13751365
// that will be equal to different types depending on which overload
13761366
// is selected.
13771367
auto locator = CS.getConstraintLocator(expr);
1378-
auto tv = CS.createTypeVariable(locator,
1379-
TVO_CanBindToLValue |
1380-
TVO_CanBindToInOut);
1368+
auto tv = CS.createTypeVariable(locator, TVO_CanBindToLValue);
13811369
ArrayRef<ValueDecl*> decls = expr->getDecls();
13821370
SmallVector<OverloadChoice, 4> choices;
13831371

@@ -1408,8 +1396,7 @@ namespace {
14081396
// to help us determine which declaration the user meant to refer to.
14091397
// FIXME: Do we need to note that we're doing some kind of recovery?
14101398
return CS.createTypeVariable(CS.getConstraintLocator(expr),
1411-
TVO_CanBindToLValue |
1412-
TVO_CanBindToInOut);
1399+
TVO_CanBindToLValue);
14131400
}
14141401

14151402
Type visitMemberRefExpr(MemberRefExpr *expr) {
@@ -1434,10 +1421,8 @@ namespace {
14341421

14351422
auto memberLocator
14361423
= CS.getConstraintLocator(expr, ConstraintLocator::UnresolvedMember);
1437-
auto baseTy = CS.createTypeVariable(baseLocator, TVO_CanBindToInOut);
1438-
auto memberTy = CS.createTypeVariable(memberLocator,
1439-
TVO_CanBindToLValue |
1440-
TVO_CanBindToInOut);
1424+
auto baseTy = CS.createTypeVariable(baseLocator, /*options*/0);
1425+
auto memberTy = CS.createTypeVariable(memberLocator, TVO_CanBindToLValue);
14411426

14421427
// An unresolved member expression '.member' is modeled as a value member
14431428
// constraint
@@ -1458,7 +1443,7 @@ namespace {
14581443
// need to include everything else in the world?
14591444
auto outputTy = CS.createTypeVariable(
14601445
CS.getConstraintLocator(expr, ConstraintLocator::FunctionResult),
1461-
TVO_CanBindToInOut);
1446+
/*options*/0);
14621447
CS.addConstraint(ConstraintKind::Conversion, outputTy, baseTy,
14631448
CS.getConstraintLocator(expr, ConstraintLocator::RvalueAdjustment));
14641449

@@ -1477,9 +1462,7 @@ namespace {
14771462

14781463
// The member type also needs to be convertible to the context type, which
14791464
// preserves lvalue-ness.
1480-
auto resultTy = CS.createTypeVariable(memberLocator,
1481-
TVO_CanBindToLValue |
1482-
TVO_CanBindToInOut);
1465+
auto resultTy = CS.createTypeVariable(memberLocator, TVO_CanBindToLValue);
14831466
CS.addConstraint(ConstraintKind::Conversion, memberTy, resultTy,
14841467
memberLocator);
14851468
CS.addConstraint(ConstraintKind::Equal, resultTy, baseTy,
@@ -1513,10 +1496,9 @@ namespace {
15131496
auto argsTy = CS.createTypeVariable(
15141497
CS.getConstraintLocator(expr),
15151498
TVO_CanBindToLValue |
1516-
TVO_PrefersSubtypeBinding |
1517-
TVO_CanBindToInOut);
1499+
TVO_PrefersSubtypeBinding);
15181500
auto resultTy = CS.createTypeVariable(CS.getConstraintLocator(expr),
1519-
TVO_CanBindToInOut);
1501+
/*options*/0);
15201502
auto methodTy = FunctionType::get(argsTy, resultTy);
15211503
CS.addValueMemberConstraint(baseTy, expr->getName(),
15221504
methodTy, CurDC, expr->getFunctionRefKind(),
@@ -1620,8 +1602,7 @@ namespace {
16201602

16211603
Type visitOptionalTryExpr(OptionalTryExpr *expr) {
16221604
auto valueTy = CS.createTypeVariable(CS.getConstraintLocator(expr),
1623-
TVO_PrefersSubtypeBinding |
1624-
TVO_CanBindToInOut);
1605+
TVO_PrefersSubtypeBinding);
16251606

16261607
Type optTy = getOptionalType(expr->getSubExpr()->getLoc(), valueTy);
16271608
if (!optTy)
@@ -1722,9 +1703,7 @@ namespace {
17221703
return contextualArrayType;
17231704
}
17241705

1725-
auto arrayTy = CS.createTypeVariable(locator,
1726-
TVO_PrefersSubtypeBinding |
1727-
TVO_CanBindToInOut);
1706+
auto arrayTy = CS.createTypeVariable(locator, TVO_PrefersSubtypeBinding);
17281707

17291708
// The array must be an array literal type.
17301709
CS.addConstraint(ConstraintKind::LiteralConformsTo, arrayTy,
@@ -1820,8 +1799,7 @@ namespace {
18201799
}
18211800

18221801
auto dictionaryTy = CS.createTypeVariable(locator,
1823-
TVO_PrefersSubtypeBinding |
1824-
TVO_CanBindToInOut);
1802+
TVO_PrefersSubtypeBinding);
18251803

18261804
// The dictionary must be a dictionary literal type.
18271805
CS.addConstraint(ConstraintKind::LiteralConformsTo, dictionaryTy,
@@ -1997,7 +1975,7 @@ namespace {
19971975
}
19981976

19991977
return CS.createTypeVariable(CS.getConstraintLocator(locator),
2000-
TVO_CanBindToInOut);
1978+
/*options*/0);
20011979
}
20021980

20031981
case PatternKind::Named: {
@@ -2314,7 +2292,7 @@ namespace {
23142292

23152293
// If no return type was specified, create a fresh type
23162294
// variable for it.
2317-
funcTy = CS.createTypeVariable(locator, TVO_CanBindToInOut);
2295+
funcTy = CS.createTypeVariable(locator, /*options*/0);
23182296

23192297
// Allow it to default to () if there are no return statements.
23202298
if (closureHasNoResult(expr)) {
@@ -2363,7 +2341,7 @@ namespace {
23632341

23642342
Type visitDynamicTypeExpr(DynamicTypeExpr *expr) {
23652343
auto tv = CS.createTypeVariable(CS.getConstraintLocator(expr),
2366-
TVO_CanBindToInOut);
2344+
/*options*/0);
23672345
CS.addConstraint(ConstraintKind::DynamicTypeOf, tv,
23682346
CS.getType(expr->getBase()),
23692347
CS.getConstraintLocator(expr, ConstraintLocator::RvalueAdjustment));
@@ -2441,7 +2419,7 @@ namespace {
24412419
if (outputTy.isNull()) {
24422420
outputTy = CS.createTypeVariable(
24432421
CS.getConstraintLocator(expr, ConstraintLocator::FunctionResult),
2444-
TVO_CanBindToInOut);
2422+
/*options*/0);
24452423
} else {
24462424
// Since we know what the output type is, we can set it as the favored
24472425
// type of this expression.
@@ -2694,9 +2672,7 @@ namespace {
26942672
// just plop an open type variable here.
26952673

26962674
auto locator = CS.getConstraintLocator(expr);
2697-
auto typeVar = CS.createTypeVariable(locator,
2698-
TVO_CanBindToLValue |
2699-
TVO_CanBindToInOut);
2675+
auto typeVar = CS.createTypeVariable(locator, TVO_CanBindToLValue);
27002676
return typeVar;
27012677
}
27022678

@@ -2719,8 +2695,7 @@ namespace {
27192695

27202696
auto objectTy = CS.createTypeVariable(locator,
27212697
TVO_PrefersSubtypeBinding |
2722-
TVO_CanBindToLValue |
2723-
TVO_CanBindToInOut);
2698+
TVO_CanBindToLValue);
27242699

27252700
// The result is the object type of the optional subexpression.
27262701
CS.addConstraint(ConstraintKind::OptionalObject,
@@ -2735,8 +2710,7 @@ namespace {
27352710
// optional types, e.g. T? over T??; otherwise we don't really
27362711
// have a preference.
27372712
auto valueTy = CS.createTypeVariable(CS.getConstraintLocator(expr),
2738-
TVO_PrefersSubtypeBinding |
2739-
TVO_CanBindToInOut);
2713+
TVO_PrefersSubtypeBinding);
27402714

27412715
Type optTy = getOptionalType(expr->getSubExpr()->getLoc(), valueTy);
27422716
if (!optTy)
@@ -2754,8 +2728,7 @@ namespace {
27542728

27552729
auto objectTy = CS.createTypeVariable(locator,
27562730
TVO_PrefersSubtypeBinding |
2757-
TVO_CanBindToLValue |
2758-
TVO_CanBindToInOut);
2731+
TVO_CanBindToLValue);
27592732

27602733
// The result is the object type of the optional subexpression.
27612734
CS.addConstraint(ConstraintKind::OptionalObject,
@@ -2796,7 +2769,7 @@ namespace {
27962769
auto &placeholderTy
27972770
= editorPlaceholderVariables[currentEditorPlaceholderVariable];
27982771
if (!placeholderTy) {
2799-
placeholderTy = CS.createTypeVariable(locator, TVO_CanBindToInOut);
2772+
placeholderTy = CS.createTypeVariable(locator, /*options*/0);
28002773

28012774
CS.addConstraint(ConstraintKind::Defaultable,
28022775
placeholderTy,
@@ -2852,7 +2825,7 @@ namespace {
28522825
// For native key paths, traverse the key path components to set up
28532826
// appropriate type relationships at each level.
28542827
auto locator = CS.getConstraintLocator(E);
2855-
Type root = CS.createTypeVariable(locator, TVO_CanBindToInOut);
2828+
Type root = CS.createTypeVariable(locator, /*options*/0);
28562829

28572830
// If a root type was explicitly given, then resolve it now.
28582831
if (auto rootRepr = E->getRootType()) {
@@ -2878,9 +2851,7 @@ namespace {
28782851
// This should only appear in resolved ASTs, but we may need to
28792852
// re-type-check the constraints during failure diagnosis.
28802853
case KeyPathExpr::Component::Kind::Property: {
2881-
auto memberTy = CS.createTypeVariable(locator,
2882-
TVO_CanBindToLValue |
2883-
TVO_CanBindToInOut);
2854+
auto memberTy = CS.createTypeVariable(locator, TVO_CanBindToLValue);
28842855
auto lookupName = kind == KeyPathExpr::Component::Kind::UnresolvedProperty
28852856
? component.getUnresolvedDeclName()
28862857
: component.getDeclRef().getDecl()->getFullName();
@@ -2924,8 +2895,7 @@ namespace {
29242895
}
29252896
case KeyPathExpr::Component::Kind::OptionalForce: {
29262897
auto optionalObjTy = CS.createTypeVariable(locator,
2927-
TVO_CanBindToLValue |
2928-
TVO_CanBindToInOut);
2898+
TVO_CanBindToLValue);
29292899

29302900
CS.addConstraint(ConstraintKind::OptionalObject, base, optionalObjTy,
29312901
locator);
@@ -2946,14 +2916,14 @@ namespace {
29462916
// If there was an optional chaining component, the end result must be
29472917
// optional.
29482918
if (didOptionalChain) {
2949-
auto objTy = CS.createTypeVariable(locator, TVO_CanBindToInOut);
2919+
auto objTy = CS.createTypeVariable(locator, /*options*/0);
29502920
auto optTy = OptionalType::get(objTy);
29512921
CS.addConstraint(ConstraintKind::Conversion, base, optTy,
29522922
locator);
29532923
base = optTy;
29542924
}
29552925

2956-
auto rvalueBase = CS.createTypeVariable(locator, TVO_CanBindToInOut);
2926+
auto rvalueBase = CS.createTypeVariable(locator, /*options*/0);
29572927
CS.addConstraint(ConstraintKind::Equal, base, rvalueBase, locator);
29582928

29592929
// The result is a KeyPath from the root to the end component.
@@ -2965,7 +2935,7 @@ namespace {
29652935
// The type of key path depends on the overloads chosen for the key
29662936
// path components.
29672937
kpTy = CS.createTypeVariable(CS.getConstraintLocator(E),
2968-
TVO_CanBindToInOut);
2938+
/*options*/0);
29692939
CS.addKeyPathConstraint(kpTy, root, rvalueBase,
29702940
CS.getConstraintLocator(E));
29712941
}
@@ -3433,8 +3403,7 @@ class InferUnresolvedMemberConstraintGenerator : public ConstraintGenerator {
34333403
TypeVariableType *createFreeTypeVariableType(Expr *E) {
34343404
auto &CS = getConstraintSystem();
34353405
return CS.createTypeVariable(CS.getConstraintLocator(nullptr),
3436-
TVO_CanBindToLValue |
3437-
TVO_CanBindToInOut);
3406+
TVO_CanBindToLValue);
34383407
}
34393408

34403409
public:
@@ -3664,9 +3633,7 @@ swift::resolveValueMember(DeclContext &DC, Type BaseTy, DeclName Name) {
36643633

36653634
// Try to figure out the best overload.
36663635
ConstraintLocator *Locator = CS.getConstraintLocator(nullptr);
3667-
TypeVariableType *TV = CS.createTypeVariable(Locator,
3668-
TVO_CanBindToLValue |
3669-
TVO_CanBindToInOut);
3636+
TypeVariableType *TV = CS.createTypeVariable(Locator, TVO_CanBindToLValue);
36703637
CS.addOverloadSet(TV, LookupResult.ViableCandidates, &DC, Locator);
36713638
Optional<Solution> OpSolution = CS.solveSingle();
36723639
ValueDecl *Selected = nullptr;

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2542,7 +2542,6 @@ ConstraintSystem::simplifyConstructionConstraint(
25422542
ConstraintLocator::ApplyFunction);
25432543
auto tv = createTypeVariable(applyLocator,
25442544
TVO_CanBindToLValue |
2545-
TVO_CanBindToInOut |
25462545
TVO_PrefersSubtypeBinding);
25472546

25482547
// The constructor will have function type T -> T2, for a fresh type
@@ -4701,9 +4700,7 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
47014700
return SolutionKind::Error;
47024701

47034702
auto constraintLocator = getConstraintLocator(locator);
4704-
auto tv = createTypeVariable(constraintLocator,
4705-
TVO_PrefersSubtypeBinding |
4706-
TVO_CanBindToInOut);
4703+
auto tv = createTypeVariable(constraintLocator, TVO_PrefersSubtypeBinding);
47074704

47084705
addConstraint(ConstraintKind::ConformsTo, tv,
47094706
hashableProtocol->getDeclaredType(), constraintLocator);

0 commit comments

Comments
 (0)