Skip to content

Commit 95b7f50

Browse files
authored
Merge pull request #15709 from rudkx/minor-cleanup
NFC: Minor cleanup to make createTypeVariable options default to zero.
2 parents 9be6519 + 72f4b3d commit 95b7f50

File tree

7 files changed

+46
-70
lines changed

7 files changed

+46
-70
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7075,7 +7075,7 @@ bool FailureDiagnosis::visitKeyPathExpr(KeyPathExpr *KPE) {
70757075

70767076
bool builtConstraints(ConstraintSystem &cs, Expr *expr) override {
70777077
auto *locator = cs.getConstraintLocator(expr);
7078-
auto valueType = cs.createTypeVariable(locator, /*options*/0);
7078+
auto valueType = cs.createTypeVariable(locator);
70797079

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

lib/Sema/CSGen.cpp

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,8 +1033,8 @@ namespace {
10331033
// I -> inout? O, where I and O are fresh type variables. The index
10341034
// expression must be convertible to I and the subscript expression
10351035
// itself has type inout? O, where O may or may not be an lvalue.
1036-
auto inputTv = CS.createTypeVariable(indexLocator, /*options*/0);
1037-
1036+
auto inputTv = CS.createTypeVariable(indexLocator);
1037+
10381038
// For an integer subscript expression on an array slice type, instead of
10391039
// introducing a new type variable we can easily obtain the element type.
10401040
if (isa<SubscriptExpr>(anchor)) {
@@ -1419,7 +1419,7 @@ namespace {
14191419

14201420
auto memberLocator
14211421
= CS.getConstraintLocator(expr, ConstraintLocator::UnresolvedMember);
1422-
auto baseTy = CS.createTypeVariable(baseLocator, /*options*/0);
1422+
auto baseTy = CS.createTypeVariable(baseLocator);
14231423
auto memberTy = CS.createTypeVariable(memberLocator, TVO_CanBindToLValue);
14241424

14251425
// An unresolved member expression '.member' is modeled as a value member
@@ -1440,8 +1440,7 @@ namespace {
14401440
// TODO: we definitely want this to include ImplicitlyUnwrappedOptional; does it
14411441
// need to include everything else in the world?
14421442
auto outputTy = CS.createTypeVariable(
1443-
CS.getConstraintLocator(expr, ConstraintLocator::FunctionResult),
1444-
/*options*/0);
1443+
CS.getConstraintLocator(expr, ConstraintLocator::FunctionResult));
14451444
CS.addConstraint(ConstraintKind::Conversion, outputTy, baseTy,
14461445
CS.getConstraintLocator(expr, ConstraintLocator::RvalueAdjustment));
14471446

@@ -1495,8 +1494,7 @@ namespace {
14951494
CS.getConstraintLocator(expr),
14961495
TVO_CanBindToLValue |
14971496
TVO_PrefersSubtypeBinding);
1498-
auto resultTy = CS.createTypeVariable(CS.getConstraintLocator(expr),
1499-
/*options*/0);
1497+
auto resultTy = CS.createTypeVariable(CS.getConstraintLocator(expr));
15001498
auto methodTy = FunctionType::get(argsTy, resultTy);
15011499
CS.addValueMemberConstraint(baseTy, expr->getName(),
15021500
methodTy, CurDC, expr->getFunctionRefKind(),
@@ -1972,8 +1970,7 @@ namespace {
19721970
return CS.getType(boundExpr)->getRValueType();
19731971
}
19741972

1975-
return CS.createTypeVariable(CS.getConstraintLocator(locator),
1976-
/*options*/0);
1973+
return CS.createTypeVariable(CS.getConstraintLocator(locator));
19771974
}
19781975

19791976
case PatternKind::Named: {
@@ -2003,16 +2000,14 @@ namespace {
20032000
case ReferenceOwnership::Unmanaged:
20042001
if (ty)
20052002
return ty;
2006-
return CS.createTypeVariable(CS.getConstraintLocator(locator),
2007-
/*options*/0);
2003+
return CS.createTypeVariable(CS.getConstraintLocator(locator));
20082004
case ReferenceOwnership::Weak:
20092005
// For weak variables, use Optional<T>.
20102006
if (ty && ty->getOptionalObjectType())
20112007
return ty; // Already Optional<T>.
20122008
// Create a fresh type variable to handle overloaded expressions.
20132009
if (!ty || ty->is<TypeVariableType>())
2014-
ty = CS.createTypeVariable(CS.getConstraintLocator(locator),
2015-
/*options*/0);
2010+
ty = CS.createTypeVariable(CS.getConstraintLocator(locator));
20162011
return CS.getTypeChecker().getOptionalType(var->getLoc(), ty);
20172012
}
20182013

@@ -2052,8 +2047,7 @@ namespace {
20522047
#include "swift/AST/PatternNodes.def"
20532048
// TODO: we could try harder here, e.g. for enum elements to provide the
20542049
// enum type.
2055-
return CS.createTypeVariable(CS.getConstraintLocator(locator),
2056-
/*options*/0);
2050+
return CS.createTypeVariable(CS.getConstraintLocator(locator));
20572051
}
20582052

20592053
llvm_unreachable("Unhandled pattern kind");
@@ -2289,7 +2283,7 @@ namespace {
22892283

22902284
// If no return type was specified, create a fresh type
22912285
// variable for it.
2292-
funcTy = CS.createTypeVariable(locator, /*options*/0);
2286+
funcTy = CS.createTypeVariable(locator);
22932287

22942288
// Allow it to default to () if there are no return statements.
22952289
if (closureHasNoResult(expr)) {
@@ -2326,8 +2320,7 @@ namespace {
23262320
// S < lvalue T
23272321
//
23282322
// where T is a fresh type variable.
2329-
auto lvalue = CS.createTypeVariable(CS.getConstraintLocator(expr),
2330-
/*options*/0);
2323+
auto lvalue = CS.createTypeVariable(CS.getConstraintLocator(expr));
23312324
auto bound = LValueType::get(lvalue);
23322325
auto result = InOutType::get(lvalue);
23332326
CS.addConstraint(ConstraintKind::Conversion,
@@ -2337,8 +2330,7 @@ namespace {
23372330
}
23382331

23392332
Type visitDynamicTypeExpr(DynamicTypeExpr *expr) {
2340-
auto tv = CS.createTypeVariable(CS.getConstraintLocator(expr),
2341-
/*options*/0);
2333+
auto tv = CS.createTypeVariable(CS.getConstraintLocator(expr));
23422334
CS.addConstraint(ConstraintKind::DynamicTypeOf, tv,
23432335
CS.getType(expr->getBase()),
23442336
CS.getConstraintLocator(expr, ConstraintLocator::RvalueAdjustment));
@@ -2415,8 +2407,7 @@ namespace {
24152407
// variables T1 and T2.
24162408
if (outputTy.isNull()) {
24172409
outputTy = CS.createTypeVariable(
2418-
CS.getConstraintLocator(expr, ConstraintLocator::FunctionResult),
2419-
/*options*/0);
2410+
CS.getConstraintLocator(expr, ConstraintLocator::FunctionResult));
24202411
} else {
24212412
// Since we know what the output type is, we can set it as the favored
24222413
// type of this expression.
@@ -2507,7 +2498,7 @@ namespace {
25072498
Type
25082499
createTypeVariableAndDisjunctionForIUOCoercion(Type toType,
25092500
ConstraintLocator *locator) {
2510-
auto typeVar = CS.createTypeVariable(locator, /*options=*/0);
2501+
auto typeVar = CS.createTypeVariable(locator);
25112502
CS.buildDisjunctionForImplicitlyUnwrappedOptional(typeVar, toType,
25122503
locator);
25132504
return typeVar;
@@ -2643,7 +2634,7 @@ namespace {
26432634

26442635
Type visitDiscardAssignmentExpr(DiscardAssignmentExpr *expr) {
26452636
auto locator = CS.getConstraintLocator(expr);
2646-
auto typeVar = CS.createTypeVariable(locator, /*options=*/0);
2637+
auto typeVar = CS.createTypeVariable(locator);
26472638
return LValueType::get(typeVar);
26482639
}
26492640

@@ -2658,8 +2649,7 @@ namespace {
26582649
if (!destTy)
26592650
return Type();
26602651
if (destTy->is<UnresolvedType>()) {
2661-
return CS.createTypeVariable(CS.getConstraintLocator(expr),
2662-
/*options=*/0);
2652+
return CS.createTypeVariable(CS.getConstraintLocator(expr));
26632653
}
26642654

26652655
// The source must be convertible to the destination.
@@ -2774,7 +2764,7 @@ namespace {
27742764
auto &placeholderTy
27752765
= editorPlaceholderVariables[currentEditorPlaceholderVariable];
27762766
if (!placeholderTy) {
2777-
placeholderTy = CS.createTypeVariable(locator, /*options*/0);
2767+
placeholderTy = CS.createTypeVariable(locator);
27782768

27792769
CS.addConstraint(ConstraintKind::Defaultable,
27802770
placeholderTy,
@@ -2830,8 +2820,8 @@ namespace {
28302820
// For native key paths, traverse the key path components to set up
28312821
// appropriate type relationships at each level.
28322822
auto locator = CS.getConstraintLocator(E);
2833-
Type root = CS.createTypeVariable(locator, /*options*/0);
2834-
2823+
Type root = CS.createTypeVariable(locator);
2824+
28352825
// If a root type was explicitly given, then resolve it now.
28362826
if (auto rootRepr = E->getRootType()) {
28372827
auto rootObjectTy = resolveTypeReferenceInExpression(rootRepr);
@@ -2893,7 +2883,7 @@ namespace {
28932883

28942884
// We can't assign an optional back through an optional chain
28952885
// today. Force the base to an rvalue.
2896-
auto rvalueTy = CS.createTypeVariable(locator, 0);
2886+
auto rvalueTy = CS.createTypeVariable(locator);
28972887
CS.addConstraint(ConstraintKind::Equal, base, rvalueTy, locator);
28982888
base = rvalueTy;
28992889
LLVM_FALLTHROUGH;
@@ -2921,14 +2911,14 @@ namespace {
29212911
// If there was an optional chaining component, the end result must be
29222912
// optional.
29232913
if (didOptionalChain) {
2924-
auto objTy = CS.createTypeVariable(locator, /*options*/0);
2914+
auto objTy = CS.createTypeVariable(locator);
29252915
auto optTy = OptionalType::get(objTy);
29262916
CS.addConstraint(ConstraintKind::Conversion, base, optTy,
29272917
locator);
29282918
base = optTy;
29292919
}
2930-
2931-
auto rvalueBase = CS.createTypeVariable(locator, /*options*/0);
2920+
2921+
auto rvalueBase = CS.createTypeVariable(locator);
29322922
CS.addConstraint(ConstraintKind::Equal, base, rvalueBase, locator);
29332923

29342924
// The result is a KeyPath from the root to the end component.
@@ -2939,8 +2929,7 @@ namespace {
29392929
} else {
29402930
// The type of key path depends on the overloads chosen for the key
29412931
// path components.
2942-
kpTy = CS.createTypeVariable(CS.getConstraintLocator(E),
2943-
/*options*/0);
2932+
kpTy = CS.createTypeVariable(CS.getConstraintLocator(E));
29442933
CS.addKeyPathConstraint(kpTy, root, rvalueBase,
29452934
CS.getConstraintLocator(E));
29462935
}

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,8 +1690,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
16901690
// left-hand side is bound to type variable which
16911691
// is wrapped in `inout` type to preserve inout/lvalue pairing.
16921692
if (auto *lvt = type2->getAs<LValueType>()) {
1693-
auto *tv = createTypeVariable(typeVar1->getImpl().getLocator(),
1694-
/*options=*/0);
1693+
auto *tv = createTypeVariable(typeVar1->getImpl().getLocator());
16951694
assignFixedType(typeVar1, InOutType::get(tv));
16961695

16971696
typeVar1 = tv;

lib/Sema/CSSolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ ConstraintSystem::solve(Expr *&expr,
13641364
if (allowFreeTypeVariables == FreeTypeVariableBinding::UnresolvedType) {
13651365
convertType = convertType.transform([&](Type type) -> Type {
13661366
if (type->is<UnresolvedType>())
1367-
return createTypeVariable(getConstraintLocator(expr), /*options*/0);
1367+
return createTypeVariable(getConstraintLocator(expr));
13681368
return type;
13691369
});
13701370
}

lib/Sema/ConstraintSystem.cpp

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,12 +1466,10 @@ resolveOverloadForDeclWithSpecialTypeCheckingSemantics(ConstraintSystem &CS,
14661466
// existentials (as seen from the current abstraction level), which can't
14671467
// be expressed in the type system currently.
14681468
auto input = CS.createTypeVariable(
1469-
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument),
1470-
/*options*/0);
1469+
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument));
14711470
auto output = CS.createTypeVariable(
1472-
CS.getConstraintLocator(locator, ConstraintLocator::FunctionResult),
1473-
/*options*/0);
1474-
1471+
CS.getConstraintLocator(locator, ConstraintLocator::FunctionResult));
1472+
14751473
auto inputArg = TupleTypeElt(input, CS.getASTContext().getIdentifier("of"));
14761474
auto inputTuple = TupleType::get(inputArg, CS.getASTContext());
14771475

@@ -1486,17 +1484,14 @@ resolveOverloadForDeclWithSpecialTypeCheckingSemantics(ConstraintSystem &CS,
14861484
// receives a copy of the argument closure that is temporarily made
14871485
// @escaping.
14881486
auto noescapeClosure = CS.createTypeVariable(
1489-
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument),
1490-
/*options*/0);
1487+
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument));
14911488
auto escapeClosure = CS.createTypeVariable(
1492-
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument),
1493-
/*options*/0);
1489+
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument));
14941490
CS.addConstraint(ConstraintKind::EscapableFunctionOf,
14951491
escapeClosure, noescapeClosure,
14961492
CS.getConstraintLocator(locator, ConstraintLocator::RvalueAdjustment));
14971493
auto result = CS.createTypeVariable(
1498-
CS.getConstraintLocator(locator, ConstraintLocator::FunctionResult),
1499-
/*options*/0);
1494+
CS.getConstraintLocator(locator, ConstraintLocator::FunctionResult));
15001495
auto bodyClosure = FunctionType::get(
15011496
ParenType::get(CS.getASTContext(), escapeClosure), result,
15021497
FunctionType::ExtInfo(FunctionType::Representation::Swift,
@@ -1521,17 +1516,14 @@ resolveOverloadForDeclWithSpecialTypeCheckingSemantics(ConstraintSystem &CS,
15211516
// The body closure receives a freshly-opened archetype constrained by the
15221517
// existential type as its input.
15231518
auto openedTy = CS.createTypeVariable(
1524-
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument),
1525-
/*options*/0);
1519+
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument));
15261520
auto existentialTy = CS.createTypeVariable(
1527-
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument),
1528-
/*options*/0);
1521+
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument));
15291522
CS.addConstraint(ConstraintKind::OpenedExistentialOf,
15301523
openedTy, existentialTy,
15311524
CS.getConstraintLocator(locator, ConstraintLocator::RvalueAdjustment));
15321525
auto result = CS.createTypeVariable(
1533-
CS.getConstraintLocator(locator, ConstraintLocator::FunctionResult),
1534-
/*options*/0);
1526+
CS.getConstraintLocator(locator, ConstraintLocator::FunctionResult));
15351527
auto bodyClosure = FunctionType::get(
15361528
ParenType::get(CS.getASTContext(), openedTy), result,
15371529
FunctionType::ExtInfo(FunctionType::Representation::Swift,
@@ -1629,7 +1621,7 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
16291621
if (choice.isImplicitlyUnwrappedValueOrReturnValue()) {
16301622
// Build the disjunction to attempt binding both T? and T (or
16311623
// function returning T? and function returning T).
1632-
Type ty = createTypeVariable(locator, /*options*/0);
1624+
Type ty = createTypeVariable(locator);
16331625
buildDisjunctionForImplicitlyUnwrappedOptional(ty, refType,
16341626
locator);
16351627
addConstraint(ConstraintKind::Bind, boundType,
@@ -1659,7 +1651,7 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
16591651
// For our original type T -> U?? we will generate:
16601652
// A disjunction V = { U?, U }
16611653
// and a disjunction boundType = { T -> V?, T -> V }
1662-
Type ty = createTypeVariable(locator, /*options*/0);
1654+
Type ty = createTypeVariable(locator);
16631655

16641656
buildDisjunctionForImplicitlyUnwrappedOptional(ty, optTy, locator);
16651657

@@ -1769,14 +1761,12 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
17691761
// The element type is T or @lvalue T based on the key path subtype and
17701762
// the mutability of the base.
17711763
auto keyPathIndexTy = createTypeVariable(
1772-
getConstraintLocator(locator, ConstraintLocator::FunctionArgument),
1773-
/*options*/0);
1764+
getConstraintLocator(locator, ConstraintLocator::FunctionArgument));
17741765
auto elementTy = createTypeVariable(
17751766
getConstraintLocator(locator, ConstraintLocator::FunctionArgument),
17761767
TVO_CanBindToLValue);
17771768
auto elementObjTy = createTypeVariable(
1778-
getConstraintLocator(locator, ConstraintLocator::FunctionArgument),
1779-
/*options*/0);
1769+
getConstraintLocator(locator, ConstraintLocator::FunctionArgument));
17801770
addConstraint(ConstraintKind::Equal, elementTy, elementObjTy, locator);
17811771

17821772
// The element result is an lvalue or rvalue based on the key path class.

lib/Sema/ConstraintSystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ class ConstraintSystem {
15661566

15671567
/// \brief Create a new type variable.
15681568
TypeVariableType *createTypeVariable(ConstraintLocator *locator,
1569-
unsigned options);
1569+
unsigned options = 0);
15701570

15711571
/// Retrieve the set of active type variables.
15721572
ArrayRef<TypeVariableType *> getTypeVariables() const {

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,8 +2331,7 @@ bool TypeChecker::typeCheckForEachBinding(DeclContext *dc, ForEachStmt *stmt) {
23312331
return true;
23322332
}
23332333

2334-
SequenceType =
2335-
cs.createTypeVariable(Locator, /*options=*/0);
2334+
SequenceType = cs.createTypeVariable(Locator);
23362335
cs.addConstraint(ConstraintKind::Conversion, cs.getType(expr),
23372336
SequenceType, Locator);
23382337
cs.addConstraint(ConstraintKind::ConformsTo, SequenceType,
@@ -2405,7 +2404,7 @@ bool TypeChecker::typeCheckForEachBinding(DeclContext *dc, ForEachStmt *stmt) {
24052404
}
24062405

24072406
if (elementType.isNull()) {
2408-
elementType = cs.createTypeVariable(elementLocator, /*options=*/0);
2407+
elementType = cs.createTypeVariable(elementLocator);
24092408
}
24102409

24112410
// Add a conversion constraint between the element type of the sequence
@@ -2489,8 +2488,7 @@ Type ConstraintSystem::computeAssignDestType(Expr *dest, SourceLoc equalLoc) {
24892488
if (auto typeVar = dyn_cast<TypeVariableType>(destTy.getPointer())) {
24902489
// Newly allocated type should be explicitly materializable,
24912490
// it's invalid to use non-materializable types as assignment destination.
2492-
auto objectTv = createTypeVariable(getConstraintLocator(dest),
2493-
/*options=*/0);
2491+
auto objectTv = createTypeVariable(getConstraintLocator(dest));
24942492
auto refTv = LValueType::get(objectTv);
24952493
addConstraint(ConstraintKind::Bind, typeVar, refTv,
24962494
getConstraintLocator(dest));
@@ -2714,7 +2712,7 @@ static Type replaceArchetypesWithTypeVariables(ConstraintSystem &cs,
27142712
return Type();
27152713

27162714
auto locator = cs.getConstraintLocator(nullptr);
2717-
auto replacement = cs.createTypeVariable(locator, /*options*/0);
2715+
auto replacement = cs.createTypeVariable(locator);
27182716

27192717
if (auto superclass = archetypeType->getSuperclass()) {
27202718
cs.addConstraint(ConstraintKind::Subtype, replacement,
@@ -2731,7 +2729,7 @@ static Type replaceArchetypesWithTypeVariables(ConstraintSystem &cs,
27312729
// FIXME: Remove this case
27322730
assert(cast<GenericTypeParamType>(origType));
27332731
auto locator = cs.getConstraintLocator(nullptr);
2734-
auto replacement = cs.createTypeVariable(locator, /*options*/0);
2732+
auto replacement = cs.createTypeVariable(locator);
27352733
types[origType] = replacement;
27362734
return replacement;
27372735
},

0 commit comments

Comments
 (0)