@@ -2625,7 +2625,7 @@ isInvalidPartialApplication(ConstraintSystem &cs,
26252625// / checking semantics, compute the type of the reference. For now, follow
26262626// / the lead of \c getTypeOfMemberReference and return a pair of
26272627// / the full opened type and the reference's type.
2628- static DeclReferenceType getTypeOfReferenceWithSpecialTypeCheckingSemantics (
2628+ static Type getTypeOfReferenceWithSpecialTypeCheckingSemantics (
26292629 ConstraintSystem &CS, ConstraintLocator *locator,
26302630 DeclTypeCheckingSemantics semantics,
26312631 PreparedOverloadBuilder *preparedOverload) {
@@ -2654,8 +2654,7 @@ static DeclReferenceType getTypeOfReferenceWithSpecialTypeCheckingSemantics(
26542654 /* isFavored=*/ false , preparedOverload);
26552655 // FIXME: Verify ExtInfo state is correct, not working by accident.
26562656 FunctionType::ExtInfo info;
2657- auto refType = FunctionType::get ({inputArg}, output, info);
2658- return {refType, refType, refType, refType, Type ()};
2657+ return FunctionType::get ({inputArg}, output, info);
26592658 }
26602659 case DeclTypeCheckingSemantics::WithoutActuallyEscaping: {
26612660 // Proceed with a "WithoutActuallyEscaping" operation. The body closure
@@ -2702,14 +2701,13 @@ static DeclReferenceType getTypeOfReferenceWithSpecialTypeCheckingSemantics(
27022701 withoutEscapingIsolation = FunctionTypeIsolation::forNonIsolatedCaller ();
27032702 }
27042703
2705- auto refType = FunctionType::get (args, result,
2706- FunctionType::ExtInfoBuilder ()
2707- .withNoEscape (false )
2708- .withIsolation (withoutEscapingIsolation)
2709- .withAsync (true )
2710- .withThrows (true , thrownError)
2711- .build ());
2712- return {refType, refType, refType, refType, Type ()};
2704+ return FunctionType::get (args, result,
2705+ FunctionType::ExtInfoBuilder ()
2706+ .withNoEscape (false )
2707+ .withIsolation (withoutEscapingIsolation)
2708+ .withAsync (true )
2709+ .withThrows (true , thrownError)
2710+ .build ());
27132711 }
27142712 case DeclTypeCheckingSemantics::OpenExistential: {
27152713 // The body closure receives a freshly-opened archetype constrained by the
@@ -2755,14 +2753,13 @@ static DeclReferenceType getTypeOfReferenceWithSpecialTypeCheckingSemantics(
27552753 openExistentialIsolation = FunctionTypeIsolation::forNonIsolatedCaller ();
27562754 }
27572755
2758- auto refType = FunctionType::get (args, result,
2759- FunctionType::ExtInfoBuilder ()
2760- .withNoEscape (false )
2761- .withThrows (true , thrownError)
2762- .withIsolation (openExistentialIsolation)
2763- .withAsync (true )
2764- .build ());
2765- return {refType, refType, refType, refType, Type ()};
2756+ return FunctionType::get (args, result,
2757+ FunctionType::ExtInfoBuilder ()
2758+ .withNoEscape (false )
2759+ .withThrows (true , thrownError)
2760+ .withIsolation (openExistentialIsolation)
2761+ .withAsync (true )
2762+ .build ());
27662763 }
27672764 }
27682765
@@ -2840,9 +2837,11 @@ void ConstraintSystem::replayChanges(
28402837// / that are to be introduced into the constraint system when this choice
28412838// / is taken.
28422839// /
2840+ // / Returns a pair consisting of the opened type, and the thrown error type.
2841+ // /
28432842// / FIXME: As a transitional mechanism, if preparedOverload is nullptr, this
28442843// / immediately performs all operations.
2845- DeclReferenceType
2844+ std::pair<Type, Type>
28462845ConstraintSystem::prepareOverloadImpl (OverloadChoice choice,
28472846 DeclContext *useDC,
28482847 ConstraintLocator *locator,
@@ -2852,20 +2851,21 @@ ConstraintSystem::prepareOverloadImpl(OverloadChoice choice,
28522851 auto semantics =
28532852 TypeChecker::getDeclTypeCheckingSemantics (choice.getDecl ());
28542853 if (semantics != DeclTypeCheckingSemantics::Normal) {
2855- return getTypeOfReferenceWithSpecialTypeCheckingSemantics (
2854+ auto openedType = getTypeOfReferenceWithSpecialTypeCheckingSemantics (
28562855 *this , locator, semantics, preparedOverload);
2856+ return {openedType, Type ()};
28572857 } else if (auto baseTy = choice.getBaseType ()) {
28582858 // Retrieve the type of a reference to the specific declaration choice.
28592859 assert (!baseTy->hasTypeParameter ());
28602860
28612861 // If the base is a module type, it's an unqualified reference.
28622862 if (baseTy->getMetatypeInstanceType ()->is <ModuleType>()) {
2863- return getTypeOfReference (choice, useDC, locator, preparedOverload);
2863+ return getTypeOfReferencePre (choice, useDC, locator, preparedOverload);
28642864 }
28652865
2866- return getTypeOfMemberReference (choice, useDC, locator, preparedOverload);
2866+ return getTypeOfMemberReferencePre (choice, useDC, locator, preparedOverload);
28672867 } else {
2868- return getTypeOfReference (choice, useDC, locator, preparedOverload);
2868+ return getTypeOfReferencePre (choice, useDC, locator, preparedOverload);
28692869 }
28702870}
28712871
@@ -2876,15 +2876,18 @@ PreparedOverload *ConstraintSystem::prepareOverload(OverloadChoice choice,
28762876 PreparingOverload = true ;
28772877
28782878 PreparedOverloadBuilder builder;
2879- auto declRefType = prepareOverloadImpl (choice, useDC, locator, &builder);
2879+ Type openedType;
2880+ Type thrownErrorType;
2881+ std::tie (openedType, thrownErrorType) = prepareOverloadImpl (
2882+ choice, useDC, locator, &builder);
28802883
28812884 PreparingOverload = false ;
28822885
28832886 size_t count = builder.Changes .size ();
28842887 auto size = PreparedOverload::totalSizeToAlloc<PreparedOverload::Change>(count);
28852888 auto mem = Allocator.Allocate (size, alignof (PreparedOverload));
28862889
2887- return new (mem) PreparedOverload (declRefType , builder.Changes );
2890+ return new (mem) PreparedOverload (openedType, thrownErrorType , builder.Changes );
28882891}
28892892
28902893void ConstraintSystem::resolveOverload (OverloadChoice choice, DeclContext *useDC,
@@ -2895,7 +2898,7 @@ void ConstraintSystem::resolveOverload(OverloadChoice choice, DeclContext *useDC
28952898 Type adjustedOpenedType;
28962899 Type refType;
28972900 Type adjustedRefType;
2898- Type thrownErrorTypeOnAccess ;
2901+ Type thrownErrorType ;
28992902
29002903 switch (choice.getKind ()) {
29012904 case OverloadChoiceKind::Decl:
@@ -2908,18 +2911,40 @@ void ConstraintSystem::resolveOverload(OverloadChoice choice, DeclContext *useDC
29082911 replayChanges (locator, preparedOverload);
29092912
29102913 openedType = preparedOverload->getOpenedType ();
2911- adjustedOpenedType = preparedOverload->getAdjustedOpenedType ();
2912- refType = preparedOverload->getReferenceType ();
2913- adjustedRefType = preparedOverload->getAdjustedReferenceType ();
2914- thrownErrorTypeOnAccess = preparedOverload->getThrownErrorTypeOnAccess ();
2914+ thrownErrorType = preparedOverload->getThrownErrorType ();
29152915 } else {
2916- auto declRefType = prepareOverloadImpl (choice, useDC, locator, nullptr );
2916+ std::tie (openedType, thrownErrorType) = prepareOverloadImpl (
2917+ choice, useDC, locator, nullptr );
2918+ }
2919+
2920+ auto semantics =
2921+ TypeChecker::getDeclTypeCheckingSemantics (choice.getDecl ());
2922+ if (semantics != DeclTypeCheckingSemantics::Normal) {
2923+ adjustedOpenedType = openedType;
2924+ refType = openedType;
2925+ adjustedRefType = openedType;
2926+ } else {
2927+ DeclReferenceType declRefType;
2928+
2929+ if (auto baseTy = choice.getBaseType ()) {
2930+ // If the base is a module type, it's an unqualified reference.
2931+ if (baseTy->getMetatypeInstanceType ()->is <ModuleType>()) {
2932+ declRefType = getTypeOfReferencePost (
2933+ choice, useDC, locator, openedType, thrownErrorType);
2934+ } else {
2935+ declRefType = getTypeOfMemberReferencePost (
2936+ choice, useDC, locator, openedType, thrownErrorType);
2937+ }
2938+ } else {
2939+ declRefType = getTypeOfReferencePost (
2940+ choice, useDC, locator, openedType, thrownErrorType);
2941+ }
29172942
29182943 openedType = declRefType.openedType ;
29192944 adjustedOpenedType = declRefType.adjustedOpenedType ;
29202945 refType = declRefType.referenceType ;
29212946 adjustedRefType = declRefType.adjustedReferenceType ;
2922- thrownErrorTypeOnAccess = declRefType.thrownErrorTypeOnAccess ;
2947+ thrownErrorType = declRefType.thrownErrorTypeOnAccess ;
29232948 }
29242949
29252950 break ;
@@ -3110,9 +3135,9 @@ void ConstraintSystem::resolveOverload(OverloadChoice choice, DeclContext *useDC
31103135
31113136 // If accessing this declaration could throw an error, record this as a
31123137 // potential throw site.
3113- if (thrownErrorTypeOnAccess ) {
3138+ if (thrownErrorType ) {
31143139 recordPotentialThrowSite (
3115- PotentialThrowSite::PropertyAccess, thrownErrorTypeOnAccess , locator);
3140+ PotentialThrowSite::PropertyAccess, thrownErrorType , locator);
31163141 }
31173142
31183143 // Note that we have resolved this overload.
0 commit comments