@@ -1623,8 +1623,6 @@ class TargetProtocolDescriptorRef {
1623
1623
ProtocolDescriptorPointer protocol,
1624
1624
ProtocolDispatchStrategy dispatchStrategy) {
1625
1625
#if SWIFT_OBJC_INTEROP
1626
- assert (!protocol ||
1627
- protocol->Flags .getDispatchStrategy () == dispatchStrategy);
1628
1626
storage = reinterpret_cast <StoredPointer>(protocol)
1629
1627
| (dispatchStrategy == ProtocolDispatchStrategy::ObjC ? IsObjCBit : 0 );
1630
1628
#else
@@ -1681,7 +1679,8 @@ class TargetProtocolDescriptorRef {
1681
1679
}
1682
1680
#endif
1683
1681
1684
- return getSwiftProtocol ()->Flags .getClassConstraint ();
1682
+ return getSwiftProtocol ()->getProtocolContextDescriptorFlags ()
1683
+ .getClassConstraint ();
1685
1684
}
1686
1685
1687
1686
// / Determine whether this protocol needs a witness table.
@@ -1702,7 +1701,8 @@ class TargetProtocolDescriptorRef {
1702
1701
}
1703
1702
#endif
1704
1703
1705
- return getSwiftProtocol ()->Flags .getSpecialProtocol ();
1704
+ return getSwiftProtocol ()->getProtocolContextDescriptorFlags ()
1705
+ .getSpecialProtocol ();
1706
1706
}
1707
1707
1708
1708
// / Retrieve the Swift protocol descriptor.
@@ -1816,76 +1816,7 @@ struct TargetProtocolRequirement {
1816
1816
1817
1817
using ProtocolRequirement = TargetProtocolRequirement<InProcess>;
1818
1818
1819
- // / A protocol descriptor. This is not type metadata, but is referenced by
1820
- // / existential type metadata records to describe a protocol constraint.
1821
- // / Its layout is compatible with the Objective-C runtime's 'protocol_t' record
1822
- // / layout.
1823
- template <typename Runtime>
1824
- struct TargetProtocolDescriptor {
1825
- using StoredPointer = typename Runtime::StoredPointer;
1826
- // / Unused by the Swift runtime.
1827
- TargetPointer<Runtime, const void > _ObjC_Isa;
1828
-
1829
- // / The mangled name of the protocol.
1830
- TargetPointer<Runtime, const char > Name;
1831
-
1832
- // / The list of protocols this protocol refines.
1833
- ConstTargetMetadataPointer<Runtime, TargetProtocolDescriptorList>
1834
- InheritedProtocols;
1835
-
1836
- // / Unused by the Swift runtime.
1837
- TargetPointer<Runtime, const void >
1838
- _ObjC_InstanceMethods,
1839
- _ObjC_ClassMethods,
1840
- _ObjC_OptionalInstanceMethods,
1841
- _ObjC_OptionalClassMethods,
1842
- _ObjC_InstanceProperties;
1843
-
1844
- // / Size of the descriptor record.
1845
- uint32_t DescriptorSize;
1846
-
1847
- // / Additional flags.
1848
- ProtocolDescriptorFlags Flags;
1849
-
1850
- // / The number of requirements described by the Requirements array.
1851
- // / If any requirements beyond MinimumWitnessTableSizeInWords are present
1852
- // / in the witness table template, they will be not be overwritten with
1853
- // / defaults.
1854
- uint32_t NumRequirements;
1855
-
1856
- // / Requirement descriptions.
1857
- RelativeDirectPointer<TargetProtocolRequirement<Runtime>> Requirements;
1858
-
1859
- // / The superclass of which all conforming types must be a subclass.
1860
- RelativeDirectPointer<const TargetClassMetadata<Runtime>, /* Nullable=*/ true >
1861
- Superclass;
1862
-
1863
- // / Associated type names, as a space-separated list in the same order
1864
- // / as the requirements.
1865
- RelativeDirectPointer<const char , /* Nullable=*/ true > AssociatedTypeNames;
1866
-
1867
- // This is only used in unittests/Metadata.cpp.
1868
- constexpr TargetProtocolDescriptor<Runtime>(const char *Name,
1869
- const TargetProtocolDescriptorList<Runtime> *Inherited,
1870
- ProtocolDescriptorFlags Flags)
1871
- : _ObjC_Isa(nullptr ), Name(Name), InheritedProtocols(Inherited),
1872
- _ObjC_InstanceMethods (nullptr ), _ObjC_ClassMethods(nullptr ),
1873
- _ObjC_OptionalInstanceMethods(nullptr ),
1874
- _ObjC_OptionalClassMethods(nullptr ),
1875
- _ObjC_InstanceProperties(nullptr ),
1876
- DescriptorSize(sizeof (TargetProtocolDescriptor<Runtime>)),
1877
- Flags(Flags),
1878
- NumRequirements(0 ),
1879
- Requirements(nullptr ),
1880
- Superclass(nullptr ),
1881
- AssociatedTypeNames(nullptr )
1882
- {}
1883
-
1884
- #ifndef NDEBUG
1885
- LLVM_ATTRIBUTE_DEPRECATED (void dump () const LLVM_ATTRIBUTE_USED,
1886
- "only for use in the debugger");
1887
- #endif
1888
- };
1819
+ template <typename Runtime> struct TargetProtocolDescriptor ;
1889
1820
using ProtocolDescriptor = TargetProtocolDescriptor<InProcess>;
1890
1821
1891
1822
// / A witness table for a protocol.
@@ -3001,6 +2932,100 @@ struct TargetAnonymousContextDescriptor final
3001
2932
}
3002
2933
};
3003
2934
2935
+ // / A protocol descriptor.
2936
+ // /
2937
+ // / Protocol descriptors contain information about the contents of a protocol:
2938
+ // / it's name, requirements, requirement signature, context, and so on. They
2939
+ // / are used both to identify a protocol and to reason about its contents.
2940
+ // /
2941
+ // / Only Swift protocols are defined by a protocol descriptor, whereas
2942
+ // / Objective-C (including protocols defined in Swift as @objc) use the
2943
+ // / Objective-C protocol layout.
2944
+ template <typename Runtime>
2945
+ struct TargetProtocolDescriptor final
2946
+ : TargetContextDescriptor<Runtime>,
2947
+ TrailingGenericContextObjects<
2948
+ TargetProtocolDescriptor<Runtime>,
2949
+ TargetGenericContextDescriptorHeader,
2950
+ TargetGenericRequirementDescriptor<Runtime>,
2951
+ TargetProtocolRequirement<Runtime>>
2952
+ {
2953
+ private:
2954
+ using TrailingObjects
2955
+ = TrailingGenericContextObjects<
2956
+ TargetProtocolDescriptor<Runtime>,
2957
+ TargetGenericContextDescriptorHeader,
2958
+ TargetGenericRequirementDescriptor<Runtime>,
2959
+ TargetProtocolRequirement<Runtime>>;
2960
+
2961
+ friend TrailingObjects;
2962
+
2963
+ template <typename T>
2964
+ using OverloadToken = typename TrailingObjects::template OverloadToken<T>;
2965
+
2966
+ public:
2967
+ using TrailingObjects::getGenericContext;
2968
+ using TrailingObjects::numTrailingObjects;
2969
+
2970
+ size_t numTrailingObjects (
2971
+ OverloadToken<TargetGenericRequirementDescriptor<Runtime>>) const {
2972
+ return NumRequirementsInSignature;
2973
+ }
2974
+
2975
+ size_t numTrailingObjects (
2976
+ OverloadToken<TargetProtocolRequirement<Runtime>>) const {
2977
+ return NumRequirements;
2978
+ }
2979
+
2980
+
2981
+ // / The name of the protocol.
2982
+ TargetRelativeDirectPointer<Runtime, const char , /* nullable*/ false > Name;
2983
+
2984
+ // / The number of generic requirements in the requirement signature of the
2985
+ // / protocol.
2986
+ uint32_t NumRequirementsInSignature;
2987
+
2988
+ // / The number of requirements in the protocol.
2989
+ // / If any requirements beyond MinimumWitnessTableSizeInWords are present
2990
+ // / in the witness table template, they will be not be overwritten with
2991
+ // / defaults.
2992
+ uint32_t NumRequirements;
2993
+
2994
+ // / Associated type names, as a space-separated list in the same order
2995
+ // / as the requirements.
2996
+ RelativeDirectPointer<const char , /* Nullable=*/ true > AssociatedTypeNames;
2997
+
2998
+ ProtocolContextDescriptorFlags getProtocolContextDescriptorFlags () const {
2999
+ return ProtocolContextDescriptorFlags (this ->Flags .getKindSpecificFlags ());
3000
+ }
3001
+
3002
+ // / Retrieve the requirements that make up the requirement signature of
3003
+ // / this protocol.
3004
+ llvm::ArrayRef<TargetGenericRequirementDescriptor<Runtime>>
3005
+ getRequirementSignature () const {
3006
+ return {this ->template getTrailingObjects <
3007
+ TargetGenericRequirementDescriptor<Runtime>>(),
3008
+ NumRequirementsInSignature};
3009
+ }
3010
+
3011
+ // / Retrieve the requirements of this protocol.
3012
+ llvm::ArrayRef<TargetProtocolRequirement<Runtime>>
3013
+ getRequirements () const {
3014
+ return {this ->template getTrailingObjects <
3015
+ TargetProtocolRequirement<Runtime>>(),
3016
+ NumRequirements};
3017
+ }
3018
+
3019
+ #ifndef NDEBUG
3020
+ LLVM_ATTRIBUTE_DEPRECATED (void dump () const LLVM_ATTRIBUTE_USED,
3021
+ "only for use in the debugger");
3022
+ #endif
3023
+
3024
+ static bool classof (const TargetContextDescriptor<Runtime> *cd) {
3025
+ return cd->getKind () == ContextDescriptorKind::Protocol;
3026
+ }
3027
+ };
3028
+
3004
3029
// / The instantiation cache for generic metadata. This must be guaranteed
3005
3030
// / to zero-initialized before it is first accessed. Its contents are private
3006
3031
// / to the runtime.
0 commit comments