@@ -3024,6 +3024,7 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
3024
3024
}
3025
3025
}
3026
3026
3027
+ auto Target = SGM.getASTContext ().LangOpts .Target ;
3027
3028
auto genericSig =
3028
3029
genericEnv ? genericEnv->getGenericSignature ().getCanonicalSignature ()
3029
3030
: nullptr ;
@@ -3032,6 +3033,14 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
3032
3033
genericEnv = nullptr ;
3033
3034
}
3034
3035
3036
+ // Add empty generic type parameter to match function signature on WebAssembly
3037
+ if (!genericSig && Target.isOSBinFormatWasm ()) {
3038
+ auto param = GenericTypeParamType::get (false , 0 , 0 , SGM.getASTContext ());
3039
+ auto sig = GenericSignature::get (param, { });
3040
+ genericSig = CanGenericSignature (sig);
3041
+ genericEnv = sig.getGenericEnvironment ();
3042
+ }
3043
+
3035
3044
// Build the signature of the thunk as expected by the keypath runtime.
3036
3045
auto signature = [&]() {
3037
3046
CanType loweredBaseTy, loweredPropTy;
@@ -3047,7 +3056,8 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
3047
3056
SmallVector<SILParameterInfo, 2 > params;
3048
3057
params.push_back ({loweredBaseTy, paramConvention});
3049
3058
auto &C = SGM.getASTContext ();
3050
- if (!indexes.empty ())
3059
+ // Always take indexes parameter to match callee and caller signature on WebAssembly
3060
+ if (!indexes.empty () || C.LangOpts .Target .isOSBinFormatWasm ())
3051
3061
params.push_back ({C.getUnsafeRawPointerType ()->getCanonicalType (),
3052
3062
ParameterConvention::Direct_Unowned});
3053
3063
@@ -3107,7 +3117,8 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
3107
3117
}
3108
3118
auto baseArg = entry->createFunctionArgument (baseArgTy);
3109
3119
SILValue indexPtrArg;
3110
- if (!indexes.empty ()) {
3120
+ // Always take indexes parameter to match callee and caller signature on WebAssembly
3121
+ if (!indexes.empty () || Target.isOSBinFormatWasm ()) {
3111
3122
auto indexArgTy =
3112
3123
subSGF.silConv .getSILType (signature->getParameters ()[1 ], signature,
3113
3124
subSGF.F .getTypeExpansionContext ());
@@ -3197,6 +3208,7 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
3197
3208
}
3198
3209
}
3199
3210
3211
+ auto Target = SGM.getASTContext ().LangOpts .Target ;
3200
3212
auto genericSig =
3201
3213
genericEnv ? genericEnv->getGenericSignature ().getCanonicalSignature ()
3202
3214
: nullptr ;
@@ -3205,6 +3217,14 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
3205
3217
genericEnv = nullptr ;
3206
3218
}
3207
3219
3220
+ // Add empty generic type parameter to match function signature on WebAssembly
3221
+ if (!genericSig && Target.isOSBinFormatWasm ()) {
3222
+ auto param = GenericTypeParamType::get (false , 0 , 0 , SGM.getASTContext ());
3223
+ auto sig = GenericSignature::get (param, { });
3224
+ genericSig = CanGenericSignature (sig);
3225
+ genericEnv = sig.getGenericEnvironment ();
3226
+ }
3227
+
3208
3228
// Build the signature of the thunk as expected by the keypath runtime.
3209
3229
auto signature = [&]() {
3210
3230
CanType loweredBaseTy, loweredPropTy;
@@ -3230,7 +3250,8 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
3230
3250
? ParameterConvention::Indirect_Inout
3231
3251
: paramConvention});
3232
3252
// indexes
3233
- if (!indexes.empty ())
3253
+ // Always take indexes parameter to match callee and caller signature on WebAssembly
3254
+ if (!indexes.empty () || C.LangOpts .Target .isOSBinFormatWasm ())
3234
3255
params.push_back ({C.getUnsafeRawPointerType ()->getCanonicalType (),
3235
3256
ParameterConvention::Direct_Unowned});
3236
3257
@@ -3286,7 +3307,8 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
3286
3307
auto baseArg = entry->createFunctionArgument (baseArgTy);
3287
3308
SILValue indexPtrArg;
3288
3309
3289
- if (!indexes.empty ()) {
3310
+ // Always take indexes parameter to match callee and caller signature on WebAssembly
3311
+ if (!indexes.empty () || Target.isOSBinFormatWasm ()) {
3290
3312
auto indexArgTy =
3291
3313
subSGF.silConv .getSILType (signature->getParameters ()[2 ], signature,
3292
3314
subSGF.getTypeExpansionContext ());
@@ -3379,6 +3401,7 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
3379
3401
return ;
3380
3402
}
3381
3403
3404
+ auto Target = SGM.getASTContext ().LangOpts .Target ;
3382
3405
auto genericSig =
3383
3406
genericEnv ? genericEnv->getGenericSignature ().getCanonicalSignature ()
3384
3407
: nullptr ;
@@ -3388,6 +3411,14 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
3388
3411
genericEnv = nullptr ;
3389
3412
}
3390
3413
3414
+ // Add empty generic type parameter to match function signature on WebAssembly
3415
+ if (!genericSig && Target.isOSBinFormatWasm ()) {
3416
+ auto param = GenericTypeParamType::get (false , 0 , 0 , SGM.getASTContext ());
3417
+ auto sig = GenericSignature::get (param, { });
3418
+ genericSig = CanGenericSignature (sig);
3419
+ genericEnv = sig.getGenericEnvironment ();
3420
+ }
3421
+
3391
3422
auto &C = SGM.getASTContext ();
3392
3423
auto unsafeRawPointerTy = C.getUnsafeRawPointerType ()->getCanonicalType ();
3393
3424
auto boolTy = C.getBoolType ()->getCanonicalType ();
0 commit comments