@@ -172,6 +172,14 @@ enum class SILFunctionTypeRepresentation : uint8_t {
172172 // / constructor). Except for
173173 // / handling the "this" argument, has the same behavior as "CFunctionPointer".
174174 CXXMethod,
175+
176+ // / A KeyPath accessor function, which is thin and also uses the variadic
177+ // / length
178+ // / generic components serialization in trailing buffer.
179+ KeyPathAccessorGetter,
180+ KeyPathAccessorSetter,
181+ KeyPathAccessorEquals,
182+ KeyPathAccessorHash,
175183};
176184
177185// / Returns true if the function with this convention doesn't carry a context.
@@ -202,6 +210,10 @@ isThinRepresentation(SILFunctionTypeRepresentation rep) {
202210 case SILFunctionTypeRepresentation::CFunctionPointer:
203211 case SILFunctionTypeRepresentation::Closure:
204212 case SILFunctionTypeRepresentation::CXXMethod:
213+ case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
214+ case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
215+ case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
216+ case SILFunctionTypeRepresentation::KeyPathAccessorHash:
205217 return true ;
206218 }
207219 llvm_unreachable (" Unhandled SILFunctionTypeRepresentation in switch." );
@@ -214,6 +226,31 @@ isThickRepresentation(Repr repr) {
214226 return !isThinRepresentation (repr);
215227}
216228
229+ // / Returns true if the function with this convention receives generic arguments
230+ // / from KeyPath argument buffer.
231+ constexpr bool
232+ isKeyPathAccessorRepresentation (SILFunctionTypeRepresentation rep) {
233+ switch (rep) {
234+ case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
235+ case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
236+ case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
237+ case SILFunctionTypeRepresentation::KeyPathAccessorHash:
238+ return true ;
239+ case SILFunctionTypeRepresentation::Thick:
240+ case SILFunctionTypeRepresentation::Block:
241+ case SILFunctionTypeRepresentation::Thin:
242+ case SILFunctionTypeRepresentation::Method:
243+ case SILFunctionTypeRepresentation::ObjCMethod:
244+ case SILFunctionTypeRepresentation::WitnessMethod:
245+ case SILFunctionTypeRepresentation::CFunctionPointer:
246+ case SILFunctionTypeRepresentation::Closure:
247+ case SILFunctionTypeRepresentation::CXXMethod:
248+ return false ;
249+ }
250+ llvm_unreachable (" Unhandled SILFunctionTypeRepresentation in switch." );
251+ }
252+
253+
217254constexpr SILFunctionTypeRepresentation
218255convertRepresentation (FunctionTypeRepresentation rep) {
219256 switch (rep) {
@@ -245,6 +282,10 @@ convertRepresentation(SILFunctionTypeRepresentation rep) {
245282 case SILFunctionTypeRepresentation::ObjCMethod:
246283 case SILFunctionTypeRepresentation::WitnessMethod:
247284 case SILFunctionTypeRepresentation::Closure:
285+ case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
286+ case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
287+ case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
288+ case SILFunctionTypeRepresentation::KeyPathAccessorHash:
248289 return None;
249290 }
250291 llvm_unreachable (" Unhandled SILFunctionTypeRepresentation!" );
@@ -264,6 +305,10 @@ constexpr bool canBeCalledIndirectly(SILFunctionTypeRepresentation rep) {
264305 case SILFunctionTypeRepresentation::ObjCMethod:
265306 case SILFunctionTypeRepresentation::Method:
266307 case SILFunctionTypeRepresentation::WitnessMethod:
308+ case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
309+ case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
310+ case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
311+ case SILFunctionTypeRepresentation::KeyPathAccessorHash:
267312 return true ;
268313 }
269314
@@ -285,6 +330,10 @@ template <typename Repr> constexpr bool shouldStoreClangType(Repr repr) {
285330 case SILFunctionTypeRepresentation::Method:
286331 case SILFunctionTypeRepresentation::WitnessMethod:
287332 case SILFunctionTypeRepresentation::Closure:
333+ case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
334+ case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
335+ case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
336+ case SILFunctionTypeRepresentation::KeyPathAccessorHash:
288337 return false ;
289338 }
290339 llvm_unreachable (" Unhandled SILFunctionTypeRepresentation." );
@@ -395,6 +444,10 @@ class ASTExtInfoBuilder {
395444 case SILFunctionTypeRepresentation::Thin:
396445 case SILFunctionTypeRepresentation::CFunctionPointer:
397446 case SILFunctionTypeRepresentation::Closure:
447+ case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
448+ case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
449+ case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
450+ case SILFunctionTypeRepresentation::KeyPathAccessorHash:
398451 return false ;
399452 case SILFunctionTypeRepresentation::ObjCMethod:
400453 case SILFunctionTypeRepresentation::Method:
@@ -633,6 +686,10 @@ SILFunctionLanguage getSILFunctionLanguage(SILFunctionTypeRepresentation rep) {
633686 case SILFunctionTypeRepresentation::Method:
634687 case SILFunctionTypeRepresentation::WitnessMethod:
635688 case SILFunctionTypeRepresentation::Closure:
689+ case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
690+ case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
691+ case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
692+ case SILFunctionTypeRepresentation::KeyPathAccessorHash:
636693 return SILFunctionLanguage::Swift;
637694 }
638695
@@ -651,17 +708,17 @@ class SILExtInfoBuilder {
651708 // and NumMaskBits must be updated, and they must match.
652709
653710 // |representation|pseudogeneric| noescape | concurrent | async |differentiability|
654- // | 0 .. 3 | 4 | 5 | 6 | 7 | 8 .. 10 |
711+ // | 0 .. 4 | 5 | 6 | 7 | 8 | 9 .. 11 |
655712 //
656713 enum : unsigned {
657- RepresentationMask = 0xF << 0 ,
658- PseudogenericMask = 1 << 4 ,
659- NoEscapeMask = 1 << 5 ,
660- SendableMask = 1 << 6 ,
661- AsyncMask = 1 << 7 ,
662- DifferentiabilityMaskOffset = 8 ,
714+ RepresentationMask = 0x1F << 0 ,
715+ PseudogenericMask = 1 << 5 ,
716+ NoEscapeMask = 1 << 6 ,
717+ SendableMask = 1 << 7 ,
718+ AsyncMask = 1 << 8 ,
719+ DifferentiabilityMaskOffset = 9 ,
663720 DifferentiabilityMask = 0x7 << DifferentiabilityMaskOffset,
664- NumMaskBits = 11
721+ NumMaskBits = 12
665722 };
666723
667724 unsigned bits; // Naturally sized for speed.
@@ -755,6 +812,10 @@ class SILExtInfoBuilder {
755812 case Representation::Thin:
756813 case Representation::CFunctionPointer:
757814 case Representation::Closure:
815+ case Representation::KeyPathAccessorGetter:
816+ case Representation::KeyPathAccessorSetter:
817+ case Representation::KeyPathAccessorEquals:
818+ case Representation::KeyPathAccessorHash:
758819 return false ;
759820 case Representation::ObjCMethod:
760821 case Representation::Method:
@@ -778,6 +839,10 @@ class SILExtInfoBuilder {
778839 case Representation::WitnessMethod:
779840 case Representation::Closure:
780841 case SILFunctionTypeRepresentation::CXXMethod:
842+ case Representation::KeyPathAccessorGetter:
843+ case Representation::KeyPathAccessorSetter:
844+ case Representation::KeyPathAccessorEquals:
845+ case Representation::KeyPathAccessorHash:
781846 return false ;
782847 }
783848 llvm_unreachable (" Unhandled Representation in switch." );
0 commit comments