@@ -2039,7 +2039,8 @@ getResultDifferentiability(SILResultInfo::Options options) {
2039
2039
2040
2040
void ASTMangler::appendImplFunctionType (SILFunctionType *fn,
2041
2041
GenericSignature outerGenericSig,
2042
- const ValueDecl *forDecl) {
2042
+ const ValueDecl *forDecl,
2043
+ bool isInRecursion) {
2043
2044
2044
2045
llvm::SmallVector<char , 32 > OpArgs;
2045
2046
@@ -2164,7 +2165,7 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn,
2164
2165
}
2165
2166
2166
2167
// Mangle if we have a transferring result.
2167
- if (fn->hasSendingResult ())
2168
+ if (isInRecursion && fn->hasSendingResult ())
2168
2169
OpArgs.push_back (' T' );
2169
2170
2170
2171
// Mangle the results.
@@ -2947,7 +2948,7 @@ void ASTMangler::appendAnyGenericType(const GenericTypeDecl *decl,
2947
2948
2948
2949
void ASTMangler::appendFunction (AnyFunctionType *fn, GenericSignature sig,
2949
2950
FunctionManglingKind functionMangling,
2950
- const ValueDecl *forDecl) {
2951
+ const ValueDecl *forDecl, bool isRecursedInto ) {
2951
2952
// Append parameter labels right before the signature/type.
2952
2953
auto parameters = fn->getParams ();
2953
2954
auto firstLabel = std::find_if (
@@ -2967,19 +2968,20 @@ void ASTMangler::appendFunction(AnyFunctionType *fn, GenericSignature sig,
2967
2968
}
2968
2969
2969
2970
if (functionMangling != NoFunctionMangling) {
2970
- appendFunctionSignature (fn, sig, forDecl, functionMangling);
2971
+ appendFunctionSignature (fn, sig, forDecl, functionMangling, isRecursedInto );
2971
2972
} else {
2972
- appendFunctionType (fn, sig, /* autoclosure*/ false , forDecl);
2973
+ appendFunctionType (fn, sig, /* autoclosure*/ false , forDecl, isRecursedInto );
2973
2974
}
2974
2975
}
2975
2976
2976
2977
void ASTMangler::appendFunctionType (AnyFunctionType *fn, GenericSignature sig,
2977
2978
bool isAutoClosure,
2978
- const ValueDecl *forDecl) {
2979
+ const ValueDecl *forDecl,
2980
+ bool isRecursedInto) {
2979
2981
assert ((DWARFMangling || fn->isCanonical ()) &&
2980
2982
" expecting canonical types when not mangling for the debugger" );
2981
2983
2982
- appendFunctionSignature (fn, sig, forDecl, NoFunctionMangling);
2984
+ appendFunctionSignature (fn, sig, forDecl, NoFunctionMangling, isRecursedInto );
2983
2985
2984
2986
bool mangleClangType = fn->getASTContext ().LangOpts .UseClangFunctionTypes &&
2985
2987
fn->hasNonDerivableClangType ();
@@ -3047,10 +3049,11 @@ void ASTMangler::appendClangType(AnyFunctionType *fn) {
3047
3049
void ASTMangler::appendFunctionSignature (AnyFunctionType *fn,
3048
3050
GenericSignature sig,
3049
3051
const ValueDecl *forDecl,
3050
- FunctionManglingKind functionMangling) {
3052
+ FunctionManglingKind functionMangling,
3053
+ bool isRecursedInto) {
3051
3054
appendFunctionResultType (fn->getResult (), sig, forDecl);
3052
3055
appendFunctionInputType (fn->getParams (), fn->getLifetimeDependenceInfo (), sig,
3053
- forDecl);
3056
+ forDecl, isRecursedInto );
3054
3057
if (fn->isAsync ())
3055
3058
appendOperator (" Ya" );
3056
3059
if (fn->isSendable ())
@@ -3096,7 +3099,7 @@ void ASTMangler::appendFunctionSignature(AnyFunctionType *fn,
3096
3099
break ;
3097
3100
}
3098
3101
3099
- if (fn->hasSendingResult ()) {
3102
+ if (isRecursedInto && fn->hasSendingResult ()) {
3100
3103
appendOperator (" YT" );
3101
3104
}
3102
3105
@@ -3142,19 +3145,25 @@ getDefaultOwnership(const ValueDecl *forDecl) {
3142
3145
3143
3146
static ParameterTypeFlags
3144
3147
getParameterFlagsForMangling (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
+
3146
3157
switch (auto specifier = flags.getOwnershipSpecifier ()) {
3147
3158
// If no parameter specifier was provided, mangle as-is, because we are by
3148
3159
// definition using the default convention.
3149
3160
case ParamSpecifier::Default:
3150
3161
// If the legacy `__shared` or `__owned` modifier was provided, mangle as-is,
3151
3162
// because we need to maintain compatibility with their existing behavior.
3152
- case ParamSpecifier::LegacyShared:
3153
3163
case ParamSpecifier::LegacyOwned:
3154
3164
// `inout` should already be specified in the flags.
3155
3165
case ParamSpecifier::InOut:
3156
3166
return flags;
3157
-
3158
3167
case ParamSpecifier::ImplicitlyCopyableConsuming:
3159
3168
case ParamSpecifier::Consuming:
3160
3169
case ParamSpecifier::Borrowing:
@@ -3163,13 +3172,23 @@ getParameterFlagsForMangling(ParameterTypeFlags flags,
3163
3172
flags = flags.withOwnershipSpecifier (ParamSpecifier::Default);
3164
3173
}
3165
3174
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;
3166
3185
}
3167
3186
}
3168
3187
3169
3188
void ASTMangler::appendFunctionInputType (
3170
3189
ArrayRef<AnyFunctionType::Param> params,
3171
3190
LifetimeDependenceInfo lifetimeDependenceInfo, GenericSignature sig,
3172
- const ValueDecl *forDecl) {
3191
+ const ValueDecl *forDecl, bool isRecursedInto ) {
3173
3192
auto defaultSpecifier = getDefaultOwnership (forDecl);
3174
3193
3175
3194
switch (params.size ()) {
@@ -3192,7 +3211,7 @@ void ASTMangler::appendFunctionInputType(
3192
3211
appendParameterTypeListElement (
3193
3212
Identifier (), type,
3194
3213
getParameterFlagsForMangling (param.getParameterFlags (),
3195
- defaultSpecifier),
3214
+ defaultSpecifier, isRecursedInto ),
3196
3215
lifetimeDependenceInfo.getLifetimeDependenceOnParam (/* paramIndex*/ 0 ),
3197
3216
sig, nullptr );
3198
3217
break ;
@@ -3214,7 +3233,7 @@ void ASTMangler::appendFunctionInputType(
3214
3233
appendParameterTypeListElement (
3215
3234
Identifier (), param.getPlainType (),
3216
3235
getParameterFlagsForMangling (param.getParameterFlags (),
3217
- defaultSpecifier),
3236
+ defaultSpecifier, isRecursedInto ),
3218
3237
lifetimeDependenceInfo.getLifetimeDependenceOnParam (paramIndex), sig,
3219
3238
nullptr );
3220
3239
appendListSeparator (isFirstParam);
@@ -3878,7 +3897,8 @@ void ASTMangler::appendDeclType(const ValueDecl *decl,
3878
3897
: decl->getDeclContext ()->getGenericSignatureOfContext ());
3879
3898
3880
3899
if (AnyFunctionType *FuncTy = type->getAs <AnyFunctionType>()) {
3881
- appendFunction (FuncTy, sig, functionMangling, decl);
3900
+ appendFunction (FuncTy, sig, functionMangling, decl,
3901
+ false /* is recursed into*/ );
3882
3902
} else {
3883
3903
appendType (type, sig, decl);
3884
3904
}
0 commit comments