Skip to content

[ConstraintSystem] Rename getFixedType/assignFixedType/getFixedTypeRecursive. #18327

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

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ using namespace swift;
using namespace constraints;

/// \brief Retrieve the fixed type for the given type variable.
Type Solution::getFixedType(TypeVariableType *typeVar) const {
Type Solution::getBoundType(TypeVariableType *typeVar) const {
auto knownBinding = typeBindings.find(typeVar);
assert(knownBinding != typeBindings.end());
return knownBinding->second;
Expand Down Expand Up @@ -77,7 +77,7 @@ SubstitutionMap Solution::computeSubstitutions(

TypeSubstitutionMap subs;
for (const auto &opened : openedTypes->second)
subs[opened.first] = getFixedType(opened.second);
subs[opened.first] = getBoundType(opened.second);

auto &tc = getConstraintSystem().getTypeChecker();

Expand Down
6 changes: 3 additions & 3 deletions lib/Sema/CSBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ConstraintSystem::determineBestBindings() {

// First, let's collect all of the possible bindings.
for (auto *typeVar : getTypeVariables()) {
if (typeVar->getImpl().hasRepresentativeOrFixed())
if (typeVar->getImpl().hasRepresentativeOrBound())
continue;

if (auto bindings = getPotentialBindings(typeVar))
Expand Down Expand Up @@ -359,7 +359,7 @@ ConstraintSystem::PotentialBindings
ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) {
assert(typeVar->getImpl().getRepresentative(nullptr) == typeVar &&
"not a representative");
assert(!typeVar->getImpl().getFixedType(nullptr) && "has a fixed type");
assert(!typeVar->getImpl().getBoundType(nullptr) && "has a fixed type");

// Gather the constraints associated with this type variable.
llvm::SetVector<Constraint *> constraints;
Expand Down Expand Up @@ -449,7 +449,7 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) {

case ConstraintKind::Defaultable:
// Do these in a separate pass.
if (getFixedTypeRecursive(constraint->getFirstType(), true)
if (resolveTypeVariable(constraint->getFirstType(), true)
->getAs<TypeVariableType>() == typeVar) {
defaultableConstraints.push_back(constraint);
hasNonDependentMemberRelationalConstraints = true;
Expand Down
8 changes: 4 additions & 4 deletions lib/Sema/CSDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6095,7 +6095,7 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
if (locator->getAnchor() == callExpr) {
argType = constraint->getSecondType();
if (auto *typeVar = argType->getAs<TypeVariableType>())
argType = CS.getFixedType(typeVar);
argType = CS.getBoundType(typeVar);
}
}
}
Expand Down Expand Up @@ -8481,8 +8481,8 @@ static void noteArchetypeSource(const TypeLoc &loc, ArchetypeType *archetype,

// ...but only if they were actually resolved by the constraint system
// despite the failure.
Type maybeFixedType = cs.getFixedTypeRecursive(preferred,
/*wantRValue*/true);
Type maybeFixedType = cs.resolveTypeVariable(preferred,
/*wantRValue*/ true);
if (maybeFixedType->hasTypeVariable() ||
maybeFixedType->hasUnresolvedType()) {
return Type();
Expand Down Expand Up @@ -8715,7 +8715,7 @@ bool FailureDiagnosis::diagnoseArchetypeAmbiguity() {
for (auto tv : CS.getTypeVariables()) {
auto &impl = tv->getImpl();

if (impl.hasRepresentativeOrFixed())
if (impl.hasRepresentativeOrBound())
continue;

// If this is a conversion to a type variable used to form an archetype,
Expand Down
4 changes: 2 additions & 2 deletions lib/Sema/CSGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -75,7 +75,7 @@ static bool mergeRepresentativeEquivalenceClasses(ConstraintSystem &CS,
auto rep2 = CS.getRepresentative(tyvar2);

if (rep1 != rep2) {
auto fixedType2 = CS.getFixedType(rep2);
auto fixedType2 = CS.getBoundType(rep2);

// If the there exists fixed type associated with the second
// type variable, and we simply merge two types together it would
Expand Down
79 changes: 40 additions & 39 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,9 +683,9 @@ getCalleeDeclAndArgs(ConstraintSystem &cs,
// References to instance members on a metatype stay at level 0.
// Everything else is level 1.
if (!(function->isInstanceMember() &&
cs.getFixedTypeRecursive(choice->getBaseType(),
/*wantRValue=*/true)
->is<AnyMetatypeType>()))
cs.resolveTypeVariable(choice->getBaseType(),
/*wantRValue=*/true)
->is<AnyMetatypeType>()))
level = 1;
} else if (isa<SubscriptDecl>(decl)) {
// Subscript level 1 == the indices.
Expand Down Expand Up @@ -1624,7 +1624,7 @@ ConstraintSystem::matchTypesBindTypeVar(
return getTypeMatchSuccess();
}

assignFixedType(typeVar, type);
assignBoundType(typeVar, type);

return getTypeMatchSuccess();
}
Expand All @@ -1648,10 +1648,10 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,

// If we have type variables that have been bound to fixed types, look through
// to the fixed type.
type1 = getFixedTypeRecursive(type1, flags, kind == ConstraintKind::Equal,
isArgumentTupleMatch);
type2 = getFixedTypeRecursive(type2, flags, kind == ConstraintKind::Equal,
isArgumentTupleMatch);
type1 = resolveTypeVariable(type1, flags, kind == ConstraintKind::Equal,
isArgumentTupleMatch);
type2 = resolveTypeVariable(type2, flags, kind == ConstraintKind::Equal,
isArgumentTupleMatch);

auto desugar1 = type1->getDesugaredType();
auto desugar2 = type2->getDesugaredType();
Expand Down Expand Up @@ -1756,9 +1756,9 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
return formUnsolvedResult();

if (auto *iot = type1->getAs<InOutType>()) {
assignFixedType(typeVar2, LValueType::get(iot->getObjectType()));
assignBoundType(typeVar2, LValueType::get(iot->getObjectType()));
} else {
assignFixedType(typeVar2, type1);
assignBoundType(typeVar2, type1);
}
return getTypeMatchSuccess();
} else if (typeVar1 && !typeVar2) {
Expand All @@ -1774,7 +1774,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
// is wrapped in `inout` type to preserve inout/lvalue pairing.
if (auto *lvt = type2->getAs<LValueType>()) {
auto *tv = createTypeVariable(typeVar1->getImpl().getLocator());
assignFixedType(typeVar1, InOutType::get(tv));
assignBoundType(typeVar1, InOutType::get(tv));

typeVar1 = tv;
type2 = lvt->getObjectType();
Expand Down Expand Up @@ -2272,7 +2272,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
if (auto inoutType1 = dyn_cast<InOutType>(desugar1)) {
auto inoutBaseType = inoutType1->getInOutObjectType();

Type simplifiedInoutBaseType = getFixedTypeRecursive(
Type simplifiedInoutBaseType = resolveTypeVariable(
inoutBaseType, kind == ConstraintKind::Equal,
isArgumentTupleConversion);

Expand Down Expand Up @@ -2342,7 +2342,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
// The pointer can be converted from a string, if the element
// type is compatible.
if (type1->isEqual(TC.getStringType(DC))) {
auto baseTy = getFixedTypeRecursive(pointeeTy, false);
auto baseTy = resolveTypeVariable(pointeeTy, false);

if (baseTy->isTypeVariableOrMember() ||
isStringCompatiblePointerBaseType(TC, DC, baseTy))
Expand Down Expand Up @@ -2669,7 +2669,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
}

// Dig out the fixed type to which this type refers.
type = getFixedTypeRecursive(type, flags, /*wantRValue=*/true);
type = resolveTypeVariable(type, flags, /*wantRValue=*/true);

return matchExistentialTypes(type, protocol, kind, flags, locator);
}
Expand All @@ -2681,7 +2681,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
ConstraintLocatorBuilder locator,
TypeMatchOptions flags) {
// Dig out the fixed type to which this type refers.
type = getFixedTypeRecursive(type, flags, /*wantRValue=*/true);
type = resolveTypeVariable(type, flags, /*wantRValue=*/true);

// If we hit a type variable without a fixed type, we can't
// solve this yet.
Expand Down Expand Up @@ -2818,15 +2818,15 @@ ConstraintSystem::simplifyCheckedCastConstraint(

do {
// Dig out the fixed type this type refers to.
fromType = getFixedTypeRecursive(fromType, flags, /*wantRValue=*/true);
fromType = resolveTypeVariable(fromType, flags, /*wantRValue=*/true);

// If we hit a type variable without a fixed type, we can't
// solve this yet.
if (fromType->isTypeVariableOrMember())
return formUnsolved();

// Dig out the fixed type this type refers to.
toType = getFixedTypeRecursive(toType, flags, /*wantRValue=*/true);
toType = resolveTypeVariable(toType, flags, /*wantRValue=*/true);

// If we hit a type variable without a fixed type, we can't
// solve this yet.
Expand Down Expand Up @@ -2929,10 +2929,10 @@ ConstraintSystem::simplifyOptionalObjectConstraint(
TypeMatchOptions flags,
ConstraintLocatorBuilder locator) {
// Resolve the optional type.
Type optLValueTy = getFixedTypeRecursive(first, flags, /*wantRValue=*/false);
Type optLValueTy = resolveTypeVariable(first, flags, /*wantRValue=*/false);
Type optTy = optLValueTy->getRValueType();
if (optTy.getPointer() != optLValueTy.getPointer())
optTy = getFixedTypeRecursive(optTy, /*wantRValue=*/false);
optTy = resolveTypeVariable(optTy, /*wantRValue=*/false);

if (optTy->isTypeVariableOrMember()) {
if (flags.contains(TMF_GenerateConstraints)) {
Expand Down Expand Up @@ -3657,7 +3657,7 @@ ConstraintSystem::simplifyDefaultableConstraint(
Type first, Type second,
TypeMatchOptions flags,
ConstraintLocatorBuilder locator) {
first = getFixedTypeRecursive(first, flags, true);
first = resolveTypeVariable(first, flags, true);

if (first->isTypeVariableOrMember()) {
if (flags.contains(TMF_GenerateConstraints)) {
Expand Down Expand Up @@ -3695,7 +3695,7 @@ ConstraintSystem::simplifyDynamicTypeOfConstraint(
};

// Solve forward.
type2 = getFixedTypeRecursive(type2, flags, /*wantRValue=*/true);
type2 = resolveTypeVariable(type2, flags, /*wantRValue=*/true);
if (!type2->isTypeVariableOrMember()) {
Type dynamicType2;
if (type2->isAnyExistentialType()) {
Expand All @@ -3708,7 +3708,7 @@ ConstraintSystem::simplifyDynamicTypeOfConstraint(
}

// Okay, can't solve forward. See what we can do backwards.
type1 = getFixedTypeRecursive(type1, flags, /*wantRValue=*/true);
type1 = resolveTypeVariable(type1, flags, /*wantRValue=*/true);
if (type1->isTypeVariableOrMember())
return formUnsolved();

Expand All @@ -3722,8 +3722,8 @@ ConstraintSystem::simplifyDynamicTypeOfConstraint(
// If we have a normal metatype, we can't solve backwards unless we
// know what kind of object it is.
if (auto metatype1 = type1->getAs<MetatypeType>()) {
Type instanceType1 = getFixedTypeRecursive(metatype1->getInstanceType(),
true);
Type instanceType1 =
resolveTypeVariable(metatype1->getInstanceType(), true);
if (instanceType1->isTypeVariableOrMember())
return formUnsolved();

Expand Down Expand Up @@ -3764,14 +3764,15 @@ ConstraintSystem::simplifyBridgingConstraint(Type type1,
++count;

TypeMatchOptions unusedOptions;
type = getFixedTypeRecursive(objectType, unusedOptions, /*wantRValue=*/true);
type =
resolveTypeVariable(objectType, unusedOptions, /*wantRValue=*/true);
}

return { type, count };
};

type1 = getFixedTypeRecursive(type1, flags, /*wantRValue=*/true);
type2 = getFixedTypeRecursive(type2, flags, /*wantRValue=*/true);
type1 = resolveTypeVariable(type1, flags, /*wantRValue=*/true);
type2 = resolveTypeVariable(type2, flags, /*wantRValue=*/true);

if (type1->isTypeVariableOrMember() || type2->isTypeVariableOrMember())
return formUnsolved();
Expand Down Expand Up @@ -3961,7 +3962,7 @@ ConstraintSystem::simplifyEscapableFunctionOfConstraint(
};


type2 = getFixedTypeRecursive(type2, flags, /*wantRValue=*/true);
type2 = resolveTypeVariable(type2, flags, /*wantRValue=*/true);
if (auto fn2 = type2->getAs<FunctionType>()) {
// Solve forward by binding the other type variable to the escapable
// variation of this type.
Expand All @@ -3972,7 +3973,7 @@ ConstraintSystem::simplifyEscapableFunctionOfConstraint(
// We definitely don't have a function, so bail.
return SolutionKind::Error;

type1 = getFixedTypeRecursive(type1, flags, /*wantRValue=*/true);
type1 = resolveTypeVariable(type1, flags, /*wantRValue=*/true);
if (auto fn1 = type1->getAs<FunctionType>()) {
// We should have the escaping end of the relation.
if (fn1->getExtInfo().isNoEscape())
Expand All @@ -3996,7 +3997,7 @@ ConstraintSystem::simplifyOpenedExistentialOfConstraint(
TypeMatchOptions flags,
ConstraintLocatorBuilder locator) {
TypeMatchOptions subflags = getDefaultDecompositionOptions(flags);
type2 = getFixedTypeRecursive(type2, flags, /*wantRValue=*/true);
type2 = resolveTypeVariable(type2, flags, /*wantRValue=*/true);
if (type2->isAnyExistentialType()) {
// We have the existential side. Produce an opened archetype and bind
// type1 to it.
Expand All @@ -4018,7 +4019,7 @@ ConstraintSystem::simplifyOpenedExistentialOfConstraint(

// If type1 is constrained to anything concrete, the constraint fails.
// It can only be bound to a type we opened for it.
type1 = getFixedTypeRecursive(type1, flags, /*wantRValue=*/true);
type1 = resolveTypeVariable(type1, flags, /*wantRValue=*/true);
if (!type1->isTypeVariableOrMember())
return SolutionKind::Error;

Expand Down Expand Up @@ -4055,7 +4056,7 @@ ConstraintSystem::simplifyKeyPathConstraint(Type keyPathTy,
}
}

keyPathTy = getFixedTypeRecursive(keyPathTy, /*want rvalue*/ true);
keyPathTy = resolveTypeVariable(keyPathTy, /*want rvalue*/ true);
auto tryMatchRootAndValueFromKeyPathType =
[&](BoundGenericType *bgt, bool allowPartial) -> SolutionKind {
Type boundRoot, boundValue;
Expand Down Expand Up @@ -4238,7 +4239,7 @@ ConstraintSystem::simplifyKeyPathApplicationConstraint(
TypeMatchOptions flags,
ConstraintLocatorBuilder locator) {
TypeMatchOptions subflags = getDefaultDecompositionOptions(flags);
keyPathTy = getFixedTypeRecursive(keyPathTy, flags, /*wantRValue=*/true);
keyPathTy = resolveTypeVariable(keyPathTy, flags, /*wantRValue=*/true);

auto unsolved = [&]() -> SolutionKind {
if (flags.contains(TMF_GenerateConstraints)) {
Expand Down Expand Up @@ -4267,7 +4268,7 @@ ConstraintSystem::simplifyKeyPathApplicationConstraint(
auto kpRootTy = bgt->getGenericArgs()[0];

// Try to match the root type.
rootTy = getFixedTypeRecursive(rootTy, flags, /*wantRValue=*/false);
rootTy = resolveTypeVariable(rootTy, flags, /*wantRValue=*/false);

auto matchRoot = [&](ConstraintKind kind) -> bool {
auto rootMatches = matchTypes(rootTy, kpRootTy, kind,
Expand Down Expand Up @@ -4365,7 +4366,7 @@ ConstraintSystem::simplifyApplicableFnConstraint(
assert(type1->is<FunctionType>());

// Drill down to the concrete type on the right hand side.
type2 = getFixedTypeRecursive(type2, flags, /*wantRValue=*/true);
type2 = resolveTypeVariable(type2, flags, /*wantRValue=*/true);
auto desugar2 = type2->getDesugaredType();

TypeMatchOptions subflags = getDefaultDecompositionOptions(flags);
Expand Down Expand Up @@ -4452,7 +4453,7 @@ ConstraintSystem::simplifyApplicableFnConstraint(

// For a metatype, perform a construction.
if (auto meta2 = dyn_cast<AnyMetatypeType>(desugar2)) {
auto instance2 = getFixedTypeRecursive(meta2->getInstanceType(), true);
auto instance2 = resolveTypeVariable(meta2->getInstanceType(), true);
if (instance2->isTypeVariableOrMember())
return formUnsolved();

Expand Down Expand Up @@ -4668,11 +4669,11 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
// Unwrap an inout type.
auto obj1 = type1->getInOutObjectType();

obj1 = getFixedTypeRecursive(obj1, false, false);
obj1 = resolveTypeVariable(obj1, false, false);

auto t2 = type2->getDesugaredType();

auto baseType1 = getFixedTypeRecursive(*isArrayType(obj1), false, false);
auto baseType1 = resolveTypeVariable(*isArrayType(obj1), false, false);
auto baseType2 = getBaseTypeForPointer(*this, t2);

increaseScore(ScoreKind::SK_ValueToPointerConversion);
Expand All @@ -4691,7 +4692,7 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
// TODO: Handle different encodings based on pointer element type, such as
// UTF16 for [U]Int16 or UTF32 for [U]Int32. For now we only interop with
// Int8 pointers using UTF8 encoding.
baseType2 = getFixedTypeRecursive(baseType2, false, false);
baseType2 = resolveTypeVariable(baseType2, false, false);
// If we haven't resolved the element type, generate constraints.
if (baseType2->isTypeVariableOrMember()) {
if (flags.contains(TMF_GenerateConstraints)) {
Expand Down
Loading