Skip to content

Commit d772338

Browse files
committed
Refactor resolveOverloadForDeclWithSpecialTypeCheckingSemantics
Have it function more like getTypeOfMemberReference and clean up its caller a bit
1 parent 1ca57e0 commit d772338

File tree

1 file changed

+40
-42
lines changed

1 file changed

+40
-42
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,21 +1587,16 @@ void ConstraintSystem::addOverloadSet(ArrayRef<Constraint *> choices,
15871587
}
15881588

15891589
/// If we're resolving an overload set with a decl that has special type
1590-
/// checking semantics, set up the special-case type system and return true;
1591-
/// otherwise return false.
1592-
static bool
1593-
resolveOverloadForDeclWithSpecialTypeCheckingSemantics(ConstraintSystem &CS,
1594-
ConstraintLocator *locator,
1595-
Type boundType,
1596-
OverloadChoice choice,
1597-
Type &refType,
1598-
Type &openedFullType) {
1599-
assert(choice.getKind() == OverloadChoiceKind::Decl);
1600-
1601-
switch (TypeChecker::getDeclTypeCheckingSemantics(choice.getDecl())) {
1590+
/// checking semantics, compute the type of the reference. For now, follow
1591+
/// the lead of \c getTypeOfMemberReference and return a pair of
1592+
/// the full opened type and the reference's type.
1593+
static std::pair<Type, Type> getTypeOfReferenceWithSpecialTypeCheckingSemantics(
1594+
ConstraintSystem &CS, ConstraintLocator *locator,
1595+
DeclTypeCheckingSemantics sema) {
1596+
switch (sema) {
16021597
case DeclTypeCheckingSemantics::Normal:
1603-
return false;
1604-
1598+
llvm_unreachable("Decl does not have special type checking semantics!");
1599+
16051600
case DeclTypeCheckingSemantics::TypeOf: {
16061601
// Proceed with a "DynamicType" operation. This produces an existential
16071602
// metatype from existentials, or a concrete metatype from non-
@@ -1619,9 +1614,8 @@ resolveOverloadForDeclWithSpecialTypeCheckingSemantics(ConstraintSystem &CS,
16191614

16201615
CS.addConstraint(ConstraintKind::DynamicTypeOf, output, input,
16211616
CS.getConstraintLocator(locator, ConstraintLocator::RValueAdjustment));
1622-
refType = FunctionType::get({inputArg}, output);
1623-
openedFullType = refType;
1624-
return true;
1617+
auto refType = FunctionType::get({inputArg}, output);
1618+
return {refType, refType};
16251619
}
16261620
case DeclTypeCheckingSemantics::WithoutActuallyEscaping: {
16271621
// Proceed with a "WithoutActuallyEscaping" operation. The body closure
@@ -1649,14 +1643,14 @@ resolveOverloadForDeclWithSpecialTypeCheckingSemantics(ConstraintSystem &CS,
16491643
FunctionType::Param(noescapeClosure),
16501644
FunctionType::Param(bodyClosure, CS.getASTContext().getIdentifier("do")),
16511645
};
1652-
1653-
refType = FunctionType::get(args, result,
1654-
FunctionType::ExtInfo(FunctionType::Representation::Swift,
1655-
/*noescape*/ false,
1656-
/*throws*/ true,
1657-
DifferentiabilityKind::NonDifferentiable));
1658-
openedFullType = refType;
1659-
return true;
1646+
1647+
auto refType = FunctionType::get(
1648+
args, result,
1649+
FunctionType::ExtInfo(FunctionType::Representation::Swift,
1650+
/*noescape*/ false,
1651+
/*throws*/ true,
1652+
DifferentiabilityKind::NonDifferentiable));
1653+
return {refType, refType};
16601654
}
16611655
case DeclTypeCheckingSemantics::OpenExistential: {
16621656
// The body closure receives a freshly-opened archetype constrained by the
@@ -1683,13 +1677,13 @@ resolveOverloadForDeclWithSpecialTypeCheckingSemantics(ConstraintSystem &CS,
16831677
FunctionType::Param(existentialTy),
16841678
FunctionType::Param(bodyClosure, CS.getASTContext().getIdentifier("do")),
16851679
};
1686-
refType = FunctionType::get(args, result,
1687-
FunctionType::ExtInfo(FunctionType::Representation::Swift,
1688-
/*noescape*/ false,
1689-
/*throws*/ true,
1690-
DifferentiabilityKind::NonDifferentiable));
1691-
openedFullType = refType;
1692-
return true;
1680+
auto refType = FunctionType::get(
1681+
args, result,
1682+
FunctionType::ExtInfo(FunctionType::Representation::Swift,
1683+
/*noescape*/ false,
1684+
/*throws*/ true,
1685+
DifferentiabilityKind::NonDifferentiable));
1686+
return {refType, refType};
16931687
}
16941688
}
16951689

@@ -1799,21 +1793,25 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
17991793

18001794
switch (auto kind = choice.getKind()) {
18011795
case OverloadChoiceKind::Decl:
1802-
// If we refer to a top-level decl with special type-checking semantics,
1803-
// handle it now.
1804-
if (resolveOverloadForDeclWithSpecialTypeCheckingSemantics(
1805-
*this, locator, boundType, choice, refType, openedFullType))
1806-
break;
1807-
1808-
LLVM_FALLTHROUGH;
1809-
18101796
case OverloadChoiceKind::DeclViaBridge:
18111797
case OverloadChoiceKind::DeclViaDynamic:
18121798
case OverloadChoiceKind::DeclViaUnwrappedOptional:
18131799
case OverloadChoiceKind::DynamicMemberLookup:
18141800
case OverloadChoiceKind::KeyPathDynamicMemberLookup: {
1815-
// Retrieve the type of a reference to the specific declaration choice.
1816-
if (auto baseTy = choice.getBaseType()) {
1801+
// If we refer to a top-level decl with special type-checking semantics,
1802+
// handle it now.
1803+
const auto semantics =
1804+
TypeChecker::getDeclTypeCheckingSemantics(choice.getDecl());
1805+
if (semantics != DeclTypeCheckingSemantics::Normal) {
1806+
std::tie(openedFullType, refType) =
1807+
getTypeOfReferenceWithSpecialTypeCheckingSemantics(*this, locator,
1808+
semantics);
1809+
// Declarations with special type checking semantics do not require
1810+
// any further adjustments to the constraint system. Break out of
1811+
// here so we don't do any more work.
1812+
break;
1813+
} else if (auto baseTy = choice.getBaseType()) {
1814+
// Retrieve the type of a reference to the specific declaration choice.
18171815
assert(!baseTy->hasTypeParameter());
18181816

18191817
auto getDotBase = [](const Expr *E) -> const DeclRefExpr * {

0 commit comments

Comments
 (0)