@@ -2034,7 +2034,8 @@ getResultDifferentiability(SILResultInfo::Options options) {
20342034
20352035void ASTMangler::appendImplFunctionType (SILFunctionType *fn,
20362036 GenericSignature outerGenericSig,
2037- const ValueDecl *forDecl) {
2037+ const ValueDecl *forDecl,
2038+ bool isInRecursion) {
20382039
20392040 llvm::SmallVector<char , 32 > OpArgs;
20402041
@@ -2159,7 +2160,7 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn,
21592160 }
21602161
21612162 // Mangle if we have a transferring result.
2162- if (fn->hasSendingResult ())
2163+ if (isInRecursion && fn->hasSendingResult ())
21632164 OpArgs.push_back (' T' );
21642165
21652166 // Mangle the results.
@@ -2942,7 +2943,7 @@ void ASTMangler::appendAnyGenericType(const GenericTypeDecl *decl,
29422943
29432944void ASTMangler::appendFunction (AnyFunctionType *fn, GenericSignature sig,
29442945 FunctionManglingKind functionMangling,
2945- const ValueDecl *forDecl) {
2946+ const ValueDecl *forDecl, bool isRecursedInto ) {
29462947 // Append parameter labels right before the signature/type.
29472948 auto parameters = fn->getParams ();
29482949 auto firstLabel = std::find_if (
@@ -2962,19 +2963,20 @@ void ASTMangler::appendFunction(AnyFunctionType *fn, GenericSignature sig,
29622963 }
29632964
29642965 if (functionMangling != NoFunctionMangling) {
2965- appendFunctionSignature (fn, sig, forDecl, functionMangling);
2966+ appendFunctionSignature (fn, sig, forDecl, functionMangling, isRecursedInto );
29662967 } else {
2967- appendFunctionType (fn, sig, /* autoclosure*/ false , forDecl);
2968+ appendFunctionType (fn, sig, /* autoclosure*/ false , forDecl, isRecursedInto );
29682969 }
29692970}
29702971
29712972void ASTMangler::appendFunctionType (AnyFunctionType *fn, GenericSignature sig,
29722973 bool isAutoClosure,
2973- const ValueDecl *forDecl) {
2974+ const ValueDecl *forDecl,
2975+ bool isRecursedInto) {
29742976 assert ((DWARFMangling || fn->isCanonical ()) &&
29752977 " expecting canonical types when not mangling for the debugger" );
29762978
2977- appendFunctionSignature (fn, sig, forDecl, NoFunctionMangling);
2979+ appendFunctionSignature (fn, sig, forDecl, NoFunctionMangling, isRecursedInto );
29782980
29792981 bool mangleClangType = fn->getASTContext ().LangOpts .UseClangFunctionTypes &&
29802982 fn->hasNonDerivableClangType ();
@@ -3042,10 +3044,11 @@ void ASTMangler::appendClangType(AnyFunctionType *fn) {
30423044void ASTMangler::appendFunctionSignature (AnyFunctionType *fn,
30433045 GenericSignature sig,
30443046 const ValueDecl *forDecl,
3045- FunctionManglingKind functionMangling) {
3047+ FunctionManglingKind functionMangling,
3048+ bool isRecursedInto) {
30463049 appendFunctionResultType (fn->getResult (), sig, forDecl);
30473050 appendFunctionInputType (fn->getParams (), fn->getLifetimeDependenceInfo (), sig,
3048- forDecl);
3051+ forDecl, isRecursedInto );
30493052 if (fn->isAsync ())
30503053 appendOperator (" Ya" );
30513054 if (fn->isSendable ())
@@ -3091,7 +3094,7 @@ void ASTMangler::appendFunctionSignature(AnyFunctionType *fn,
30913094 break ;
30923095 }
30933096
3094- if (fn->hasSendingResult ()) {
3097+ if (isRecursedInto && fn->hasSendingResult ()) {
30953098 appendOperator (" YT" );
30963099 }
30973100
@@ -3137,19 +3140,25 @@ getDefaultOwnership(const ValueDecl *forDecl) {
31373140
31383141static ParameterTypeFlags
31393142getParameterFlagsForMangling (ParameterTypeFlags flags,
3140- ParamSpecifier defaultSpecifier) {
3143+ ParamSpecifier defaultSpecifier,
3144+ bool isInRecursion = true ) {
3145+ bool initiallySending = flags.isSending ();
3146+
3147+ // If we have been recursed into, then remove sending from our flags.
3148+ if (!isInRecursion) {
3149+ flags = flags.withSending (false );
3150+ }
3151+
31413152 switch (auto specifier = flags.getOwnershipSpecifier ()) {
31423153 // If no parameter specifier was provided, mangle as-is, because we are by
31433154 // definition using the default convention.
31443155 case ParamSpecifier::Default:
31453156 // If the legacy `__shared` or `__owned` modifier was provided, mangle as-is,
31463157 // because we need to maintain compatibility with their existing behavior.
3147- case ParamSpecifier::LegacyShared:
31483158 case ParamSpecifier::LegacyOwned:
31493159 // `inout` should already be specified in the flags.
31503160 case ParamSpecifier::InOut:
31513161 return flags;
3152-
31533162 case ParamSpecifier::ImplicitlyCopyableConsuming:
31543163 case ParamSpecifier::Consuming:
31553164 case ParamSpecifier::Borrowing:
@@ -3158,13 +3167,23 @@ getParameterFlagsForMangling(ParameterTypeFlags flags,
31583167 flags = flags.withOwnershipSpecifier (ParamSpecifier::Default);
31593168 }
31603169 return flags;
3170+ case ParamSpecifier::LegacyShared:
3171+ // If we were originally sending and by default we are borrowing, suppress
3172+ // this and set ownership specifier to default so we do not mangle in
3173+ // __shared.
3174+ //
3175+ // This is a work around in the short term since shared borrow is not
3176+ // supported.
3177+ if (initiallySending && ParamSpecifier::Borrowing == defaultSpecifier)
3178+ return flags.withOwnershipSpecifier (ParamSpecifier::Default);
3179+ return flags;
31613180 }
31623181}
31633182
31643183void ASTMangler::appendFunctionInputType (
31653184 ArrayRef<AnyFunctionType::Param> params,
31663185 LifetimeDependenceInfo lifetimeDependenceInfo, GenericSignature sig,
3167- const ValueDecl *forDecl) {
3186+ const ValueDecl *forDecl, bool isRecursedInto ) {
31683187 auto defaultSpecifier = getDefaultOwnership (forDecl);
31693188
31703189 switch (params.size ()) {
@@ -3187,7 +3206,7 @@ void ASTMangler::appendFunctionInputType(
31873206 appendParameterTypeListElement (
31883207 Identifier (), type,
31893208 getParameterFlagsForMangling (param.getParameterFlags (),
3190- defaultSpecifier),
3209+ defaultSpecifier, isRecursedInto ),
31913210 lifetimeDependenceInfo.getLifetimeDependenceOnParam (/* paramIndex*/ 0 ),
31923211 sig, nullptr );
31933212 break ;
@@ -3209,7 +3228,7 @@ void ASTMangler::appendFunctionInputType(
32093228 appendParameterTypeListElement (
32103229 Identifier (), param.getPlainType (),
32113230 getParameterFlagsForMangling (param.getParameterFlags (),
3212- defaultSpecifier),
3231+ defaultSpecifier, isRecursedInto ),
32133232 lifetimeDependenceInfo.getLifetimeDependenceOnParam (paramIndex), sig,
32143233 nullptr );
32153234 appendListSeparator (isFirstParam);
@@ -3873,7 +3892,8 @@ void ASTMangler::appendDeclType(const ValueDecl *decl,
38733892 : decl->getDeclContext ()->getGenericSignatureOfContext ());
38743893
38753894 if (AnyFunctionType *FuncTy = type->getAs <AnyFunctionType>()) {
3876- appendFunction (FuncTy, sig, functionMangling, decl);
3895+ appendFunction (FuncTy, sig, functionMangling, decl,
3896+ false /* is recursed into*/ );
38773897 } else {
38783898 appendType (type, sig, decl);
38793899 }
0 commit comments