@@ -1587,21 +1587,16 @@ void ConstraintSystem::addOverloadSet(ArrayRef<Constraint *> choices,
1587
1587
}
1588
1588
1589
1589
// / 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) {
1602
1597
case DeclTypeCheckingSemantics::Normal:
1603
- return false ;
1604
-
1598
+ llvm_unreachable ( " Decl does not have special type checking semantics! " ) ;
1599
+
1605
1600
case DeclTypeCheckingSemantics::TypeOf: {
1606
1601
// Proceed with a "DynamicType" operation. This produces an existential
1607
1602
// metatype from existentials, or a concrete metatype from non-
@@ -1619,9 +1614,8 @@ resolveOverloadForDeclWithSpecialTypeCheckingSemantics(ConstraintSystem &CS,
1619
1614
1620
1615
CS.addConstraint (ConstraintKind::DynamicTypeOf, output, input,
1621
1616
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};
1625
1619
}
1626
1620
case DeclTypeCheckingSemantics::WithoutActuallyEscaping: {
1627
1621
// Proceed with a "WithoutActuallyEscaping" operation. The body closure
@@ -1649,14 +1643,14 @@ resolveOverloadForDeclWithSpecialTypeCheckingSemantics(ConstraintSystem &CS,
1649
1643
FunctionType::Param (noescapeClosure),
1650
1644
FunctionType::Param (bodyClosure, CS.getASTContext ().getIdentifier (" do" )),
1651
1645
};
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} ;
1660
1654
}
1661
1655
case DeclTypeCheckingSemantics::OpenExistential: {
1662
1656
// The body closure receives a freshly-opened archetype constrained by the
@@ -1683,13 +1677,13 @@ resolveOverloadForDeclWithSpecialTypeCheckingSemantics(ConstraintSystem &CS,
1683
1677
FunctionType::Param (existentialTy),
1684
1678
FunctionType::Param (bodyClosure, CS.getASTContext ().getIdentifier (" do" )),
1685
1679
};
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} ;
1693
1687
}
1694
1688
}
1695
1689
@@ -1799,21 +1793,25 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
1799
1793
1800
1794
switch (auto kind = choice.getKind ()) {
1801
1795
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
-
1810
1796
case OverloadChoiceKind::DeclViaBridge:
1811
1797
case OverloadChoiceKind::DeclViaDynamic:
1812
1798
case OverloadChoiceKind::DeclViaUnwrappedOptional:
1813
1799
case OverloadChoiceKind::DynamicMemberLookup:
1814
1800
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.
1817
1815
assert (!baseTy->hasTypeParameter ());
1818
1816
1819
1817
auto getDotBase = [](const Expr *E) -> const DeclRefExpr * {
0 commit comments