Skip to content

NFC: Minor cleanup to make createTypeVariable options default to zero. #15709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Sema/CSDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7075,7 +7075,7 @@ bool FailureDiagnosis::visitKeyPathExpr(KeyPathExpr *KPE) {

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

auto keyPathType =
BoundGenericClassType::get(Decl, ParentType, {RootType, valueType});
Expand Down
59 changes: 24 additions & 35 deletions lib/Sema/CSGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,8 +1033,8 @@ namespace {
// I -> inout? O, where I and O are fresh type variables. The index
// expression must be convertible to I and the subscript expression
// itself has type inout? O, where O may or may not be an lvalue.
auto inputTv = CS.createTypeVariable(indexLocator, /*options*/0);
auto inputTv = CS.createTypeVariable(indexLocator);

// For an integer subscript expression on an array slice type, instead of
// introducing a new type variable we can easily obtain the element type.
if (isa<SubscriptExpr>(anchor)) {
Expand Down Expand Up @@ -1419,7 +1419,7 @@ namespace {

auto memberLocator
= CS.getConstraintLocator(expr, ConstraintLocator::UnresolvedMember);
auto baseTy = CS.createTypeVariable(baseLocator, /*options*/0);
auto baseTy = CS.createTypeVariable(baseLocator);
auto memberTy = CS.createTypeVariable(memberLocator, TVO_CanBindToLValue);

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

Expand Down Expand Up @@ -1495,8 +1494,7 @@ namespace {
CS.getConstraintLocator(expr),
TVO_CanBindToLValue |
TVO_PrefersSubtypeBinding);
auto resultTy = CS.createTypeVariable(CS.getConstraintLocator(expr),
/*options*/0);
auto resultTy = CS.createTypeVariable(CS.getConstraintLocator(expr));
auto methodTy = FunctionType::get(argsTy, resultTy);
CS.addValueMemberConstraint(baseTy, expr->getName(),
methodTy, CurDC, expr->getFunctionRefKind(),
Expand Down Expand Up @@ -1972,8 +1970,7 @@ namespace {
return CS.getType(boundExpr)->getRValueType();
}

return CS.createTypeVariable(CS.getConstraintLocator(locator),
/*options*/0);
return CS.createTypeVariable(CS.getConstraintLocator(locator));
}

case PatternKind::Named: {
Expand Down Expand Up @@ -2003,16 +2000,14 @@ namespace {
case ReferenceOwnership::Unmanaged:
if (ty)
return ty;
return CS.createTypeVariable(CS.getConstraintLocator(locator),
/*options*/0);
return CS.createTypeVariable(CS.getConstraintLocator(locator));
case ReferenceOwnership::Weak:
// For weak variables, use Optional<T>.
if (ty && ty->getOptionalObjectType())
return ty; // Already Optional<T>.
// Create a fresh type variable to handle overloaded expressions.
if (!ty || ty->is<TypeVariableType>())
ty = CS.createTypeVariable(CS.getConstraintLocator(locator),
/*options*/0);
ty = CS.createTypeVariable(CS.getConstraintLocator(locator));
return CS.getTypeChecker().getOptionalType(var->getLoc(), ty);
}

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

llvm_unreachable("Unhandled pattern kind");
Expand Down Expand Up @@ -2289,7 +2283,7 @@ namespace {

// If no return type was specified, create a fresh type
// variable for it.
funcTy = CS.createTypeVariable(locator, /*options*/0);
funcTy = CS.createTypeVariable(locator);

// Allow it to default to () if there are no return statements.
if (closureHasNoResult(expr)) {
Expand Down Expand Up @@ -2326,8 +2320,7 @@ namespace {
// S < lvalue T
//
// where T is a fresh type variable.
auto lvalue = CS.createTypeVariable(CS.getConstraintLocator(expr),
/*options*/0);
auto lvalue = CS.createTypeVariable(CS.getConstraintLocator(expr));
auto bound = LValueType::get(lvalue);
auto result = InOutType::get(lvalue);
CS.addConstraint(ConstraintKind::Conversion,
Expand All @@ -2337,8 +2330,7 @@ namespace {
}

Type visitDynamicTypeExpr(DynamicTypeExpr *expr) {
auto tv = CS.createTypeVariable(CS.getConstraintLocator(expr),
/*options*/0);
auto tv = CS.createTypeVariable(CS.getConstraintLocator(expr));
CS.addConstraint(ConstraintKind::DynamicTypeOf, tv,
CS.getType(expr->getBase()),
CS.getConstraintLocator(expr, ConstraintLocator::RvalueAdjustment));
Expand Down Expand Up @@ -2415,8 +2407,7 @@ namespace {
// variables T1 and T2.
if (outputTy.isNull()) {
outputTy = CS.createTypeVariable(
CS.getConstraintLocator(expr, ConstraintLocator::FunctionResult),
/*options*/0);
CS.getConstraintLocator(expr, ConstraintLocator::FunctionResult));
} else {
// Since we know what the output type is, we can set it as the favored
// type of this expression.
Expand Down Expand Up @@ -2507,7 +2498,7 @@ namespace {
Type
createTypeVariableAndDisjunctionForIUOCoercion(Type toType,
ConstraintLocator *locator) {
auto typeVar = CS.createTypeVariable(locator, /*options=*/0);
auto typeVar = CS.createTypeVariable(locator);
CS.buildDisjunctionForImplicitlyUnwrappedOptional(typeVar, toType,
locator);
return typeVar;
Expand Down Expand Up @@ -2643,7 +2634,7 @@ namespace {

Type visitDiscardAssignmentExpr(DiscardAssignmentExpr *expr) {
auto locator = CS.getConstraintLocator(expr);
auto typeVar = CS.createTypeVariable(locator, /*options=*/0);
auto typeVar = CS.createTypeVariable(locator);
return LValueType::get(typeVar);
}

Expand All @@ -2658,8 +2649,7 @@ namespace {
if (!destTy)
return Type();
if (destTy->is<UnresolvedType>()) {
return CS.createTypeVariable(CS.getConstraintLocator(expr),
/*options=*/0);
return CS.createTypeVariable(CS.getConstraintLocator(expr));
}

// The source must be convertible to the destination.
Expand Down Expand Up @@ -2774,7 +2764,7 @@ namespace {
auto &placeholderTy
= editorPlaceholderVariables[currentEditorPlaceholderVariable];
if (!placeholderTy) {
placeholderTy = CS.createTypeVariable(locator, /*options*/0);
placeholderTy = CS.createTypeVariable(locator);

CS.addConstraint(ConstraintKind::Defaultable,
placeholderTy,
Expand Down Expand Up @@ -2830,8 +2820,8 @@ namespace {
// For native key paths, traverse the key path components to set up
// appropriate type relationships at each level.
auto locator = CS.getConstraintLocator(E);
Type root = CS.createTypeVariable(locator, /*options*/0);
Type root = CS.createTypeVariable(locator);

// If a root type was explicitly given, then resolve it now.
if (auto rootRepr = E->getRootType()) {
auto rootObjectTy = resolveTypeReferenceInExpression(rootRepr);
Expand Down Expand Up @@ -2893,7 +2883,7 @@ namespace {

// We can't assign an optional back through an optional chain
// today. Force the base to an rvalue.
auto rvalueTy = CS.createTypeVariable(locator, 0);
auto rvalueTy = CS.createTypeVariable(locator);
CS.addConstraint(ConstraintKind::Equal, base, rvalueTy, locator);
base = rvalueTy;
LLVM_FALLTHROUGH;
Expand Down Expand Up @@ -2921,14 +2911,14 @@ namespace {
// If there was an optional chaining component, the end result must be
// optional.
if (didOptionalChain) {
auto objTy = CS.createTypeVariable(locator, /*options*/0);
auto objTy = CS.createTypeVariable(locator);
auto optTy = OptionalType::get(objTy);
CS.addConstraint(ConstraintKind::Conversion, base, optTy,
locator);
base = optTy;
}
auto rvalueBase = CS.createTypeVariable(locator, /*options*/0);

auto rvalueBase = CS.createTypeVariable(locator);
CS.addConstraint(ConstraintKind::Equal, base, rvalueBase, locator);

// The result is a KeyPath from the root to the end component.
Expand All @@ -2939,8 +2929,7 @@ namespace {
} else {
// The type of key path depends on the overloads chosen for the key
// path components.
kpTy = CS.createTypeVariable(CS.getConstraintLocator(E),
/*options*/0);
kpTy = CS.createTypeVariable(CS.getConstraintLocator(E));
CS.addKeyPathConstraint(kpTy, root, rvalueBase,
CS.getConstraintLocator(E));
}
Expand Down
3 changes: 1 addition & 2 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1690,8 +1690,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
// left-hand side is bound to type variable which
// is wrapped in `inout` type to preserve inout/lvalue pairing.
if (auto *lvt = type2->getAs<LValueType>()) {
auto *tv = createTypeVariable(typeVar1->getImpl().getLocator(),
/*options=*/0);
auto *tv = createTypeVariable(typeVar1->getImpl().getLocator());
assignFixedType(typeVar1, InOutType::get(tv));

typeVar1 = tv;
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/CSSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ ConstraintSystem::solve(Expr *&expr,
if (allowFreeTypeVariables == FreeTypeVariableBinding::UnresolvedType) {
convertType = convertType.transform([&](Type type) -> Type {
if (type->is<UnresolvedType>())
return createTypeVariable(getConstraintLocator(expr), /*options*/0);
return createTypeVariable(getConstraintLocator(expr));
return type;
});
}
Expand Down
36 changes: 13 additions & 23 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1466,12 +1466,10 @@ resolveOverloadForDeclWithSpecialTypeCheckingSemantics(ConstraintSystem &CS,
// existentials (as seen from the current abstraction level), which can't
// be expressed in the type system currently.
auto input = CS.createTypeVariable(
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument),
/*options*/0);
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument));
auto output = CS.createTypeVariable(
CS.getConstraintLocator(locator, ConstraintLocator::FunctionResult),
/*options*/0);

CS.getConstraintLocator(locator, ConstraintLocator::FunctionResult));

auto inputArg = TupleTypeElt(input, CS.getASTContext().getIdentifier("of"));
auto inputTuple = TupleType::get(inputArg, CS.getASTContext());

Expand All @@ -1486,17 +1484,14 @@ resolveOverloadForDeclWithSpecialTypeCheckingSemantics(ConstraintSystem &CS,
// receives a copy of the argument closure that is temporarily made
// @escaping.
auto noescapeClosure = CS.createTypeVariable(
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument),
/*options*/0);
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument));
auto escapeClosure = CS.createTypeVariable(
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument),
/*options*/0);
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument));
CS.addConstraint(ConstraintKind::EscapableFunctionOf,
escapeClosure, noescapeClosure,
CS.getConstraintLocator(locator, ConstraintLocator::RvalueAdjustment));
auto result = CS.createTypeVariable(
CS.getConstraintLocator(locator, ConstraintLocator::FunctionResult),
/*options*/0);
CS.getConstraintLocator(locator, ConstraintLocator::FunctionResult));
auto bodyClosure = FunctionType::get(
ParenType::get(CS.getASTContext(), escapeClosure), result,
FunctionType::ExtInfo(FunctionType::Representation::Swift,
Expand All @@ -1521,17 +1516,14 @@ resolveOverloadForDeclWithSpecialTypeCheckingSemantics(ConstraintSystem &CS,
// The body closure receives a freshly-opened archetype constrained by the
// existential type as its input.
auto openedTy = CS.createTypeVariable(
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument),
/*options*/0);
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument));
auto existentialTy = CS.createTypeVariable(
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument),
/*options*/0);
CS.getConstraintLocator(locator, ConstraintLocator::FunctionArgument));
CS.addConstraint(ConstraintKind::OpenedExistentialOf,
openedTy, existentialTy,
CS.getConstraintLocator(locator, ConstraintLocator::RvalueAdjustment));
auto result = CS.createTypeVariable(
CS.getConstraintLocator(locator, ConstraintLocator::FunctionResult),
/*options*/0);
CS.getConstraintLocator(locator, ConstraintLocator::FunctionResult));
auto bodyClosure = FunctionType::get(
ParenType::get(CS.getASTContext(), openedTy), result,
FunctionType::ExtInfo(FunctionType::Representation::Swift,
Expand Down Expand Up @@ -1629,7 +1621,7 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
if (choice.isImplicitlyUnwrappedValueOrReturnValue()) {
// Build the disjunction to attempt binding both T? and T (or
// function returning T? and function returning T).
Type ty = createTypeVariable(locator, /*options*/0);
Type ty = createTypeVariable(locator);
buildDisjunctionForImplicitlyUnwrappedOptional(ty, refType,
locator);
addConstraint(ConstraintKind::Bind, boundType,
Expand Down Expand Up @@ -1659,7 +1651,7 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
// For our original type T -> U?? we will generate:
// A disjunction V = { U?, U }
// and a disjunction boundType = { T -> V?, T -> V }
Type ty = createTypeVariable(locator, /*options*/0);
Type ty = createTypeVariable(locator);

buildDisjunctionForImplicitlyUnwrappedOptional(ty, optTy, locator);

Expand Down Expand Up @@ -1769,14 +1761,12 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
// The element type is T or @lvalue T based on the key path subtype and
// the mutability of the base.
auto keyPathIndexTy = createTypeVariable(
getConstraintLocator(locator, ConstraintLocator::FunctionArgument),
/*options*/0);
getConstraintLocator(locator, ConstraintLocator::FunctionArgument));
auto elementTy = createTypeVariable(
getConstraintLocator(locator, ConstraintLocator::FunctionArgument),
TVO_CanBindToLValue);
auto elementObjTy = createTypeVariable(
getConstraintLocator(locator, ConstraintLocator::FunctionArgument),
/*options*/0);
getConstraintLocator(locator, ConstraintLocator::FunctionArgument));
addConstraint(ConstraintKind::Equal, elementTy, elementObjTy, locator);

// The element result is an lvalue or rvalue based on the key path class.
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,7 @@ class ConstraintSystem {

/// \brief Create a new type variable.
TypeVariableType *createTypeVariable(ConstraintLocator *locator,
unsigned options);
unsigned options = 0);

/// Retrieve the set of active type variables.
ArrayRef<TypeVariableType *> getTypeVariables() const {
Expand Down
12 changes: 5 additions & 7 deletions lib/Sema/TypeCheckConstraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2331,8 +2331,7 @@ bool TypeChecker::typeCheckForEachBinding(DeclContext *dc, ForEachStmt *stmt) {
return true;
}

SequenceType =
cs.createTypeVariable(Locator, /*options=*/0);
SequenceType = cs.createTypeVariable(Locator);
cs.addConstraint(ConstraintKind::Conversion, cs.getType(expr),
SequenceType, Locator);
cs.addConstraint(ConstraintKind::ConformsTo, SequenceType,
Expand Down Expand Up @@ -2405,7 +2404,7 @@ bool TypeChecker::typeCheckForEachBinding(DeclContext *dc, ForEachStmt *stmt) {
}

if (elementType.isNull()) {
elementType = cs.createTypeVariable(elementLocator, /*options=*/0);
elementType = cs.createTypeVariable(elementLocator);
}

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

auto locator = cs.getConstraintLocator(nullptr);
auto replacement = cs.createTypeVariable(locator, /*options*/0);
auto replacement = cs.createTypeVariable(locator);

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