@@ -2680,6 +2680,7 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
2680
2680
}
2681
2681
}
2682
2682
2683
+ auto Target = SGM.getASTContext ().LangOpts .Target ;
2683
2684
auto genericSig =
2684
2685
genericEnv ? genericEnv->getGenericSignature ().getCanonicalSignature ()
2685
2686
: nullptr ;
@@ -2688,6 +2689,14 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
2688
2689
genericEnv = nullptr ;
2689
2690
}
2690
2691
2692
+ // Add empty generic type parameter to match function signature on WebAssembly
2693
+ if (!genericSig && Target.isOSBinFormatWasm ()) {
2694
+ auto param = GenericTypeParamType::get (0 , 0 , SGM.getASTContext ());
2695
+ auto sig = GenericSignature::get (param, { });
2696
+ genericSig = CanGenericSignature (sig);
2697
+ genericEnv = sig->getGenericEnvironment ();
2698
+ }
2699
+
2691
2700
// Build the signature of the thunk as expected by the keypath runtime.
2692
2701
auto signature = [&]() {
2693
2702
CanType loweredBaseTy, loweredPropTy;
@@ -2703,7 +2712,8 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
2703
2712
SmallVector<SILParameterInfo, 2 > params;
2704
2713
params.push_back ({loweredBaseTy, paramConvention});
2705
2714
auto &C = SGM.getASTContext ();
2706
- if (!indexes.empty ())
2715
+ // Always take indexes parameter to match callee and caller signature on WebAssembly
2716
+ if (!indexes.empty () || C.LangOpts .Target .isOSBinFormatWasm ())
2707
2717
params.push_back ({C.getUnsafeRawPointerDecl ()->getDeclaredType ()
2708
2718
->getCanonicalType (),
2709
2719
ParameterConvention::Direct_Unowned});
@@ -2759,7 +2769,8 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
2759
2769
auto resultArg = entry->createFunctionArgument (resultArgTy);
2760
2770
auto baseArg = entry->createFunctionArgument (baseArgTy);
2761
2771
SILValue indexPtrArg;
2762
- if (!indexes.empty ()) {
2772
+ // Always take indexes parameter to match callee and caller signature on WebAssembly
2773
+ if (!indexes.empty () || Target.isOSBinFormatWasm ()) {
2763
2774
auto indexArgTy = signature->getParameters ()[1 ].getSILStorageType (
2764
2775
SGM.M , signature);
2765
2776
indexPtrArg = entry->createFunctionArgument (indexArgTy);
@@ -2821,6 +2832,7 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
2821
2832
}
2822
2833
}
2823
2834
2835
+ auto Target = SGM.getASTContext ().LangOpts .Target ;
2824
2836
auto genericSig =
2825
2837
genericEnv ? genericEnv->getGenericSignature ().getCanonicalSignature ()
2826
2838
: nullptr ;
@@ -2829,6 +2841,14 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
2829
2841
genericEnv = nullptr ;
2830
2842
}
2831
2843
2844
+ // Add empty generic type parameter to match function signature on WebAssembly
2845
+ if (!genericSig && Target.isOSBinFormatWasm ()) {
2846
+ auto param = GenericTypeParamType::get (0 , 0 , SGM.getASTContext ());
2847
+ auto sig = GenericSignature::get (param, { });
2848
+ genericSig = CanGenericSignature (sig);
2849
+ genericEnv = sig->getGenericEnvironment ();
2850
+ }
2851
+
2832
2852
// Build the signature of the thunk as expected by the keypath runtime.
2833
2853
auto signature = [&]() {
2834
2854
CanType loweredBaseTy, loweredPropTy;
@@ -2854,7 +2874,8 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
2854
2874
? ParameterConvention::Indirect_Inout
2855
2875
: paramConvention});
2856
2876
// indexes
2857
- if (!indexes.empty ())
2877
+ // Always take indexes parameter to match callee and caller signature on WebAssembly
2878
+ if (!indexes.empty () || C.LangOpts .Target .isOSBinFormatWasm ())
2858
2879
params.push_back ({C.getUnsafeRawPointerDecl ()->getDeclaredType ()
2859
2880
->getCanonicalType (),
2860
2881
ParameterConvention::Direct_Unowned});
@@ -2910,7 +2931,8 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
2910
2931
auto baseArg = entry->createFunctionArgument (baseArgTy);
2911
2932
SILValue indexPtrArg;
2912
2933
2913
- if (!indexes.empty ()) {
2934
+ // Always take indexes parameter to match callee and caller signature on WebAssembly
2935
+ if (!indexes.empty () || Target.isOSBinFormatWasm ()) {
2914
2936
auto indexArgTy = signature->getParameters ()[2 ].getSILStorageType (
2915
2937
SGM.M , signature);
2916
2938
indexPtrArg = entry->createFunctionArgument (indexArgTy);
@@ -2992,6 +3014,7 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
2992
3014
return ;
2993
3015
}
2994
3016
3017
+ auto Target = SGM.getASTContext ().LangOpts .Target ;
2995
3018
auto genericSig =
2996
3019
genericEnv ? genericEnv->getGenericSignature ().getCanonicalSignature ()
2997
3020
: nullptr ;
@@ -3001,6 +3024,14 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
3001
3024
genericEnv = nullptr ;
3002
3025
}
3003
3026
3027
+ // Add empty generic type parameter to match function signature on WebAssembly
3028
+ if (!genericSig && Target.isOSBinFormatWasm ()) {
3029
+ auto param = GenericTypeParamType::get (0 , 0 , SGM.getASTContext ());
3030
+ auto sig = GenericSignature::get (param, { });
3031
+ genericSig = CanGenericSignature (sig);
3032
+ genericEnv = sig->getGenericEnvironment ();
3033
+ }
3034
+
3004
3035
auto &C = SGM.getASTContext ();
3005
3036
auto unsafeRawPointerTy = C.getUnsafeRawPointerDecl ()->getDeclaredType ()
3006
3037
->getCanonicalType ();
0 commit comments