@@ -2994,6 +2994,7 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
2994
2994
}
2995
2995
}
2996
2996
2997
+ auto Target = SGM.getASTContext ().LangOpts .Target ;
2997
2998
auto genericSig =
2998
2999
genericEnv ? genericEnv->getGenericSignature ().getCanonicalSignature ()
2999
3000
: nullptr ;
@@ -3002,6 +3003,14 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
3002
3003
genericEnv = nullptr ;
3003
3004
}
3004
3005
3006
+ // Add empty generic type parameter to match function signature on WebAssembly
3007
+ if (!genericSig && Target.isOSBinFormatWasm ()) {
3008
+ auto param = GenericTypeParamType::get (false , 0 , 0 , SGM.getASTContext ());
3009
+ auto sig = GenericSignature::get (param, { });
3010
+ genericSig = CanGenericSignature (sig);
3011
+ genericEnv = sig.getGenericEnvironment ();
3012
+ }
3013
+
3005
3014
// Build the signature of the thunk as expected by the keypath runtime.
3006
3015
auto signature = [&]() {
3007
3016
CanType loweredBaseTy, loweredPropTy;
@@ -3017,7 +3026,8 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
3017
3026
SmallVector<SILParameterInfo, 2 > params;
3018
3027
params.push_back ({loweredBaseTy, paramConvention});
3019
3028
auto &C = SGM.getASTContext ();
3020
- if (!indexes.empty ())
3029
+ // Always take indexes parameter to match callee and caller signature on WebAssembly
3030
+ if (!indexes.empty () || C.LangOpts .Target .isOSBinFormatWasm ())
3021
3031
params.push_back ({C.getUnsafeRawPointerType ()->getCanonicalType (),
3022
3032
ParameterConvention::Direct_Unowned});
3023
3033
@@ -3080,7 +3090,8 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
3080
3090
}
3081
3091
auto baseArg = entry->createFunctionArgument (baseArgTy);
3082
3092
SILValue indexPtrArg;
3083
- if (!indexes.empty ()) {
3093
+ // Always take indexes parameter to match callee and caller signature on WebAssembly
3094
+ if (!indexes.empty () || Target.isOSBinFormatWasm ()) {
3084
3095
auto indexArgTy = signature->getParameters ()[1 ].getSILStorageType (
3085
3096
SGM.M , signature, subSGF.F .getTypeExpansionContext ());
3086
3097
indexPtrArg = entry->createFunctionArgument (indexArgTy);
@@ -3169,6 +3180,7 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
3169
3180
}
3170
3181
}
3171
3182
3183
+ auto Target = SGM.getASTContext ().LangOpts .Target ;
3172
3184
auto genericSig =
3173
3185
genericEnv ? genericEnv->getGenericSignature ().getCanonicalSignature ()
3174
3186
: nullptr ;
@@ -3177,6 +3189,14 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
3177
3189
genericEnv = nullptr ;
3178
3190
}
3179
3191
3192
+ // Add empty generic type parameter to match function signature on WebAssembly
3193
+ if (!genericSig && Target.isOSBinFormatWasm ()) {
3194
+ auto param = GenericTypeParamType::get (false , 0 , 0 , SGM.getASTContext ());
3195
+ auto sig = GenericSignature::get (param, { });
3196
+ genericSig = CanGenericSignature (sig);
3197
+ genericEnv = sig.getGenericEnvironment ();
3198
+ }
3199
+
3180
3200
// Build the signature of the thunk as expected by the keypath runtime.
3181
3201
auto signature = [&]() {
3182
3202
CanType loweredBaseTy, loweredPropTy;
@@ -3202,7 +3222,8 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
3202
3222
? ParameterConvention::Indirect_Inout
3203
3223
: paramConvention});
3204
3224
// indexes
3205
- if (!indexes.empty ())
3225
+ // Always take indexes parameter to match callee and caller signature on WebAssembly
3226
+ if (!indexes.empty () || C.LangOpts .Target .isOSBinFormatWasm ())
3206
3227
params.push_back ({C.getUnsafeRawPointerType ()->getCanonicalType (),
3207
3228
ParameterConvention::Direct_Unowned});
3208
3229
@@ -3259,7 +3280,8 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
3259
3280
auto baseArg = entry->createFunctionArgument (baseArgTy);
3260
3281
SILValue indexPtrArg;
3261
3282
3262
- if (!indexes.empty ()) {
3283
+ // Always take indexes parameter to match callee and caller signature on WebAssembly
3284
+ if (!indexes.empty () || Target.isOSBinFormatWasm ()) {
3263
3285
auto indexArgTy = signature->getParameters ()[2 ].getSILStorageType (
3264
3286
SGM.M , signature, subSGF.getTypeExpansionContext ());
3265
3287
indexPtrArg = entry->createFunctionArgument (indexArgTy);
@@ -3350,6 +3372,7 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
3350
3372
return ;
3351
3373
}
3352
3374
3375
+ auto Target = SGM.getASTContext ().LangOpts .Target ;
3353
3376
auto genericSig =
3354
3377
genericEnv ? genericEnv->getGenericSignature ().getCanonicalSignature ()
3355
3378
: nullptr ;
@@ -3359,6 +3382,14 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
3359
3382
genericEnv = nullptr ;
3360
3383
}
3361
3384
3385
+ // Add empty generic type parameter to match function signature on WebAssembly
3386
+ if (!genericSig && Target.isOSBinFormatWasm ()) {
3387
+ auto param = GenericTypeParamType::get (false , 0 , 0 , SGM.getASTContext ());
3388
+ auto sig = GenericSignature::get (param, { });
3389
+ genericSig = CanGenericSignature (sig);
3390
+ genericEnv = sig.getGenericEnvironment ();
3391
+ }
3392
+
3362
3393
auto &C = SGM.getASTContext ();
3363
3394
auto unsafeRawPointerTy = C.getUnsafeRawPointerType ()->getCanonicalType ();
3364
3395
auto boolTy = C.getBoolType ()->getCanonicalType ();
0 commit comments