@@ -2039,7 +2039,8 @@ getResultDifferentiability(SILResultInfo::Options options) {
20392039
20402040void ASTMangler::appendImplFunctionType (SILFunctionType *fn,
20412041 GenericSignature outerGenericSig,
2042- const ValueDecl *forDecl) {
2042+ const ValueDecl *forDecl,
2043+ bool isInRecursion) {
20432044
20442045 llvm::SmallVector<char , 32 > OpArgs;
20452046
@@ -2164,7 +2165,7 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn,
21642165 }
21652166
21662167 // Mangle if we have a transferring result.
2167- if (fn->hasSendingResult ())
2168+ if (isInRecursion && fn->hasSendingResult ())
21682169 OpArgs.push_back (' T' );
21692170
21702171 // Mangle the results.
@@ -2947,7 +2948,7 @@ void ASTMangler::appendAnyGenericType(const GenericTypeDecl *decl,
29472948
29482949void ASTMangler::appendFunction (AnyFunctionType *fn, GenericSignature sig,
29492950 FunctionManglingKind functionMangling,
2950- const ValueDecl *forDecl) {
2951+ const ValueDecl *forDecl, bool isRecursedInto ) {
29512952 // Append parameter labels right before the signature/type.
29522953 auto parameters = fn->getParams ();
29532954 auto firstLabel = std::find_if (
@@ -2967,19 +2968,20 @@ void ASTMangler::appendFunction(AnyFunctionType *fn, GenericSignature sig,
29672968 }
29682969
29692970 if (functionMangling != NoFunctionMangling) {
2970- appendFunctionSignature (fn, sig, forDecl, functionMangling);
2971+ appendFunctionSignature (fn, sig, forDecl, functionMangling, isRecursedInto );
29712972 } else {
2972- appendFunctionType (fn, sig, /* autoclosure*/ false , forDecl);
2973+ appendFunctionType (fn, sig, /* autoclosure*/ false , forDecl, isRecursedInto );
29732974 }
29742975}
29752976
29762977void ASTMangler::appendFunctionType (AnyFunctionType *fn, GenericSignature sig,
29772978 bool isAutoClosure,
2978- const ValueDecl *forDecl) {
2979+ const ValueDecl *forDecl,
2980+ bool isRecursedInto) {
29792981 assert ((DWARFMangling || fn->isCanonical ()) &&
29802982 " expecting canonical types when not mangling for the debugger" );
29812983
2982- appendFunctionSignature (fn, sig, forDecl, NoFunctionMangling);
2984+ appendFunctionSignature (fn, sig, forDecl, NoFunctionMangling, isRecursedInto );
29832985
29842986 bool mangleClangType = fn->getASTContext ().LangOpts .UseClangFunctionTypes &&
29852987 fn->hasNonDerivableClangType ();
@@ -3047,10 +3049,11 @@ void ASTMangler::appendClangType(AnyFunctionType *fn) {
30473049void ASTMangler::appendFunctionSignature (AnyFunctionType *fn,
30483050 GenericSignature sig,
30493051 const ValueDecl *forDecl,
3050- FunctionManglingKind functionMangling) {
3052+ FunctionManglingKind functionMangling,
3053+ bool isRecursedInto) {
30513054 appendFunctionResultType (fn->getResult (), sig, forDecl);
30523055 appendFunctionInputType (fn->getParams (), fn->getLifetimeDependenceInfo (), sig,
3053- forDecl);
3056+ forDecl, isRecursedInto );
30543057 if (fn->isAsync ())
30553058 appendOperator (" Ya" );
30563059 if (fn->isSendable ())
@@ -3096,7 +3099,7 @@ void ASTMangler::appendFunctionSignature(AnyFunctionType *fn,
30963099 break ;
30973100 }
30983101
3099- if (fn->hasSendingResult ()) {
3102+ if (isRecursedInto && fn->hasSendingResult ()) {
31003103 appendOperator (" YT" );
31013104 }
31023105
@@ -3142,19 +3145,25 @@ getDefaultOwnership(const ValueDecl *forDecl) {
31423145
31433146static ParameterTypeFlags
31443147getParameterFlagsForMangling (ParameterTypeFlags flags,
3145- ParamSpecifier defaultSpecifier) {
3148+ ParamSpecifier defaultSpecifier,
3149+ bool isInRecursion = true ) {
3150+ bool initiallySending = flags.isSending ();
3151+
3152+ // If we have been recursed into, then remove sending from our flags.
3153+ if (!isInRecursion) {
3154+ flags = flags.withSending (false );
3155+ }
3156+
31463157 switch (auto specifier = flags.getOwnershipSpecifier ()) {
31473158 // If no parameter specifier was provided, mangle as-is, because we are by
31483159 // definition using the default convention.
31493160 case ParamSpecifier::Default:
31503161 // If the legacy `__shared` or `__owned` modifier was provided, mangle as-is,
31513162 // because we need to maintain compatibility with their existing behavior.
3152- case ParamSpecifier::LegacyShared:
31533163 case ParamSpecifier::LegacyOwned:
31543164 // `inout` should already be specified in the flags.
31553165 case ParamSpecifier::InOut:
31563166 return flags;
3157-
31583167 case ParamSpecifier::ImplicitlyCopyableConsuming:
31593168 case ParamSpecifier::Consuming:
31603169 case ParamSpecifier::Borrowing:
@@ -3163,13 +3172,23 @@ getParameterFlagsForMangling(ParameterTypeFlags flags,
31633172 flags = flags.withOwnershipSpecifier (ParamSpecifier::Default);
31643173 }
31653174 return flags;
3175+ case ParamSpecifier::LegacyShared:
3176+ // If we were originally sending and by default we are borrowing, suppress
3177+ // this and set ownership specifier to default so we do not mangle in
3178+ // __shared.
3179+ //
3180+ // This is a work around in the short term since shared borrow is not
3181+ // supported.
3182+ if (initiallySending && ParamSpecifier::Borrowing == defaultSpecifier)
3183+ return flags.withOwnershipSpecifier (ParamSpecifier::Default);
3184+ return flags;
31663185 }
31673186}
31683187
31693188void ASTMangler::appendFunctionInputType (
31703189 ArrayRef<AnyFunctionType::Param> params,
31713190 LifetimeDependenceInfo lifetimeDependenceInfo, GenericSignature sig,
3172- const ValueDecl *forDecl) {
3191+ const ValueDecl *forDecl, bool isRecursedInto ) {
31733192 auto defaultSpecifier = getDefaultOwnership (forDecl);
31743193
31753194 switch (params.size ()) {
@@ -3192,7 +3211,7 @@ void ASTMangler::appendFunctionInputType(
31923211 appendParameterTypeListElement (
31933212 Identifier (), type,
31943213 getParameterFlagsForMangling (param.getParameterFlags (),
3195- defaultSpecifier),
3214+ defaultSpecifier, isRecursedInto ),
31963215 lifetimeDependenceInfo.getLifetimeDependenceOnParam (/* paramIndex*/ 0 ),
31973216 sig, nullptr );
31983217 break ;
@@ -3214,7 +3233,7 @@ void ASTMangler::appendFunctionInputType(
32143233 appendParameterTypeListElement (
32153234 Identifier (), param.getPlainType (),
32163235 getParameterFlagsForMangling (param.getParameterFlags (),
3217- defaultSpecifier),
3236+ defaultSpecifier, isRecursedInto ),
32183237 lifetimeDependenceInfo.getLifetimeDependenceOnParam (paramIndex), sig,
32193238 nullptr );
32203239 appendListSeparator (isFirstParam);
@@ -3878,7 +3897,8 @@ void ASTMangler::appendDeclType(const ValueDecl *decl,
38783897 : decl->getDeclContext ()->getGenericSignatureOfContext ());
38793898
38803899 if (AnyFunctionType *FuncTy = type->getAs <AnyFunctionType>()) {
3881- appendFunction (FuncTy, sig, functionMangling, decl);
3900+ appendFunction (FuncTy, sig, functionMangling, decl,
3901+ false /* is recursed into*/ );
38823902 } else {
38833903 appendType (type, sig, decl);
38843904 }
0 commit comments