@@ -2809,7 +2809,8 @@ void ASTMangler::appendFunctionSignature(AnyFunctionType *fn,
2809
2809
const ValueDecl *forDecl,
2810
2810
FunctionManglingKind functionMangling) {
2811
2811
appendFunctionResultType (fn->getResult (), sig, forDecl);
2812
- appendFunctionInputType (fn->getParams (), sig, forDecl);
2812
+ appendFunctionInputType (fn->getParams (), fn->getLifetimeDependenceInfo (), sig,
2813
+ forDecl);
2813
2814
if (fn->isAsync ())
2814
2815
appendOperator (" Ya" );
2815
2816
if (fn->isSendable ())
@@ -2843,6 +2844,18 @@ void ASTMangler::appendFunctionSignature(AnyFunctionType *fn,
2843
2844
appendType (globalActor, sig);
2844
2845
appendOperator (" Yc" );
2845
2846
}
2847
+
2848
+ if (auto *afd = dyn_cast_or_null<AbstractFunctionDecl>(forDecl)) {
2849
+ if (afd->hasImplicitSelfDecl ()) {
2850
+ auto lifetimeDependenceKind =
2851
+ fn->getLifetimeDependenceInfo ().getLifetimeDependenceOnParam (
2852
+ /* paramIndex*/ 0 );
2853
+ if (lifetimeDependenceKind) {
2854
+ appendLifetimeDependenceKind (*lifetimeDependenceKind,
2855
+ /* isSelfDependence*/ true );
2856
+ }
2857
+ }
2858
+ }
2846
2859
}
2847
2860
2848
2861
static ParamSpecifier
@@ -2900,7 +2913,7 @@ getParameterFlagsForMangling(ParameterTypeFlags flags,
2900
2913
2901
2914
void ASTMangler::appendFunctionInputType (
2902
2915
ArrayRef<AnyFunctionType::Param> params,
2903
- GenericSignature sig,
2916
+ LifetimeDependenceInfo lifetimeDependenceInfo, GenericSignature sig,
2904
2917
const ValueDecl *forDecl) {
2905
2918
auto defaultSpecifier = getDefaultOwnership (forDecl);
2906
2919
@@ -2921,10 +2934,12 @@ void ASTMangler::appendFunctionInputType(
2921
2934
// of the input is no longer directly the type of the declaration, so we
2922
2935
// don't want it to pick up contextual behavior, such as default ownership,
2923
2936
// from the top-level declaration type.
2924
- appendTypeListElement (Identifier (), type,
2925
- getParameterFlagsForMangling (param.getParameterFlags (),
2926
- defaultSpecifier),
2927
- sig, nullptr );
2937
+ appendParameterTypeListElement (
2938
+ Identifier (), type,
2939
+ getParameterFlagsForMangling (param.getParameterFlags (),
2940
+ defaultSpecifier),
2941
+ lifetimeDependenceInfo.getLifetimeDependenceOnParam (/* paramIndex*/ 1 ),
2942
+ sig, nullptr );
2928
2943
break ;
2929
2944
}
2930
2945
@@ -2935,16 +2950,20 @@ void ASTMangler::appendFunctionInputType(
2935
2950
2936
2951
default :
2937
2952
bool isFirstParam = true ;
2953
+ unsigned paramIndex = 1 ; /* 0 is reserved for self*/
2938
2954
for (auto ¶m : params) {
2939
2955
// Note that we pass `nullptr` as the `forDecl` argument, since the type
2940
2956
// of the input is no longer directly the type of the declaration, so we
2941
2957
// don't want it to pick up contextual behavior, such as default ownership,
2942
2958
// from the top-level declaration type.
2943
- appendTypeListElement (Identifier (), param.getPlainType (),
2944
- getParameterFlagsForMangling (param.getParameterFlags (),
2945
- defaultSpecifier),
2946
- sig, nullptr );
2959
+ appendParameterTypeListElement (
2960
+ Identifier (), param.getPlainType (),
2961
+ getParameterFlagsForMangling (param.getParameterFlags (),
2962
+ defaultSpecifier),
2963
+ lifetimeDependenceInfo.getLifetimeDependenceOnParam (paramIndex), sig,
2964
+ nullptr );
2947
2965
appendListSeparator (isFirstParam);
2966
+ paramIndex++;
2948
2967
}
2949
2968
appendOperator (" t" );
2950
2969
break ;
@@ -2964,9 +2983,8 @@ void ASTMangler::appendTypeList(Type listTy, GenericSignature sig,
2964
2983
return appendOperator (" y" );
2965
2984
bool firstField = true ;
2966
2985
for (auto &field : tuple->getElements ()) {
2967
- appendTypeListElement (field.getName (), field.getType (),
2968
- ParameterTypeFlags (),
2969
- sig, forDecl);
2986
+ appendTupleTypeListElement (field.getName (), field.getType (), sig,
2987
+ forDecl);
2970
2988
appendListSeparator (firstField);
2971
2989
}
2972
2990
} else {
@@ -2975,10 +2993,10 @@ void ASTMangler::appendTypeList(Type listTy, GenericSignature sig,
2975
2993
}
2976
2994
}
2977
2995
2978
- void ASTMangler::appendTypeListElement (Identifier name, Type elementType,
2979
- ParameterTypeFlags flags,
2980
- GenericSignature sig ,
2981
- const ValueDecl *forDecl) {
2996
+ void ASTMangler::appendParameterTypeListElement (
2997
+ Identifier name, Type elementType, ParameterTypeFlags flags,
2998
+ std::optional<LifetimeDependenceKind> lifetimeDependenceKind ,
2999
+ GenericSignature sig, const ValueDecl *forDecl) {
2982
3000
if (auto *fnType = elementType->getAs <FunctionType>())
2983
3001
appendFunctionType (fnType, sig, flags.isAutoClosure (), forDecl);
2984
3002
else
@@ -3007,12 +3025,53 @@ void ASTMangler::appendTypeListElement(Identifier name, Type elementType,
3007
3025
if (flags.isCompileTimeConst ())
3008
3026
appendOperator (" Yt" );
3009
3027
3028
+ if (lifetimeDependenceKind) {
3029
+ appendLifetimeDependenceKind (*lifetimeDependenceKind,
3030
+ /* isSelfDependence*/ false );
3031
+ }
3032
+
3010
3033
if (!name.empty ())
3011
3034
appendIdentifier (name.str ());
3012
3035
if (flags.isVariadic ())
3013
3036
appendOperator (" d" );
3014
3037
}
3015
3038
3039
+ void ASTMangler::appendLifetimeDependenceKind (LifetimeDependenceKind kind,
3040
+ bool isSelfDependence) {
3041
+ // If we converge on dependsOn(borrowed: paramName)/dependsOn(paramName)
3042
+ // syntax, this can be a single case value check.
3043
+ if (kind == LifetimeDependenceKind::Borrow ||
3044
+ kind == LifetimeDependenceKind::Mutate) {
3045
+ if (isSelfDependence) {
3046
+ appendOperator (" YLs" );
3047
+ } else {
3048
+ appendOperator (" Yls" );
3049
+ }
3050
+ } else {
3051
+ // If we converge on dependsOn(borrowed: paramName)/dependsOn(paramName)
3052
+ // syntax, this can be a single case value check.
3053
+ assert (kind == LifetimeDependenceKind::Copy ||
3054
+ kind == LifetimeDependenceKind::Consume);
3055
+ if (isSelfDependence) {
3056
+ appendOperator (" YLi" );
3057
+ } else {
3058
+ appendOperator (" Yli" );
3059
+ }
3060
+ }
3061
+ }
3062
+
3063
+ void ASTMangler::appendTupleTypeListElement (Identifier name, Type elementType,
3064
+ GenericSignature sig,
3065
+ const ValueDecl *forDecl) {
3066
+ if (auto *fnType = elementType->getAs <FunctionType>())
3067
+ appendFunctionType (fnType, sig, /* isAutoClosure*/ false , forDecl);
3068
+ else
3069
+ appendType (elementType, sig, forDecl);
3070
+
3071
+ if (!name.empty ())
3072
+ appendIdentifier (name.str ());
3073
+ }
3074
+
3016
3075
bool ASTMangler::appendGenericSignature (GenericSignature sig,
3017
3076
GenericSignature contextSig) {
3018
3077
auto canSig = sig.getCanonicalSignature ();
0 commit comments