Skip to content

Commit be6cf92

Browse files
committed
Sema: Plumb PreparedOverload through to replaceInferableTypesWithTypeVars()
1 parent ab72407 commit be6cf92

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4317,7 +4317,8 @@ class ConstraintSystem {
43174317
/// \returns The opened type.
43184318
Type openUnboundGenericType(GenericTypeDecl *decl, Type parentTy,
43194319
ConstraintLocatorBuilder locator,
4320-
bool isTypeResolution);
4320+
bool isTypeResolution,
4321+
PreparedOverload *preparedOverload = nullptr);
43214322

43224323
/// Replace placeholder types with fresh type variables, and unbound generic
43234324
/// types with bound generic types whose generic args are fresh type
@@ -4327,7 +4328,9 @@ class ConstraintSystem {
43274328
///
43284329
/// \returns The converted type.
43294330
Type replaceInferableTypesWithTypeVars(Type type,
4330-
ConstraintLocatorBuilder locator);
4331+
ConstraintLocatorBuilder locator,
4332+
PreparedOverload *preparedOverload
4333+
= nullptr);
43314334

43324335
/// "Open" the given type by replacing any occurrences of generic
43334336
/// parameter types and dependent member types with fresh type variables.

lib/Sema/TypeOfReference.cpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,20 @@ using namespace inference;
4545
Type ConstraintSystem::openUnboundGenericType(GenericTypeDecl *decl,
4646
Type parentTy,
4747
ConstraintLocatorBuilder locator,
48-
bool isTypeResolution) {
48+
bool isTypeResolution,
49+
PreparedOverload *preparedOverload) {
4950
if (parentTy) {
50-
parentTy = replaceInferableTypesWithTypeVars(parentTy, locator);
51+
parentTy = replaceInferableTypesWithTypeVars(
52+
parentTy, locator, preparedOverload);
5153
}
5254

5355
// Open up the generic type.
5456
SmallVector<OpenedType, 4> replacements;
5557
openGeneric(decl->getDeclContext(), decl->getGenericSignature(), locator,
56-
replacements, /*preparedOverload=*/nullptr);
58+
replacements, preparedOverload);
5759

5860
// FIXME: Get rid of fixmeAllowDuplicates.
59-
recordOpenedTypes(locator, replacements, /*preparedOverload=*/nullptr,
61+
recordOpenedTypes(locator, replacements, preparedOverload,
6062
/*fixmeAllowDuplicates=*/true);
6163

6264
if (parentTy) {
@@ -84,7 +86,7 @@ Type ConstraintSystem::openUnboundGenericType(GenericTypeDecl *decl,
8486
continue;
8587

8688
addConstraint(ConstraintKind::Bind, pair.second, found->second,
87-
locator);
89+
locator, /*isFavored=*/false, preparedOverload);
8890
}
8991
}
9092

@@ -197,34 +199,35 @@ static void checkNestedTypeConstraints(ConstraintSystem &cs, Type type,
197199
}
198200

199201
Type ConstraintSystem::replaceInferableTypesWithTypeVars(
200-
Type type, ConstraintLocatorBuilder locator) {
202+
Type type, ConstraintLocatorBuilder locator,
203+
PreparedOverload *preparedOverload) {
201204
if (!type->hasUnboundGenericType() && !type->hasPlaceholder())
202205
return type;
203206

207+
auto flags = TVO_CanBindToNoEscape | TVO_PrefersSubtypeBinding | TVO_CanBindToHole;
208+
204209
type = type.transformRec([&](Type type) -> std::optional<Type> {
205210
if (auto unbound = type->getAs<UnboundGenericType>()) {
206211
return openUnboundGenericType(unbound->getDecl(), unbound->getParent(),
207-
locator, /*isTypeResolution=*/false);
212+
locator, /*isTypeResolution=*/false,
213+
preparedOverload);
208214
} else if (auto *placeholderTy = type->getAs<PlaceholderType>()) {
209215
if (auto *typeRepr =
210216
placeholderTy->getOriginator().dyn_cast<TypeRepr *>()) {
211217
if (isa<PlaceholderTypeRepr>(typeRepr)) {
212-
return Type(createTypeVariable(
213-
getConstraintLocator(locator,
214-
LocatorPathElt::PlaceholderType(typeRepr)),
215-
TVO_CanBindToNoEscape | TVO_PrefersSubtypeBinding |
216-
TVO_CanBindToHole));
218+
return Type(
219+
createTypeVariable(
220+
getConstraintLocator(locator, LocatorPathElt::PlaceholderType(typeRepr)),
221+
flags, preparedOverload));
217222
}
218-
} else if (auto *var =
219-
placeholderTy->getOriginator().dyn_cast<VarDecl *>()) {
223+
} else if (auto *var = placeholderTy->getOriginator().dyn_cast<VarDecl *>()) {
220224
if (var->getName().hasDollarPrefix()) {
221225
auto *repr =
222226
new (type->getASTContext()) PlaceholderTypeRepr(var->getLoc());
223-
return Type(createTypeVariable(
224-
getConstraintLocator(locator,
225-
LocatorPathElt::PlaceholderType(repr)),
226-
TVO_CanBindToNoEscape | TVO_PrefersSubtypeBinding |
227-
TVO_CanBindToHole));
227+
return Type(
228+
createTypeVariable(
229+
getConstraintLocator(locator, LocatorPathElt::PlaceholderType(repr)),
230+
flags, preparedOverload));
228231
}
229232
}
230233
}
@@ -1085,7 +1088,7 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
10851088
checkNestedTypeConstraints(*this, type, locator, preparedOverload);
10861089

10871090
// Convert any placeholder types and open generics.
1088-
type = replaceInferableTypesWithTypeVars(type, locator);
1091+
type = replaceInferableTypesWithTypeVars(type, locator, preparedOverload);
10891092

10901093
// Module types are not wrapped in metatypes.
10911094
if (type->is<ModuleType>())
@@ -1629,7 +1632,8 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
16291632
checkNestedTypeConstraints(*this, memberTy, locator, preparedOverload);
16301633

16311634
// Convert any placeholders and open any generics.
1632-
memberTy = replaceInferableTypesWithTypeVars(memberTy, locator);
1635+
memberTy = replaceInferableTypesWithTypeVars(
1636+
memberTy, locator, preparedOverload);
16331637

16341638
// Wrap it in a metatype.
16351639
memberTy = MetatypeType::get(memberTy);

0 commit comments

Comments
 (0)