@@ -2659,33 +2659,35 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
2659
2659
}
2660
2660
2661
2661
// Build the signature of the thunk as expected by the keypath runtime.
2662
- CanType loweredBaseTy, loweredPropTy;
2663
- AbstractionPattern opaque = AbstractionPattern::getOpaque ();
2662
+ auto signature = [&]() {
2663
+ CanType loweredBaseTy, loweredPropTy;
2664
+ AbstractionPattern opaque = AbstractionPattern::getOpaque ();
2664
2665
2665
- loweredBaseTy = SGM.Types .getLoweredRValueType (
2666
- TypeExpansionContext::minimal (), opaque, baseType);
2667
- loweredPropTy = SGM.Types .getLoweredRValueType (
2668
- TypeExpansionContext::minimal (), opaque, propertyType);
2669
-
2670
- auto paramConvention = ParameterConvention::Indirect_In_Guaranteed;
2666
+ loweredBaseTy = SGM.Types .getLoweredRValueType (
2667
+ TypeExpansionContext::minimal (), opaque, baseType);
2668
+ loweredPropTy = SGM.Types .getLoweredRValueType (
2669
+ TypeExpansionContext::minimal (), opaque, propertyType);
2670
+
2671
+ auto paramConvention = ParameterConvention::Indirect_In_Guaranteed;
2671
2672
2672
- SmallVector<SILParameterInfo, 2 > params;
2673
- params.push_back ({loweredBaseTy, paramConvention});
2674
- auto &C = SGM.getASTContext ();
2675
- if (!indexes.empty ())
2676
- params.push_back ({C.getUnsafeRawPointerDecl ()->getDeclaredType ()
2677
- ->getCanonicalType (),
2678
- ParameterConvention::Direct_Unowned});
2679
-
2680
- SILResultInfo result (loweredPropTy, ResultConvention::Indirect);
2681
-
2682
- auto signature = SILFunctionType::get (genericSig,
2683
- SILFunctionType::ExtInfo::getThin (),
2684
- SILCoroutineKind::None,
2685
- ParameterConvention::Direct_Unowned,
2686
- params, {}, result, None,
2687
- SubstitutionMap (), false ,
2688
- SGM.getASTContext ());
2673
+ SmallVector<SILParameterInfo, 2 > params;
2674
+ params.push_back ({loweredBaseTy, paramConvention});
2675
+ auto &C = SGM.getASTContext ();
2676
+ if (!indexes.empty ())
2677
+ params.push_back ({C.getUnsafeRawPointerDecl ()->getDeclaredType ()
2678
+ ->getCanonicalType (),
2679
+ ParameterConvention::Direct_Unowned});
2680
+
2681
+ SILResultInfo result (loweredPropTy, ResultConvention::Indirect);
2682
+
2683
+ return SILFunctionType::get (genericSig,
2684
+ SILFunctionType::ExtInfo::getThin (),
2685
+ SILCoroutineKind::None,
2686
+ ParameterConvention::Direct_Unowned,
2687
+ params, {}, result, None,
2688
+ SubstitutionMap (), false ,
2689
+ SGM.getASTContext ());
2690
+ }();
2689
2691
2690
2692
// Find the function and see if we already created it.
2691
2693
auto name = Mangle::ASTMangler ()
@@ -2711,9 +2713,15 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
2711
2713
}
2712
2714
2713
2715
SILGenFunction subSGF (SGM, *thunk, SGM.SwiftModule );
2716
+
2717
+ signature = subSGF.F .getLoweredFunctionTypeInContext (
2718
+ subSGF.F .getTypeExpansionContext ());
2719
+
2714
2720
auto entry = thunk->begin ();
2715
- auto resultArgTy = result.getSILStorageType (SGM.M , signature);
2716
- auto baseArgTy = params[0 ].getSILStorageType (SGM.M , signature);
2721
+ auto resultArgTy = signature->getSingleResult ().getSILStorageType (
2722
+ SGM.M , signature);
2723
+ auto baseArgTy = signature->getParameters ()[0 ].getSILStorageType (
2724
+ SGM.M , signature);
2717
2725
if (genericEnv) {
2718
2726
resultArgTy = genericEnv->mapTypeIntoContext (SGM.M , resultArgTy);
2719
2727
baseArgTy = genericEnv->mapTypeIntoContext (SGM.M , baseArgTy);
@@ -2722,7 +2730,8 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
2722
2730
auto baseArg = entry->createFunctionArgument (baseArgTy);
2723
2731
SILValue indexPtrArg;
2724
2732
if (!indexes.empty ()) {
2725
- auto indexArgTy = params[1 ].getSILStorageType (SGM.M , signature);
2733
+ auto indexArgTy = signature->getParameters ()[1 ].getSILStorageType (
2734
+ SGM.M , signature);
2726
2735
indexPtrArg = entry->createFunctionArgument (indexArgTy);
2727
2736
}
2728
2737
@@ -2792,41 +2801,43 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
2792
2801
}
2793
2802
2794
2803
// Build the signature of the thunk as expected by the keypath runtime.
2795
- CanType loweredBaseTy, loweredPropTy;
2796
- {
2797
- AbstractionPattern opaque = AbstractionPattern::getOpaque ();
2804
+ auto signature = [&]() {
2805
+ CanType loweredBaseTy, loweredPropTy;
2806
+ {
2807
+ AbstractionPattern opaque = AbstractionPattern::getOpaque ();
2798
2808
2799
- loweredBaseTy = SGM.Types .getLoweredRValueType (
2800
- TypeExpansionContext::minimal (), opaque, baseType);
2801
- loweredPropTy = SGM.Types .getLoweredRValueType (
2802
- TypeExpansionContext::minimal (), opaque, propertyType);
2803
- }
2804
-
2805
- auto &C = SGM.getASTContext ();
2806
-
2807
- auto paramConvention = ParameterConvention::Indirect_In_Guaranteed;
2808
-
2809
- SmallVector<SILParameterInfo, 3 > params;
2810
- // property value
2811
- params.push_back ({loweredPropTy, paramConvention});
2812
- // base
2813
- params.push_back ({loweredBaseTy,
2814
- property->isSetterMutating ()
2815
- ? ParameterConvention::Indirect_Inout
2816
- : paramConvention});
2817
- // indexes
2818
- if (!indexes.empty ())
2819
- params.push_back ({C.getUnsafeRawPointerDecl ()->getDeclaredType ()
2820
- ->getCanonicalType (),
2821
- ParameterConvention::Direct_Unowned});
2822
-
2823
- auto signature = SILFunctionType::get (genericSig,
2824
- SILFunctionType::ExtInfo::getThin (),
2825
- SILCoroutineKind::None,
2826
- ParameterConvention::Direct_Unowned,
2827
- params, {}, {}, None,
2828
- SubstitutionMap (), false ,
2829
- SGM.getASTContext ());
2809
+ loweredBaseTy = SGM.Types .getLoweredRValueType (
2810
+ TypeExpansionContext::minimal (), opaque, baseType);
2811
+ loweredPropTy = SGM.Types .getLoweredRValueType (
2812
+ TypeExpansionContext::minimal (), opaque, propertyType);
2813
+ }
2814
+
2815
+ auto &C = SGM.getASTContext ();
2816
+
2817
+ auto paramConvention = ParameterConvention::Indirect_In_Guaranteed;
2818
+
2819
+ SmallVector<SILParameterInfo, 3 > params;
2820
+ // property value
2821
+ params.push_back ({loweredPropTy, paramConvention});
2822
+ // base
2823
+ params.push_back ({loweredBaseTy,
2824
+ property->isSetterMutating ()
2825
+ ? ParameterConvention::Indirect_Inout
2826
+ : paramConvention});
2827
+ // indexes
2828
+ if (!indexes.empty ())
2829
+ params.push_back ({C.getUnsafeRawPointerDecl ()->getDeclaredType ()
2830
+ ->getCanonicalType (),
2831
+ ParameterConvention::Direct_Unowned});
2832
+
2833
+ return SILFunctionType::get (genericSig,
2834
+ SILFunctionType::ExtInfo::getThin (),
2835
+ SILCoroutineKind::None,
2836
+ ParameterConvention::Direct_Unowned,
2837
+ params, {}, {}, None,
2838
+ SubstitutionMap (), false ,
2839
+ SGM.getASTContext ());
2840
+ }();
2830
2841
2831
2842
// Mangle the name of the thunk to see if we already created it.
2832
2843
auto name = Mangle::ASTMangler ()
@@ -2853,9 +2864,15 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
2853
2864
}
2854
2865
2855
2866
SILGenFunction subSGF (SGM, *thunk, SGM.SwiftModule );
2867
+
2868
+ signature = subSGF.F .getLoweredFunctionTypeInContext (
2869
+ subSGF.F .getTypeExpansionContext ());
2870
+
2856
2871
auto entry = thunk->begin ();
2857
- auto valueArgTy = params[0 ].getSILStorageType (SGM.M , signature);
2858
- auto baseArgTy = params[1 ].getSILStorageType (SGM.M , signature);
2872
+ auto valueArgTy = signature->getParameters ()[0 ].getSILStorageType (
2873
+ SGM.M , signature);
2874
+ auto baseArgTy = signature->getParameters ()[1 ].getSILStorageType (
2875
+ SGM.M , signature);
2859
2876
if (genericEnv) {
2860
2877
valueArgTy = genericEnv->mapTypeIntoContext (SGM.M , valueArgTy);
2861
2878
baseArgTy = genericEnv->mapTypeIntoContext (SGM.M , baseArgTy);
@@ -2865,7 +2882,8 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
2865
2882
SILValue indexPtrArg;
2866
2883
2867
2884
if (!indexes.empty ()) {
2868
- auto indexArgTy = params[2 ].getSILStorageType (SGM.M , signature);
2885
+ auto indexArgTy = signature->getParameters ()[2 ].getSILStorageType (
2886
+ SGM.M , signature);
2869
2887
indexPtrArg = entry->createFunctionArgument (indexArgTy);
2870
2888
}
2871
2889
0 commit comments