@@ -2689,33 +2689,35 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
2689
2689
}
2690
2690
2691
2691
// Build the signature of the thunk as expected by the keypath runtime.
2692
- CanType loweredBaseTy, loweredPropTy;
2693
- AbstractionPattern opaque = AbstractionPattern::getOpaque ();
2692
+ auto signature = [&]() {
2693
+ CanType loweredBaseTy, loweredPropTy;
2694
+ AbstractionPattern opaque = AbstractionPattern::getOpaque ();
2694
2695
2695
- loweredBaseTy = SGM.Types .getLoweredRValueType (
2696
- TypeExpansionContext::minimal (), opaque, baseType);
2697
- loweredPropTy = SGM.Types .getLoweredRValueType (
2698
- TypeExpansionContext::minimal (), opaque, propertyType);
2699
-
2700
- auto paramConvention = ParameterConvention::Indirect_In_Guaranteed;
2696
+ loweredBaseTy = SGM.Types .getLoweredRValueType (
2697
+ TypeExpansionContext::minimal (), opaque, baseType);
2698
+ loweredPropTy = SGM.Types .getLoweredRValueType (
2699
+ TypeExpansionContext::minimal (), opaque, propertyType);
2700
+
2701
+ auto paramConvention = ParameterConvention::Indirect_In_Guaranteed;
2701
2702
2702
- SmallVector<SILParameterInfo, 2 > params;
2703
- params.push_back ({loweredBaseTy, paramConvention});
2704
- auto &C = SGM.getASTContext ();
2705
- if (!indexes.empty ())
2706
- params.push_back ({C.getUnsafeRawPointerDecl ()->getDeclaredType ()
2707
- ->getCanonicalType (),
2708
- ParameterConvention::Direct_Unowned});
2709
-
2710
- SILResultInfo result (loweredPropTy, ResultConvention::Indirect);
2711
-
2712
- auto signature = SILFunctionType::get (genericSig,
2713
- SILFunctionType::ExtInfo::getThin (),
2714
- SILCoroutineKind::None,
2715
- ParameterConvention::Direct_Unowned,
2716
- params, {}, result, None,
2717
- SubstitutionMap (), false ,
2718
- SGM.getASTContext ());
2703
+ SmallVector<SILParameterInfo, 2 > params;
2704
+ params.push_back ({loweredBaseTy, paramConvention});
2705
+ auto &C = SGM.getASTContext ();
2706
+ if (!indexes.empty ())
2707
+ params.push_back ({C.getUnsafeRawPointerDecl ()->getDeclaredType ()
2708
+ ->getCanonicalType (),
2709
+ ParameterConvention::Direct_Unowned});
2710
+
2711
+ SILResultInfo result (loweredPropTy, ResultConvention::Indirect);
2712
+
2713
+ return SILFunctionType::get (genericSig,
2714
+ SILFunctionType::ExtInfo::getThin (),
2715
+ SILCoroutineKind::None,
2716
+ ParameterConvention::Direct_Unowned,
2717
+ params, {}, result, None,
2718
+ SubstitutionMap (), false ,
2719
+ SGM.getASTContext ());
2720
+ }();
2719
2721
2720
2722
// Find the function and see if we already created it.
2721
2723
auto name = Mangle::ASTMangler ()
@@ -2741,9 +2743,15 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
2741
2743
}
2742
2744
2743
2745
SILGenFunction subSGF (SGM, *thunk, SGM.SwiftModule );
2746
+
2747
+ signature = subSGF.F .getLoweredFunctionTypeInContext (
2748
+ subSGF.F .getTypeExpansionContext ());
2749
+
2744
2750
auto entry = thunk->begin ();
2745
- auto resultArgTy = result.getSILStorageType (SGM.M , signature);
2746
- auto baseArgTy = params[0 ].getSILStorageType (SGM.M , signature);
2751
+ auto resultArgTy = signature->getSingleResult ().getSILStorageType (
2752
+ SGM.M , signature);
2753
+ auto baseArgTy = signature->getParameters ()[0 ].getSILStorageType (
2754
+ SGM.M , signature);
2747
2755
if (genericEnv) {
2748
2756
resultArgTy = genericEnv->mapTypeIntoContext (SGM.M , resultArgTy);
2749
2757
baseArgTy = genericEnv->mapTypeIntoContext (SGM.M , baseArgTy);
@@ -2752,7 +2760,8 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
2752
2760
auto baseArg = entry->createFunctionArgument (baseArgTy);
2753
2761
SILValue indexPtrArg;
2754
2762
if (!indexes.empty ()) {
2755
- auto indexArgTy = params[1 ].getSILStorageType (SGM.M , signature);
2763
+ auto indexArgTy = signature->getParameters ()[1 ].getSILStorageType (
2764
+ SGM.M , signature);
2756
2765
indexPtrArg = entry->createFunctionArgument (indexArgTy);
2757
2766
}
2758
2767
@@ -2821,41 +2830,43 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
2821
2830
}
2822
2831
2823
2832
// Build the signature of the thunk as expected by the keypath runtime.
2824
- CanType loweredBaseTy, loweredPropTy;
2825
- {
2826
- AbstractionPattern opaque = AbstractionPattern::getOpaque ();
2833
+ auto signature = [&]() {
2834
+ CanType loweredBaseTy, loweredPropTy;
2835
+ {
2836
+ AbstractionPattern opaque = AbstractionPattern::getOpaque ();
2827
2837
2828
- loweredBaseTy = SGM.Types .getLoweredRValueType (
2829
- TypeExpansionContext::minimal (), opaque, baseType);
2830
- loweredPropTy = SGM.Types .getLoweredRValueType (
2831
- TypeExpansionContext::minimal (), opaque, propertyType);
2832
- }
2833
-
2834
- auto &C = SGM.getASTContext ();
2835
-
2836
- auto paramConvention = ParameterConvention::Indirect_In_Guaranteed;
2837
-
2838
- SmallVector<SILParameterInfo, 3 > params;
2839
- // property value
2840
- params.push_back ({loweredPropTy, paramConvention});
2841
- // base
2842
- params.push_back ({loweredBaseTy,
2843
- property->isSetterMutating ()
2844
- ? ParameterConvention::Indirect_Inout
2845
- : paramConvention});
2846
- // indexes
2847
- if (!indexes.empty ())
2848
- params.push_back ({C.getUnsafeRawPointerDecl ()->getDeclaredType ()
2849
- ->getCanonicalType (),
2850
- ParameterConvention::Direct_Unowned});
2851
-
2852
- auto signature = SILFunctionType::get (genericSig,
2853
- SILFunctionType::ExtInfo::getThin (),
2854
- SILCoroutineKind::None,
2855
- ParameterConvention::Direct_Unowned,
2856
- params, {}, {}, None,
2857
- SubstitutionMap (), false ,
2858
- SGM.getASTContext ());
2838
+ loweredBaseTy = SGM.Types .getLoweredRValueType (
2839
+ TypeExpansionContext::minimal (), opaque, baseType);
2840
+ loweredPropTy = SGM.Types .getLoweredRValueType (
2841
+ TypeExpansionContext::minimal (), opaque, propertyType);
2842
+ }
2843
+
2844
+ auto &C = SGM.getASTContext ();
2845
+
2846
+ auto paramConvention = ParameterConvention::Indirect_In_Guaranteed;
2847
+
2848
+ SmallVector<SILParameterInfo, 3 > params;
2849
+ // property value
2850
+ params.push_back ({loweredPropTy, paramConvention});
2851
+ // base
2852
+ params.push_back ({loweredBaseTy,
2853
+ property->isSetterMutating ()
2854
+ ? ParameterConvention::Indirect_Inout
2855
+ : paramConvention});
2856
+ // indexes
2857
+ if (!indexes.empty ())
2858
+ params.push_back ({C.getUnsafeRawPointerDecl ()->getDeclaredType ()
2859
+ ->getCanonicalType (),
2860
+ ParameterConvention::Direct_Unowned});
2861
+
2862
+ return SILFunctionType::get (genericSig,
2863
+ SILFunctionType::ExtInfo::getThin (),
2864
+ SILCoroutineKind::None,
2865
+ ParameterConvention::Direct_Unowned,
2866
+ params, {}, {}, None,
2867
+ SubstitutionMap (), false ,
2868
+ SGM.getASTContext ());
2869
+ }();
2859
2870
2860
2871
// Mangle the name of the thunk to see if we already created it.
2861
2872
auto name = Mangle::ASTMangler ()
@@ -2882,9 +2893,15 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
2882
2893
}
2883
2894
2884
2895
SILGenFunction subSGF (SGM, *thunk, SGM.SwiftModule );
2896
+
2897
+ signature = subSGF.F .getLoweredFunctionTypeInContext (
2898
+ subSGF.F .getTypeExpansionContext ());
2899
+
2885
2900
auto entry = thunk->begin ();
2886
- auto valueArgTy = params[0 ].getSILStorageType (SGM.M , signature);
2887
- auto baseArgTy = params[1 ].getSILStorageType (SGM.M , signature);
2901
+ auto valueArgTy = signature->getParameters ()[0 ].getSILStorageType (
2902
+ SGM.M , signature);
2903
+ auto baseArgTy = signature->getParameters ()[1 ].getSILStorageType (
2904
+ SGM.M , signature);
2888
2905
if (genericEnv) {
2889
2906
valueArgTy = genericEnv->mapTypeIntoContext (SGM.M , valueArgTy);
2890
2907
baseArgTy = genericEnv->mapTypeIntoContext (SGM.M , baseArgTy);
@@ -2894,7 +2911,8 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
2894
2911
SILValue indexPtrArg;
2895
2912
2896
2913
if (!indexes.empty ()) {
2897
- auto indexArgTy = params[2 ].getSILStorageType (SGM.M , signature);
2914
+ auto indexArgTy = signature->getParameters ()[2 ].getSILStorageType (
2915
+ SGM.M , signature);
2898
2916
indexPtrArg = entry->createFunctionArgument (indexArgTy);
2899
2917
}
2900
2918
0 commit comments