@@ -173,6 +173,15 @@ enum class SILFunctionTypeRepresentation : uint8_t {
173173 // / constructor). Except for
174174 // / handling the "this" argument, has the same behavior as "CFunctionPointer".
175175 CXXMethod,
176+
177+ // / A KeyPath accessor function, which is thin and also uses the variadic
178+ // / length generic components serialization in trailing buffer.
179+ // / Each representation has a different convention for which parameters
180+ // / have serialized generic type info.
181+ KeyPathAccessorGetter,
182+ KeyPathAccessorSetter,
183+ KeyPathAccessorEquals,
184+ KeyPathAccessorHash,
176185};
177186
178187// / Returns true if the function with this convention doesn't carry a context.
@@ -203,6 +212,10 @@ isThinRepresentation(SILFunctionTypeRepresentation rep) {
203212 case SILFunctionTypeRepresentation::CFunctionPointer:
204213 case SILFunctionTypeRepresentation::Closure:
205214 case SILFunctionTypeRepresentation::CXXMethod:
215+ case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
216+ case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
217+ case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
218+ case SILFunctionTypeRepresentation::KeyPathAccessorHash:
206219 return true ;
207220 }
208221 llvm_unreachable (" Unhandled SILFunctionTypeRepresentation in switch." );
@@ -215,6 +228,31 @@ isThickRepresentation(Repr repr) {
215228 return !isThinRepresentation (repr);
216229}
217230
231+ // / Returns true if the function with this convention receives generic arguments
232+ // / from KeyPath argument buffer.
233+ constexpr bool
234+ isKeyPathAccessorRepresentation (SILFunctionTypeRepresentation rep) {
235+ switch (rep) {
236+ case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
237+ case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
238+ case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
239+ case SILFunctionTypeRepresentation::KeyPathAccessorHash:
240+ return true ;
241+ case SILFunctionTypeRepresentation::Thick:
242+ case SILFunctionTypeRepresentation::Block:
243+ case SILFunctionTypeRepresentation::Thin:
244+ case SILFunctionTypeRepresentation::Method:
245+ case SILFunctionTypeRepresentation::ObjCMethod:
246+ case SILFunctionTypeRepresentation::WitnessMethod:
247+ case SILFunctionTypeRepresentation::CFunctionPointer:
248+ case SILFunctionTypeRepresentation::Closure:
249+ case SILFunctionTypeRepresentation::CXXMethod:
250+ return false ;
251+ }
252+ llvm_unreachable (" Unhandled SILFunctionTypeRepresentation in switch." );
253+ }
254+
255+
218256constexpr SILFunctionTypeRepresentation
219257convertRepresentation (FunctionTypeRepresentation rep) {
220258 switch (rep) {
@@ -246,6 +284,10 @@ convertRepresentation(SILFunctionTypeRepresentation rep) {
246284 case SILFunctionTypeRepresentation::ObjCMethod:
247285 case SILFunctionTypeRepresentation::WitnessMethod:
248286 case SILFunctionTypeRepresentation::Closure:
287+ case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
288+ case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
289+ case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
290+ case SILFunctionTypeRepresentation::KeyPathAccessorHash:
249291 return llvm::None;
250292 }
251293 llvm_unreachable (" Unhandled SILFunctionTypeRepresentation!" );
@@ -265,6 +307,10 @@ constexpr bool canBeCalledIndirectly(SILFunctionTypeRepresentation rep) {
265307 case SILFunctionTypeRepresentation::ObjCMethod:
266308 case SILFunctionTypeRepresentation::Method:
267309 case SILFunctionTypeRepresentation::WitnessMethod:
310+ case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
311+ case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
312+ case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
313+ case SILFunctionTypeRepresentation::KeyPathAccessorHash:
268314 return true ;
269315 }
270316
@@ -286,6 +332,10 @@ template <typename Repr> constexpr bool shouldStoreClangType(Repr repr) {
286332 case SILFunctionTypeRepresentation::Method:
287333 case SILFunctionTypeRepresentation::WitnessMethod:
288334 case SILFunctionTypeRepresentation::Closure:
335+ case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
336+ case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
337+ case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
338+ case SILFunctionTypeRepresentation::KeyPathAccessorHash:
289339 return false ;
290340 }
291341 llvm_unreachable (" Unhandled SILFunctionTypeRepresentation." );
@@ -396,6 +446,10 @@ class ASTExtInfoBuilder {
396446 case SILFunctionTypeRepresentation::Thin:
397447 case SILFunctionTypeRepresentation::CFunctionPointer:
398448 case SILFunctionTypeRepresentation::Closure:
449+ case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
450+ case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
451+ case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
452+ case SILFunctionTypeRepresentation::KeyPathAccessorHash:
399453 return false ;
400454 case SILFunctionTypeRepresentation::ObjCMethod:
401455 case SILFunctionTypeRepresentation::Method:
@@ -634,6 +688,10 @@ SILFunctionLanguage getSILFunctionLanguage(SILFunctionTypeRepresentation rep) {
634688 case SILFunctionTypeRepresentation::Method:
635689 case SILFunctionTypeRepresentation::WitnessMethod:
636690 case SILFunctionTypeRepresentation::Closure:
691+ case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
692+ case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
693+ case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
694+ case SILFunctionTypeRepresentation::KeyPathAccessorHash:
637695 return SILFunctionLanguage::Swift;
638696 }
639697
@@ -652,20 +710,20 @@ class SILExtInfoBuilder {
652710 // and NumMaskBits must be updated, and they must match.
653711
654712 // |representation|pseudogeneric| noescape | concurrent | async
655- // | 0 .. 3 | 4 | 5 | 6 | 7
713+ // | 0 .. 4 | 5 | 6 | 7 | 8
656714 // |differentiability|unimplementable|
657- // | 8 .. 10 | 11 |
715+ // | 9 .. 11 | 12 |
658716 //
659717 enum : unsigned {
660- RepresentationMask = 0xF << 0 ,
661- PseudogenericMask = 1 << 4 ,
662- NoEscapeMask = 1 << 5 ,
663- SendableMask = 1 << 6 ,
664- AsyncMask = 1 << 7 ,
665- DifferentiabilityMaskOffset = 8 ,
718+ RepresentationMask = 0x1F << 0 ,
719+ PseudogenericMask = 1 << 5 ,
720+ NoEscapeMask = 1 << 6 ,
721+ SendableMask = 1 << 7 ,
722+ AsyncMask = 1 << 8 ,
723+ DifferentiabilityMaskOffset = 9 ,
666724 DifferentiabilityMask = 0x7 << DifferentiabilityMaskOffset,
667- UnimplementableMask = 1 << 11 ,
668- NumMaskBits = 12
725+ UnimplementableMask = 1 << 12 ,
726+ NumMaskBits = 13
669727 };
670728
671729 unsigned bits; // Naturally sized for speed.
@@ -765,6 +823,10 @@ class SILExtInfoBuilder {
765823 case Representation::Thin:
766824 case Representation::CFunctionPointer:
767825 case Representation::Closure:
826+ case Representation::KeyPathAccessorGetter:
827+ case Representation::KeyPathAccessorSetter:
828+ case Representation::KeyPathAccessorEquals:
829+ case Representation::KeyPathAccessorHash:
768830 return false ;
769831 case Representation::ObjCMethod:
770832 case Representation::Method:
@@ -788,6 +850,10 @@ class SILExtInfoBuilder {
788850 case Representation::WitnessMethod:
789851 case Representation::Closure:
790852 case SILFunctionTypeRepresentation::CXXMethod:
853+ case Representation::KeyPathAccessorGetter:
854+ case Representation::KeyPathAccessorSetter:
855+ case Representation::KeyPathAccessorEquals:
856+ case Representation::KeyPathAccessorHash:
791857 return false ;
792858 }
793859 llvm_unreachable (" Unhandled Representation in switch." );
0 commit comments