Skip to content

Commit f6fff1b

Browse files
committed
Sema: Split off openFunctionType() from openType()
- Change openGeneric() to take two DeclContexts, one is the generic context for the signature and the second is the generic context containing the declaration being opened - This allows us to clean up the logic around skipProtocolSelfRequirement; instead of testing both the DeclContext and its parent, we know exactly what DeclContext to test. Also, use the right Self type here, instead of always using (0, 0) - Now that we have the right DeclContexts handy, we can move the getGenericTypeContextDepth() call into openGeneric(), simplifying callers - Now that openType() no longer opens generic signatures, it takes fewer parameters
1 parent 4446bc0 commit f6fff1b

File tree

4 files changed

+157
-155
lines changed

4 files changed

+157
-155
lines changed

lib/Sema/CSRanking.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,8 @@ static bool isProtocolExtensionAsSpecializedAs(TypeChecker &tc,
450450
// the second protocol extension.
451451
ConstraintSystem cs(tc, dc1, None);
452452
llvm::DenseMap<CanType, TypeVariableType *> replacements;
453-
cs.openGeneric(dc2, sig2, false, dc2->getGenericTypeContextDepth(),
453+
cs.openGeneric(dc2, dc2, sig2,
454+
/*skipProtocolSelfConstraint=*/false,
454455
ConstraintLocatorBuilder(nullptr),
455456
replacements);
456457

@@ -571,14 +572,35 @@ static bool isDeclAsSpecializedAs(TypeChecker &tc, DeclContext *dc,
571572
auto locator = cs.getConstraintLocator(nullptr);
572573
// FIXME: Locator when anchored on a declaration.
573574
// Get the type of a reference to the second declaration.
574-
Type openedType2 = cs.openType(type2, locator,
575-
decl2->getInnermostDeclContext());
575+
llvm::DenseMap<CanType, TypeVariableType *> unused;
576+
Type openedType2;
577+
if (auto *funcType = type2->getAs<AnyFunctionType>()) {
578+
openedType2 = cs.openFunctionType(
579+
funcType, locator,
580+
/*replacements=*/unused,
581+
decl2->getInnermostDeclContext(),
582+
decl2->getDeclContext(),
583+
/*skipProtocolSelfConstraint=*/false);
584+
} else {
585+
openedType2 = cs.openType(type2, locator, unused);
586+
}
576587

577588
// Get the type of a reference to the first declaration, swapping in
578589
// archetypes for the dependent types.
579590
llvm::DenseMap<CanType, TypeVariableType *> replacements;
580591
auto dc1 = decl1->getInnermostDeclContext();
581-
Type openedType1 = cs.openType(type1, locator, replacements, dc1);
592+
Type openedType1;
593+
if (auto *funcType = type1->getAs<AnyFunctionType>()) {
594+
openedType1 = cs.openFunctionType(
595+
funcType, locator,
596+
replacements,
597+
dc1,
598+
decl1->getDeclContext(),
599+
/*skipProtocolSelfConstraint=*/false);
600+
} else {
601+
openedType1 = cs.openType(type1, locator, replacements);
602+
}
603+
582604
for (const auto &replacement : replacements) {
583605
if (auto mapped =
584606
ArchetypeBuilder::mapTypeIntoContext(dc1,

0 commit comments

Comments
 (0)