@@ -2809,7 +2809,8 @@ void ASTMangler::appendFunctionSignature(AnyFunctionType *fn,
28092809 const ValueDecl *forDecl,
28102810 FunctionManglingKind functionMangling) {
28112811 appendFunctionResultType (fn->getResult (), sig, forDecl);
2812- appendFunctionInputType (fn->getParams (), sig, forDecl);
2812+ appendFunctionInputType (fn->getParams (), fn->getLifetimeDependenceInfo (), sig,
2813+ forDecl);
28132814 if (fn->isAsync ())
28142815 appendOperator (" Ya" );
28152816 if (fn->isSendable ())
@@ -2843,6 +2844,18 @@ void ASTMangler::appendFunctionSignature(AnyFunctionType *fn,
28432844 appendType (globalActor, sig);
28442845 appendOperator (" Yc" );
28452846 }
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+ }
28462859}
28472860
28482861static ParamSpecifier
@@ -2900,7 +2913,7 @@ getParameterFlagsForMangling(ParameterTypeFlags flags,
29002913
29012914void ASTMangler::appendFunctionInputType (
29022915 ArrayRef<AnyFunctionType::Param> params,
2903- GenericSignature sig,
2916+ LifetimeDependenceInfo lifetimeDependenceInfo, GenericSignature sig,
29042917 const ValueDecl *forDecl) {
29052918 auto defaultSpecifier = getDefaultOwnership (forDecl);
29062919
@@ -2921,10 +2934,12 @@ void ASTMangler::appendFunctionInputType(
29212934 // of the input is no longer directly the type of the declaration, so we
29222935 // don't want it to pick up contextual behavior, such as default ownership,
29232936 // 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 );
29282943 break ;
29292944 }
29302945
@@ -2935,16 +2950,20 @@ void ASTMangler::appendFunctionInputType(
29352950
29362951 default :
29372952 bool isFirstParam = true ;
2953+ unsigned paramIndex = 1 ; /* 0 is reserved for self*/
29382954 for (auto ¶m : params) {
29392955 // Note that we pass `nullptr` as the `forDecl` argument, since the type
29402956 // of the input is no longer directly the type of the declaration, so we
29412957 // don't want it to pick up contextual behavior, such as default ownership,
29422958 // 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 );
29472965 appendListSeparator (isFirstParam);
2966+ paramIndex++;
29482967 }
29492968 appendOperator (" t" );
29502969 break ;
@@ -2964,9 +2983,8 @@ void ASTMangler::appendTypeList(Type listTy, GenericSignature sig,
29642983 return appendOperator (" y" );
29652984 bool firstField = true ;
29662985 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);
29702988 appendListSeparator (firstField);
29712989 }
29722990 } else {
@@ -2975,10 +2993,10 @@ void ASTMangler::appendTypeList(Type listTy, GenericSignature sig,
29752993 }
29762994}
29772995
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) {
29823000 if (auto *fnType = elementType->getAs <FunctionType>())
29833001 appendFunctionType (fnType, sig, flags.isAutoClosure (), forDecl);
29843002 else
@@ -3007,12 +3025,53 @@ void ASTMangler::appendTypeListElement(Identifier name, Type elementType,
30073025 if (flags.isCompileTimeConst ())
30083026 appendOperator (" Yt" );
30093027
3028+ if (lifetimeDependenceKind) {
3029+ appendLifetimeDependenceKind (*lifetimeDependenceKind,
3030+ /* isSelfDependence*/ false );
3031+ }
3032+
30103033 if (!name.empty ())
30113034 appendIdentifier (name.str ());
30123035 if (flags.isVariadic ())
30133036 appendOperator (" d" );
30143037}
30153038
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+
30163075bool ASTMangler::appendGenericSignature (GenericSignature sig,
30173076 GenericSignature contextSig) {
30183077 auto canSig = sig.getCanonicalSignature ();
0 commit comments