@@ -2995,6 +2995,7 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
2995
2995
}
2996
2996
}
2997
2997
2998
+ auto Target = SGM.getASTContext ().LangOpts .Target ;
2998
2999
auto genericSig =
2999
3000
genericEnv ? genericEnv->getGenericSignature ().getCanonicalSignature ()
3000
3001
: nullptr ;
@@ -3003,6 +3004,14 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
3003
3004
genericEnv = nullptr ;
3004
3005
}
3005
3006
3007
+ // Add empty generic type parameter to match function signature on WebAssembly
3008
+ if (!genericSig && Target.isOSBinFormatWasm ()) {
3009
+ auto param = GenericTypeParamType::get (false , 0 , 0 , SGM.getASTContext ());
3010
+ auto sig = GenericSignature::get (param, { });
3011
+ genericSig = CanGenericSignature (sig);
3012
+ genericEnv = sig.getGenericEnvironment ();
3013
+ }
3014
+
3006
3015
// Build the signature of the thunk as expected by the keypath runtime.
3007
3016
auto signature = [&]() {
3008
3017
CanType loweredBaseTy, loweredPropTy;
@@ -3018,7 +3027,8 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
3018
3027
SmallVector<SILParameterInfo, 2 > params;
3019
3028
params.push_back ({loweredBaseTy, paramConvention});
3020
3029
auto &C = SGM.getASTContext ();
3021
- if (!indexes.empty ())
3030
+ // Always take indexes parameter to match callee and caller signature on WebAssembly
3031
+ if (!indexes.empty () || C.LangOpts .Target .isOSBinFormatWasm ())
3022
3032
params.push_back ({C.getUnsafeRawPointerType ()->getCanonicalType (),
3023
3033
ParameterConvention::Direct_Unowned});
3024
3034
@@ -3078,7 +3088,8 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
3078
3088
}
3079
3089
auto baseArg = entry->createFunctionArgument (baseArgTy);
3080
3090
SILValue indexPtrArg;
3081
- if (!indexes.empty ()) {
3091
+ // Always take indexes parameter to match callee and caller signature on WebAssembly
3092
+ if (!indexes.empty () || Target.isOSBinFormatWasm ()) {
3082
3093
auto indexArgTy = signature->getParameters ()[1 ].getSILStorageType (
3083
3094
SGM.M , signature, subSGF.F .getTypeExpansionContext ());
3084
3095
indexPtrArg = entry->createFunctionArgument (indexArgTy);
@@ -3167,6 +3178,7 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
3167
3178
}
3168
3179
}
3169
3180
3181
+ auto Target = SGM.getASTContext ().LangOpts .Target ;
3170
3182
auto genericSig =
3171
3183
genericEnv ? genericEnv->getGenericSignature ().getCanonicalSignature ()
3172
3184
: nullptr ;
@@ -3175,6 +3187,14 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
3175
3187
genericEnv = nullptr ;
3176
3188
}
3177
3189
3190
+ // Add empty generic type parameter to match function signature on WebAssembly
3191
+ if (!genericSig && Target.isOSBinFormatWasm ()) {
3192
+ auto param = GenericTypeParamType::get (false , 0 , 0 , SGM.getASTContext ());
3193
+ auto sig = GenericSignature::get (param, { });
3194
+ genericSig = CanGenericSignature (sig);
3195
+ genericEnv = sig.getGenericEnvironment ();
3196
+ }
3197
+
3178
3198
// Build the signature of the thunk as expected by the keypath runtime.
3179
3199
auto signature = [&]() {
3180
3200
CanType loweredBaseTy, loweredPropTy;
@@ -3200,7 +3220,8 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
3200
3220
? ParameterConvention::Indirect_Inout
3201
3221
: paramConvention});
3202
3222
// indexes
3203
- if (!indexes.empty ())
3223
+ // Always take indexes parameter to match callee and caller signature on WebAssembly
3224
+ if (!indexes.empty () || C.LangOpts .Target .isOSBinFormatWasm ())
3204
3225
params.push_back ({C.getUnsafeRawPointerType ()->getCanonicalType (),
3205
3226
ParameterConvention::Direct_Unowned});
3206
3227
@@ -3254,7 +3275,8 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
3254
3275
auto baseArg = entry->createFunctionArgument (baseArgTy);
3255
3276
SILValue indexPtrArg;
3256
3277
3257
- if (!indexes.empty ()) {
3278
+ // Always take indexes parameter to match callee and caller signature on WebAssembly
3279
+ if (!indexes.empty () || Target.isOSBinFormatWasm ()) {
3258
3280
auto indexArgTy = signature->getParameters ()[2 ].getSILStorageType (
3259
3281
SGM.M , signature, subSGF.getTypeExpansionContext ());
3260
3282
indexPtrArg = entry->createFunctionArgument (indexArgTy);
@@ -3344,6 +3366,7 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
3344
3366
return ;
3345
3367
}
3346
3368
3369
+ auto Target = SGM.getASTContext ().LangOpts .Target ;
3347
3370
auto genericSig =
3348
3371
genericEnv ? genericEnv->getGenericSignature ().getCanonicalSignature ()
3349
3372
: nullptr ;
@@ -3353,6 +3376,14 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
3353
3376
genericEnv = nullptr ;
3354
3377
}
3355
3378
3379
+ // Add empty generic type parameter to match function signature on WebAssembly
3380
+ if (!genericSig && Target.isOSBinFormatWasm ()) {
3381
+ auto param = GenericTypeParamType::get (false , 0 , 0 , SGM.getASTContext ());
3382
+ auto sig = GenericSignature::get (param, { });
3383
+ genericSig = CanGenericSignature (sig);
3384
+ genericEnv = sig.getGenericEnvironment ();
3385
+ }
3386
+
3356
3387
auto &C = SGM.getASTContext ();
3357
3388
auto unsafeRawPointerTy = C.getUnsafeRawPointerType ()->getCanonicalType ();
3358
3389
auto boolTy = C.getBoolType ()->getCanonicalType ();
0 commit comments