@@ -1750,29 +1750,79 @@ struct TargetClassMetadata : public TargetHeapMetadata<Runtime> {
1750
1750
};
1751
1751
using ClassMetadata = TargetClassMetadata<InProcess>;
1752
1752
1753
+ // / A key-value pair in a TypeRef -> MetadataSource map.
1754
+ struct GenericMetadataSource {
1755
+ using Key = RelativeDirectPointer<const char >;
1756
+ using Value = Key;
1757
+
1758
+ const Key MangledTypeName;
1759
+ const Value EncodedMetadataSource;
1760
+ };
1761
+
1762
+ // / Describes the layout of a heap closure.
1763
+ // /
1764
+ // / For simplicity's sake and other reasons, this shouldn't contain
1765
+ // / architecture-specifically sized things like direct pointers, uintptr_t, etc.
1766
+ // /
1767
+ // / Following the CaptureDescriptor are:
1768
+ // / - a list of direct relative offsets to the mangled type names of the
1769
+ // / captures (these aren't in the DATA segment, however).
1770
+ // / - a list of GenericMetadataSource objects - each element is a pair of:
1771
+ // / - MangledTypeName (for a GenericTypeParameterTypeRef)
1772
+ // / - EncodededMetadataSource (an encoded string like TypeRefs, but describe
1773
+ // / the method of crawling to the metadata for that generic type parameter.
1774
+ struct CaptureDescriptor {
1775
+ public:
1776
+
1777
+ // / The number of captures in the closure and the number of typerefs that
1778
+ // / immediately follow this struct.
1779
+ const uint32_t NumCaptures;
1780
+
1781
+ // / The number of sources of metadata available in the MetadataSourceMap
1782
+ // / directly following the list of capture's typerefs.
1783
+ const uint32_t NumMetadataSources;
1784
+
1785
+ // / The number of items in the NecessaryBindings structure at the head of
1786
+ // / the closure.
1787
+ const uint32_t NumBindings;
1788
+
1789
+ // / Get the key-value pair for the ith generic metadata source.
1790
+ const GenericMetadataSource &getGenericMetadataSource (size_t i) const {
1791
+ assert (i <= NumMetadataSources &&
1792
+ " Generic metadata source index out of range" );
1793
+ auto Begin = getGenericMetadataSourceBuffer ();
1794
+ return Begin[i];
1795
+ }
1796
+
1797
+ // / Get the typeref (encoded as a mangled type name) of the ith
1798
+ // / closure capture.
1799
+ const RelativeDirectPointer<const char > &
1800
+ getCaptureMangledTypeName (size_t i) const {
1801
+ assert (i <= NumCaptures && " Capture index out of range" );
1802
+ auto Begin = getCaptureTypeRefBuffer ();
1803
+ return Begin[i];
1804
+ }
1805
+
1806
+ private:
1807
+ const GenericMetadataSource *getGenericMetadataSourceBuffer () const {
1808
+ auto BeginTR = reinterpret_cast <const char *>(getCaptureTypeRefBuffer ());
1809
+ auto EndTR = BeginTR + NumCaptures * sizeof (GenericMetadataSource);
1810
+ return reinterpret_cast <const GenericMetadataSource *>(EndTR);
1811
+ }
1812
+
1813
+ const RelativeDirectPointer<const char > *getCaptureTypeRefBuffer () const {
1814
+ return reinterpret_cast <const RelativeDirectPointer<const char > *>(this +1 );
1815
+ }
1816
+ };
1817
+
1753
1818
// / The structure of metadata for heap-allocated local variables.
1754
1819
// / This is non-type metadata.
1755
- // /
1756
- // / It would be nice for tools to be able to dynamically discover the
1757
- // / type of a heap-allocated local variable. This should not require
1758
- // / us to aggressively produce metadata for the type, though. The
1759
- // / obvious solution is to simply place the mangling of the type after
1760
- // / the variable metadata.
1761
- // /
1762
- // / One complication is that, in generic code, we don't want something
1763
- // / as low-priority (sorry!) as the convenience of tools to force us
1764
- // / to generate per-instantiation metadata for capturing variables.
1765
- // / In these cases, the heap-destructor function will be using
1766
- // / information stored in the allocated object (rather than in
1767
- // / metadata) to actually do the work of destruction, but even then,
1768
- // / that information needn't be metadata for the actual variable type;
1769
- // / consider the case of local variable of type (T, Int).
1770
- // /
1771
- // / Anyway, that's all something to consider later.
1772
1820
template <typename Runtime>
1773
1821
struct TargetHeapLocalVariableMetadata
1774
1822
: public TargetHeapMetadata<Runtime> {
1775
- // No extra fields for now.
1823
+ using StoredPointer = typename Runtime::StoredPointer;
1824
+ uint32_t OffsetToFirstCapture;
1825
+ TargetPointer<Runtime, CaptureDescriptor> CaptureDescription;
1776
1826
};
1777
1827
using HeapLocalVariableMetadata
1778
1828
= TargetHeapLocalVariableMetadata<InProcess>;
0 commit comments