@@ -2891,11 +2891,7 @@ void ConstraintSystem::resolveOverload(OverloadChoice choice, DeclContext *useDC
2891
2891
ConstraintLocator *locator, Type boundType,
2892
2892
PreparedOverload *preparedOverload) {
2893
2893
// Determine the type to which we'll bind the overload set's type.
2894
- Type openedType;
2895
- Type adjustedOpenedType;
2896
- Type refType;
2897
- Type adjustedRefType;
2898
- Type thrownErrorType;
2894
+ DeclReferenceType declRefType;
2899
2895
2900
2896
switch (choice.getKind ()) {
2901
2897
case OverloadChoiceKind::Decl:
@@ -2904,6 +2900,8 @@ void ConstraintSystem::resolveOverload(OverloadChoice choice, DeclContext *useDC
2904
2900
case OverloadChoiceKind::DeclViaUnwrappedOptional:
2905
2901
case OverloadChoiceKind::DynamicMemberLookup:
2906
2902
case OverloadChoiceKind::KeyPathDynamicMemberLookup: {
2903
+ Type openedType, thrownErrorType;
2904
+
2907
2905
if (preparedOverload) {
2908
2906
replayChanges (locator, preparedOverload);
2909
2907
@@ -2917,25 +2915,19 @@ void ConstraintSystem::resolveOverload(OverloadChoice choice, DeclContext *useDC
2917
2915
auto semantics =
2918
2916
TypeChecker::getDeclTypeCheckingSemantics (choice.getDecl ());
2919
2917
if (semantics != DeclTypeCheckingSemantics::Normal) {
2920
- adjustedOpenedType = openedType;
2921
- refType = openedType;
2922
- adjustedRefType = openedType;
2918
+ declRefType.openedType = openedType;
2919
+ declRefType.adjustedOpenedType = openedType;
2920
+ declRefType.referenceType = openedType;
2921
+ declRefType.adjustedReferenceType = openedType;
2922
+ declRefType.thrownErrorTypeOnAccess = thrownErrorType;
2923
2923
} else {
2924
- DeclReferenceType declRefType;
2925
-
2926
2924
if (choice.getBaseType ()) {
2927
2925
declRefType = getTypeOfMemberReferencePost (
2928
2926
choice, useDC, locator, openedType, thrownErrorType);
2929
2927
} else {
2930
2928
declRefType = getTypeOfReferencePost (
2931
2929
choice, useDC, locator, openedType, thrownErrorType);
2932
2930
}
2933
-
2934
- openedType = declRefType.openedType ;
2935
- adjustedOpenedType = declRefType.adjustedOpenedType ;
2936
- refType = declRefType.referenceType ;
2937
- adjustedRefType = declRefType.adjustedReferenceType ;
2938
- thrownErrorType = declRefType.thrownErrorTypeOnAccess ;
2939
2931
}
2940
2932
2941
2933
break ;
@@ -2945,14 +2937,16 @@ void ConstraintSystem::resolveOverload(OverloadChoice choice, DeclContext *useDC
2945
2937
if (auto lvalueTy = choice.getBaseType ()->getAs <LValueType>()) {
2946
2938
// When the base of a tuple lvalue, the member is always an lvalue.
2947
2939
auto tuple = lvalueTy->getObjectType ()->castTo <TupleType>();
2948
- adjustedRefType = tuple->getElementType (choice.getTupleIndex ())->getRValueType ();
2949
- adjustedRefType = LValueType::get (adjustedRefType);
2940
+ declRefType.adjustedReferenceType =
2941
+ LValueType::get (
2942
+ tuple->getElementType (choice.getTupleIndex ())->getRValueType ());
2950
2943
} else {
2951
2944
// When the base is a tuple rvalue, the member is always an rvalue.
2952
2945
auto tuple = choice.getBaseType ()->castTo <TupleType>();
2953
- adjustedRefType = tuple->getElementType (choice.getTupleIndex ())->getRValueType ();
2946
+ declRefType.adjustedReferenceType =
2947
+ tuple->getElementType (choice.getTupleIndex ())->getRValueType ();
2954
2948
}
2955
- refType = adjustedRefType ;
2949
+ declRefType. referenceType = declRefType. adjustedReferenceType ;
2956
2950
break ;
2957
2951
2958
2952
case OverloadChoiceKind::MaterializePack: {
@@ -2962,18 +2956,18 @@ void ConstraintSystem::resolveOverload(OverloadChoice choice, DeclContext *useDC
2962
2956
// In the future, _if_ the syntax allows for multiple expansions
2963
2957
// this code would have to be adjusted to project l-value from the
2964
2958
// base type just like TupleIndex does.
2965
- adjustedRefType =
2959
+ declRefType. adjustedReferenceType =
2966
2960
getPatternTypeOfSingleUnlabeledPackExpansionTuple (choice.getBaseType ());
2967
- refType = adjustedRefType ;
2961
+ declRefType. referenceType = declRefType. adjustedReferenceType ;
2968
2962
break ;
2969
2963
}
2970
2964
2971
2965
case OverloadChoiceKind::ExtractFunctionIsolation: {
2972
2966
// The type of `.isolation` is `(any Actor)?`
2973
2967
auto actor = getASTContext ().getProtocol (KnownProtocolKind::Actor);
2974
- adjustedRefType =
2968
+ declRefType. adjustedReferenceType =
2975
2969
OptionalType::get (actor->getDeclaredExistentialType ());
2976
- refType = adjustedRefType ;
2970
+ declRefType. referenceType = declRefType. adjustedReferenceType ;
2977
2971
break ;
2978
2972
}
2979
2973
@@ -3004,11 +2998,11 @@ void ConstraintSystem::resolveOverload(OverloadChoice choice, DeclContext *useDC
3004
2998
// FIXME: Verify ExtInfo state is correct, not working by accident.
3005
2999
FunctionType::ExtInfo fullInfo;
3006
3000
auto fullTy = FunctionType::get ({baseParam}, subscriptTy, fullInfo);
3007
- openedType = fullTy;
3008
- adjustedOpenedType = fullTy;
3001
+ declRefType. openedType = fullTy;
3002
+ declRefType. adjustedOpenedType = fullTy;
3009
3003
// FIXME: @preconcurrency
3010
- refType = subscriptTy;
3011
- adjustedRefType = subscriptTy;
3004
+ declRefType. referenceType = subscriptTy;
3005
+ declRefType. adjustedReferenceType = subscriptTy;
3012
3006
3013
3007
// Increase the score so that actual subscripts get preference.
3014
3008
// ...except if we're solving for code completion and the index expression
@@ -3021,8 +3015,9 @@ void ConstraintSystem::resolveOverload(OverloadChoice choice, DeclContext *useDC
3021
3015
break ;
3022
3016
}
3023
3017
}
3024
- assert (!refType->hasTypeParameter () && " Cannot have a dependent type here" );
3025
- assert (!adjustedRefType->hasTypeParameter () &&
3018
+ assert (!declRefType.referenceType ->hasTypeParameter () &&
3019
+ " Cannot have a dependent type here" );
3020
+ assert (!declRefType.adjustedReferenceType ->hasTypeParameter () &&
3026
3021
" Cannot have a dependent type here" );
3027
3022
3028
3023
if (auto *decl = choice.getDeclOrNull ()) {
@@ -3042,7 +3037,7 @@ void ConstraintSystem::resolveOverload(OverloadChoice choice, DeclContext *useDC
3042
3037
if (locator->isResultOfKeyPathDynamicMemberLookup () ||
3043
3038
locator->isKeyPathSubscriptComponent ()) {
3044
3039
// Subscript type has a format of (Self[.Type) -> (Arg...) -> Result
3045
- auto declTy = adjustedOpenedType->castTo <FunctionType>();
3040
+ auto declTy = declRefType. adjustedOpenedType ->castTo <FunctionType>();
3046
3041
auto subscriptTy = declTy->getResult ()->castTo <FunctionType>();
3047
3042
// If we have subscript, each of the arguments has to conform to
3048
3043
// Hashable, because it would be used as a component inside key path.
@@ -3114,7 +3109,7 @@ void ConstraintSystem::resolveOverload(OverloadChoice choice, DeclContext *useDC
3114
3109
3115
3110
// The default type of the #isolation builtin macro is `(any Actor)?`
3116
3111
if (macro->getBuiltinKind () == BuiltinMacroKind::IsolationMacro) {
3117
- auto *fnType = openedType->getAs <FunctionType>();
3112
+ auto *fnType = declRefType. openedType ->getAs <FunctionType>();
3118
3113
auto actor = getASTContext ().getProtocol (KnownProtocolKind::Actor);
3119
3114
addConstraint (
3120
3115
ConstraintKind::Defaultable, fnType->getResult (),
@@ -3126,14 +3121,20 @@ void ConstraintSystem::resolveOverload(OverloadChoice choice, DeclContext *useDC
3126
3121
3127
3122
// If accessing this declaration could throw an error, record this as a
3128
3123
// potential throw site.
3129
- if (thrownErrorType ) {
3124
+ if (declRefType. thrownErrorTypeOnAccess ) {
3130
3125
recordPotentialThrowSite (
3131
- PotentialThrowSite::PropertyAccess, thrownErrorType, locator);
3126
+ PotentialThrowSite::PropertyAccess,
3127
+ declRefType.thrownErrorTypeOnAccess ,
3128
+ locator);
3132
3129
}
3133
3130
3134
3131
// Note that we have resolved this overload.
3135
3132
auto overload = SelectedOverload{
3136
- choice, openedType, adjustedOpenedType, refType, adjustedRefType,
3133
+ choice,
3134
+ declRefType.openedType ,
3135
+ declRefType.adjustedOpenedType ,
3136
+ declRefType.referenceType ,
3137
+ declRefType.adjustedReferenceType ,
3137
3138
boundType};
3138
3139
recordResolvedOverload (locator, overload);
3139
3140
@@ -3149,7 +3150,7 @@ void ConstraintSystem::resolveOverload(OverloadChoice choice, DeclContext *useDC
3149
3150
log << " (overload set choice binding " ;
3150
3151
boundType->print (log, PO);
3151
3152
log << " := " ;
3152
- adjustedRefType ->print (log, PO);
3153
+ declRefType. adjustedReferenceType ->print (log, PO);
3153
3154
3154
3155
auto openedAtLoc = getOpenedTypes (locator);
3155
3156
if (!openedAtLoc.empty ()) {
@@ -3181,8 +3182,9 @@ void ConstraintSystem::resolveOverload(OverloadChoice choice, DeclContext *useDC
3181
3182
OverloadChoiceKind::DeclViaDynamic)) {
3182
3183
3183
3184
// Strip curried 'self' parameters.
3184
- auto fromTy = openedType->castTo <AnyFunctionType>()->getResult ();
3185
- auto toTy = refType;
3185
+ auto fromTy = declRefType.openedType
3186
+ ->castTo <AnyFunctionType>()->getResult ();
3187
+ auto toTy = declRefType.referenceType ;
3186
3188
if (!doesMemberRefApplyCurriedSelf (baseTy, decl)) {
3187
3189
toTy = toTy->castTo <AnyFunctionType>()->getResult ();
3188
3190
}
0 commit comments