Skip to content

Commit 75e1df6

Browse files
committed
[NFC] Minor conveniences for working with metadata.
1 parent 09cfb81 commit 75e1df6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

include/swift/ABI/Metadata.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,11 +625,27 @@ struct TargetMetadata {
625625
getValueWitnesses()->_asEVWT()->destructiveInjectEnumTag(value, tag, this);
626626
}
627627

628+
size_t vw_size() const {
629+
return getValueWitnesses()->getSize();
630+
}
631+
632+
size_t vw_alignment() const {
633+
return getValueWitnesses()->getAlignment();
634+
}
635+
636+
size_t vw_stride() const {
637+
return getValueWitnesses()->getStride();
638+
}
639+
628640
/// Allocate an out-of-line buffer if values of this type don't fit in the
629641
/// ValueBuffer.
630642
/// NOTE: This is not a box for copy-on-write existentials.
631643
OpaqueValue *allocateBufferIn(ValueBuffer *buffer) const;
632644

645+
/// Get the address of the memory previously allocated in the ValueBuffer.
646+
/// NOTE: This is not a box for copy-on-write existentials.
647+
OpaqueValue *projectBufferFrom(ValueBuffer *buffer) const;
648+
633649
/// Deallocate an out-of-line buffer stored in 'buffer' if values of this type
634650
/// are not stored inline in the ValueBuffer.
635651
void deallocateBufferIn(ValueBuffer *buffer) const;

stdlib/public/runtime/Metadata.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3712,6 +3712,13 @@ template <> OpaqueValue *Metadata::allocateBufferIn(ValueBuffer *buffer) const {
37123712
return reinterpret_cast<OpaqueValue *>(ptr);
37133713
}
37143714

3715+
template <> OpaqueValue *Metadata::projectBufferFrom(ValueBuffer *buffer) const{
3716+
auto *vwt = getValueWitnesses();
3717+
if (vwt->isValueInline())
3718+
return reinterpret_cast<OpaqueValue *>(buffer);
3719+
return reinterpret_cast<OpaqueValue *>(buffer->PrivateData[0]);
3720+
}
3721+
37153722
template <> void Metadata::deallocateBufferIn(ValueBuffer *buffer) const {
37163723
auto *vwt = getValueWitnesses();
37173724
if (vwt->isValueInline())

0 commit comments

Comments
 (0)