@@ -2625,7 +2625,7 @@ isInvalidPartialApplication(ConstraintSystem &cs,
2625
2625
// / checking semantics, compute the type of the reference. For now, follow
2626
2626
// / the lead of \c getTypeOfMemberReference and return a pair of
2627
2627
// / the full opened type and the reference's type.
2628
- static DeclReferenceType getTypeOfReferenceWithSpecialTypeCheckingSemantics (
2628
+ static Type getTypeOfReferenceWithSpecialTypeCheckingSemantics (
2629
2629
ConstraintSystem &CS, ConstraintLocator *locator,
2630
2630
DeclTypeCheckingSemantics semantics,
2631
2631
PreparedOverloadBuilder *preparedOverload) {
@@ -2654,8 +2654,7 @@ static DeclReferenceType getTypeOfReferenceWithSpecialTypeCheckingSemantics(
2654
2654
/* isFavored=*/ false , preparedOverload);
2655
2655
// FIXME: Verify ExtInfo state is correct, not working by accident.
2656
2656
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);
2659
2658
}
2660
2659
case DeclTypeCheckingSemantics::WithoutActuallyEscaping: {
2661
2660
// Proceed with a "WithoutActuallyEscaping" operation. The body closure
@@ -2702,14 +2701,13 @@ static DeclReferenceType getTypeOfReferenceWithSpecialTypeCheckingSemantics(
2702
2701
withoutEscapingIsolation = FunctionTypeIsolation::forNonIsolatedCaller ();
2703
2702
}
2704
2703
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 ());
2713
2711
}
2714
2712
case DeclTypeCheckingSemantics::OpenExistential: {
2715
2713
// The body closure receives a freshly-opened archetype constrained by the
@@ -2755,14 +2753,13 @@ static DeclReferenceType getTypeOfReferenceWithSpecialTypeCheckingSemantics(
2755
2753
openExistentialIsolation = FunctionTypeIsolation::forNonIsolatedCaller ();
2756
2754
}
2757
2755
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 ());
2766
2763
}
2767
2764
}
2768
2765
@@ -2840,9 +2837,11 @@ void ConstraintSystem::replayChanges(
2840
2837
// / that are to be introduced into the constraint system when this choice
2841
2838
// / is taken.
2842
2839
// /
2840
+ // / Returns a pair consisting of the opened type, and the thrown error type.
2841
+ // /
2843
2842
// / FIXME: As a transitional mechanism, if preparedOverload is nullptr, this
2844
2843
// / immediately performs all operations.
2845
- DeclReferenceType
2844
+ std::pair<Type, Type>
2846
2845
ConstraintSystem::prepareOverloadImpl (OverloadChoice choice,
2847
2846
DeclContext *useDC,
2848
2847
ConstraintLocator *locator,
@@ -2852,20 +2851,21 @@ ConstraintSystem::prepareOverloadImpl(OverloadChoice choice,
2852
2851
auto semantics =
2853
2852
TypeChecker::getDeclTypeCheckingSemantics (choice.getDecl ());
2854
2853
if (semantics != DeclTypeCheckingSemantics::Normal) {
2855
- return getTypeOfReferenceWithSpecialTypeCheckingSemantics (
2854
+ auto openedType = getTypeOfReferenceWithSpecialTypeCheckingSemantics (
2856
2855
*this , locator, semantics, preparedOverload);
2856
+ return {openedType, Type ()};
2857
2857
} else if (auto baseTy = choice.getBaseType ()) {
2858
2858
// Retrieve the type of a reference to the specific declaration choice.
2859
2859
assert (!baseTy->hasTypeParameter ());
2860
2860
2861
2861
// If the base is a module type, it's an unqualified reference.
2862
2862
if (baseTy->getMetatypeInstanceType ()->is <ModuleType>()) {
2863
- return getTypeOfReference (choice, useDC, locator, preparedOverload);
2863
+ return getTypeOfReferencePre (choice, useDC, locator, preparedOverload);
2864
2864
}
2865
2865
2866
- return getTypeOfMemberReference (choice, useDC, locator, preparedOverload);
2866
+ return getTypeOfMemberReferencePre (choice, useDC, locator, preparedOverload);
2867
2867
} else {
2868
- return getTypeOfReference (choice, useDC, locator, preparedOverload);
2868
+ return getTypeOfReferencePre (choice, useDC, locator, preparedOverload);
2869
2869
}
2870
2870
}
2871
2871
@@ -2876,15 +2876,18 @@ PreparedOverload *ConstraintSystem::prepareOverload(OverloadChoice choice,
2876
2876
PreparingOverload = true ;
2877
2877
2878
2878
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);
2880
2883
2881
2884
PreparingOverload = false ;
2882
2885
2883
2886
size_t count = builder.Changes .size ();
2884
2887
auto size = PreparedOverload::totalSizeToAlloc<PreparedOverload::Change>(count);
2885
2888
auto mem = Allocator.Allocate (size, alignof (PreparedOverload));
2886
2889
2887
- return new (mem) PreparedOverload (declRefType , builder.Changes );
2890
+ return new (mem) PreparedOverload (openedType, thrownErrorType , builder.Changes );
2888
2891
}
2889
2892
2890
2893
void ConstraintSystem::resolveOverload (OverloadChoice choice, DeclContext *useDC,
@@ -2895,7 +2898,7 @@ void ConstraintSystem::resolveOverload(OverloadChoice choice, DeclContext *useDC
2895
2898
Type adjustedOpenedType;
2896
2899
Type refType;
2897
2900
Type adjustedRefType;
2898
- Type thrownErrorTypeOnAccess ;
2901
+ Type thrownErrorType ;
2899
2902
2900
2903
switch (choice.getKind ()) {
2901
2904
case OverloadChoiceKind::Decl:
@@ -2908,18 +2911,40 @@ void ConstraintSystem::resolveOverload(OverloadChoice choice, DeclContext *useDC
2908
2911
replayChanges (locator, preparedOverload);
2909
2912
2910
2913
openedType = preparedOverload->getOpenedType ();
2911
- adjustedOpenedType = preparedOverload->getAdjustedOpenedType ();
2912
- refType = preparedOverload->getReferenceType ();
2913
- adjustedRefType = preparedOverload->getAdjustedReferenceType ();
2914
- thrownErrorTypeOnAccess = preparedOverload->getThrownErrorTypeOnAccess ();
2914
+ thrownErrorType = preparedOverload->getThrownErrorType ();
2915
2915
} 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
+ }
2917
2942
2918
2943
openedType = declRefType.openedType ;
2919
2944
adjustedOpenedType = declRefType.adjustedOpenedType ;
2920
2945
refType = declRefType.referenceType ;
2921
2946
adjustedRefType = declRefType.adjustedReferenceType ;
2922
- thrownErrorTypeOnAccess = declRefType.thrownErrorTypeOnAccess ;
2947
+ thrownErrorType = declRefType.thrownErrorTypeOnAccess ;
2923
2948
}
2924
2949
2925
2950
break ;
@@ -3110,9 +3135,9 @@ void ConstraintSystem::resolveOverload(OverloadChoice choice, DeclContext *useDC
3110
3135
3111
3136
// If accessing this declaration could throw an error, record this as a
3112
3137
// potential throw site.
3113
- if (thrownErrorTypeOnAccess ) {
3138
+ if (thrownErrorType ) {
3114
3139
recordPotentialThrowSite (
3115
- PotentialThrowSite::PropertyAccess, thrownErrorTypeOnAccess , locator);
3140
+ PotentialThrowSite::PropertyAccess, thrownErrorType , locator);
3116
3141
}
3117
3142
3118
3143
// Note that we have resolved this overload.
0 commit comments