@@ -2987,6 +2987,7 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
2987
2987
}
2988
2988
}
2989
2989
2990
+ auto Target = SGM.getASTContext ().LangOpts .Target ;
2990
2991
auto genericSig =
2991
2992
genericEnv ? genericEnv->getGenericSignature ().getCanonicalSignature ()
2992
2993
: nullptr ;
@@ -2995,6 +2996,14 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
2995
2996
genericEnv = nullptr ;
2996
2997
}
2997
2998
2999
+ // Add empty generic type parameter to match function signature on WebAssembly
3000
+ if (!genericSig && Target.isOSBinFormatWasm ()) {
3001
+ auto param = GenericTypeParamType::get (false , 0 , 0 , SGM.getASTContext ());
3002
+ auto sig = GenericSignature::get (param, { });
3003
+ genericSig = CanGenericSignature (sig);
3004
+ genericEnv = sig.getGenericEnvironment ();
3005
+ }
3006
+
2998
3007
// Build the signature of the thunk as expected by the keypath runtime.
2999
3008
auto signature = [&]() {
3000
3009
CanType loweredBaseTy, loweredPropTy;
@@ -3010,7 +3019,8 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
3010
3019
SmallVector<SILParameterInfo, 2 > params;
3011
3020
params.push_back ({loweredBaseTy, paramConvention});
3012
3021
auto &C = SGM.getASTContext ();
3013
- if (!indexes.empty ())
3022
+ // Always take indexes parameter to match callee and caller signature on WebAssembly
3023
+ if (!indexes.empty () || C.LangOpts .Target .isOSBinFormatWasm ())
3014
3024
params.push_back ({C.getUnsafeRawPointerType ()->getCanonicalType (),
3015
3025
ParameterConvention::Direct_Unowned});
3016
3026
@@ -3070,7 +3080,8 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
3070
3080
}
3071
3081
auto baseArg = entry->createFunctionArgument (baseArgTy);
3072
3082
SILValue indexPtrArg;
3073
- if (!indexes.empty ()) {
3083
+ // Always take indexes parameter to match callee and caller signature on WebAssembly
3084
+ if (!indexes.empty () || Target.isOSBinFormatWasm ()) {
3074
3085
auto indexArgTy = signature->getParameters ()[1 ].getSILStorageType (
3075
3086
SGM.M , signature, subSGF.F .getTypeExpansionContext ());
3076
3087
indexPtrArg = entry->createFunctionArgument (indexArgTy);
@@ -3159,6 +3170,7 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
3159
3170
}
3160
3171
}
3161
3172
3173
+ auto Target = SGM.getASTContext ().LangOpts .Target ;
3162
3174
auto genericSig =
3163
3175
genericEnv ? genericEnv->getGenericSignature ().getCanonicalSignature ()
3164
3176
: nullptr ;
@@ -3167,6 +3179,14 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
3167
3179
genericEnv = nullptr ;
3168
3180
}
3169
3181
3182
+ // Add empty generic type parameter to match function signature on WebAssembly
3183
+ if (!genericSig && Target.isOSBinFormatWasm ()) {
3184
+ auto param = GenericTypeParamType::get (false , 0 , 0 , SGM.getASTContext ());
3185
+ auto sig = GenericSignature::get (param, { });
3186
+ genericSig = CanGenericSignature (sig);
3187
+ genericEnv = sig.getGenericEnvironment ();
3188
+ }
3189
+
3170
3190
// Build the signature of the thunk as expected by the keypath runtime.
3171
3191
auto signature = [&]() {
3172
3192
CanType loweredBaseTy, loweredPropTy;
@@ -3192,7 +3212,8 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
3192
3212
? ParameterConvention::Indirect_Inout
3193
3213
: paramConvention});
3194
3214
// indexes
3195
- if (!indexes.empty ())
3215
+ // Always take indexes parameter to match callee and caller signature on WebAssembly
3216
+ if (!indexes.empty () || C.LangOpts .Target .isOSBinFormatWasm ())
3196
3217
params.push_back ({C.getUnsafeRawPointerType ()->getCanonicalType (),
3197
3218
ParameterConvention::Direct_Unowned});
3198
3219
@@ -3246,7 +3267,8 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
3246
3267
auto baseArg = entry->createFunctionArgument (baseArgTy);
3247
3268
SILValue indexPtrArg;
3248
3269
3249
- if (!indexes.empty ()) {
3270
+ // Always take indexes parameter to match callee and caller signature on WebAssembly
3271
+ if (!indexes.empty () || Target.isOSBinFormatWasm ()) {
3250
3272
auto indexArgTy = signature->getParameters ()[2 ].getSILStorageType (
3251
3273
SGM.M , signature, subSGF.getTypeExpansionContext ());
3252
3274
indexPtrArg = entry->createFunctionArgument (indexArgTy);
@@ -3336,6 +3358,7 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
3336
3358
return ;
3337
3359
}
3338
3360
3361
+ auto Target = SGM.getASTContext ().LangOpts .Target ;
3339
3362
auto genericSig =
3340
3363
genericEnv ? genericEnv->getGenericSignature ().getCanonicalSignature ()
3341
3364
: nullptr ;
@@ -3345,6 +3368,14 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
3345
3368
genericEnv = nullptr ;
3346
3369
}
3347
3370
3371
+ // Add empty generic type parameter to match function signature on WebAssembly
3372
+ if (!genericSig && Target.isOSBinFormatWasm ()) {
3373
+ auto param = GenericTypeParamType::get (false , 0 , 0 , SGM.getASTContext ());
3374
+ auto sig = GenericSignature::get (param, { });
3375
+ genericSig = CanGenericSignature (sig);
3376
+ genericEnv = sig.getGenericEnvironment ();
3377
+ }
3378
+
3348
3379
auto &C = SGM.getASTContext ();
3349
3380
auto unsafeRawPointerTy = C.getUnsafeRawPointerType ()->getCanonicalType ();
3350
3381
auto boolTy = C.getBoolType ()->getCanonicalType ();
0 commit comments