Skip to content

Commit d764167

Browse files
committed
Runtime: Fix Windows build
1 parent 560aad7 commit d764167

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

include/swift/ABI/Metadata.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4878,6 +4878,8 @@ class TargetPackPointer {
48784878
using PointerType = typename Runtime::template Pointer<const Pointee<Runtime>>;
48794879

48804880
public:
4881+
explicit TargetPackPointer(typename Runtime::StoredSize rawPtr) : Ptr(rawPtr) {}
4882+
48814883
explicit TargetPackPointer(PointerType const *ptr, PackLifetime lifetime)
48824884
: Ptr(reinterpret_cast<typename Runtime::StoredSize>(ptr) |
48834885
(lifetime == PackLifetime::OnHeap ? 1 : 0)) {}
@@ -4890,6 +4892,11 @@ class TargetPackPointer {
48904892
return reinterpret_cast<PointerType *>(Ptr & ~1);
48914893
}
48924894

4895+
const PointerType *getPointer() const {
4896+
return reinterpret_cast<const PointerType *>(Ptr);
4897+
}
4898+
4899+
48934900
PackLifetime getLifetime() const {
48944901
return (bool)(Ptr & 1) ? PackLifetime::OnHeap : PackLifetime::OnStack;
48954902
}

include/swift/Runtime/Metadata.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,30 +449,30 @@ bool swift_compareProtocolConformanceDescriptors(
449449
///
450450
/// Metadata packs are uniqued by pointer equality on their elements.
451451
///
452-
/// \param pack A pack pointer, where the least significant bit indicates if
452+
/// \param ptr A pack pointer, where the least significant bit indicates if
453453
/// it is already on the heap.
454454
/// \param count The number of metadata pointers in the pack.
455455
///
456456
/// \returns a metadata pack allocated on the heap, with the least significant
457457
/// bit set to true.
458458
SWIFT_RUNTIME_EXPORT SWIFT_CC(swift)
459-
MetadataPackPointer
460-
swift_allocateMetadataPack(MetadataPackPointer pack, unsigned count);
459+
const Metadata * const *
460+
swift_allocateMetadataPack(const Metadata * const *ptr, unsigned count);
461461

462462
/// Allocate a witness table pack on the heap, unless this pack is already on
463463
/// the heap.
464464
///
465465
/// Witness table packs are not uniqued.
466466
///
467-
/// \param pack A pack pointer, where the least significant bit indicates if
467+
/// \param ptr A pack pointer, where the least significant bit indicates if
468468
/// it is already on the heap.
469469
/// \param count The number of witness table pointers in the pack.
470470
///
471471
/// \returns a witness table pack allocated on the heap, with the least
472472
/// significant bit set to true.
473473
SWIFT_RUNTIME_EXPORT SWIFT_CC(swift)
474-
WitnessTablePackPointer
475-
swift_allocateWitnessTablePack(WitnessTablePackPointer pack, unsigned count);
474+
const WitnessTable * const *
475+
swift_allocateWitnessTablePack(const WitnessTable * const *ptr, unsigned count);
476476

477477
/// Fetch a uniqued metadata for a function type.
478478
SWIFT_RUNTIME_EXPORT

stdlib/public/runtime/Metadata.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,31 +1231,33 @@ MetadataPackCacheEntry::MetadataPackCacheEntry(const Key &key) {
12311231
static SimpleGlobalCache<MetadataPackCacheEntry, MetadataPackTag> MetadataPacks;
12321232

12331233
SWIFT_RUNTIME_EXPORT SWIFT_CC(swift)
1234-
MetadataPackPointer
1235-
swift_allocateMetadataPack(MetadataPackPointer pack, unsigned count) {
1236-
if (pack.getLifetime() == PackLifetime::OnHeap)
1237-
return pack;
1234+
const Metadata * const *
1235+
swift_allocateMetadataPack(const Metadata * const *ptr, unsigned count) {
1236+
if (MetadataPackPointer(reinterpret_cast<uintptr_t>(ptr)).getLifetime()
1237+
== PackLifetime::OnHeap)
1238+
return ptr;
12381239

1239-
MetadataPackCacheEntry::Key key{pack.getElements(), count};
1240+
MetadataPackCacheEntry::Key key{ptr, count};
12401241
auto bytes = MetadataPacks.getOrInsert(key).first->getElements();
12411242

1242-
return MetadataPackPointer(bytes, PackLifetime::OnHeap);
1243+
return MetadataPackPointer(bytes, PackLifetime::OnHeap).getPointer();
12431244
}
12441245

12451246
SWIFT_RUNTIME_EXPORT SWIFT_CC(swift)
1246-
WitnessTablePackPointer
1247-
swift_allocateWitnessTablePack(WitnessTablePackPointer pack, unsigned count) {
1248-
if (pack.getLifetime() == PackLifetime::OnHeap)
1249-
return pack;
1247+
const WitnessTable * const *
1248+
swift_allocateWitnessTablePack(const WitnessTable * const *ptr, unsigned count) {
1249+
if (WitnessTablePackPointer(reinterpret_cast<uintptr_t>(ptr)).getLifetime()
1250+
== PackLifetime::OnHeap)
1251+
return ptr;
12501252

12511253
size_t totalSize = (size_t) count * sizeof(const WitnessTable *);
12521254

12531255
auto bytes = (const WitnessTable **)
12541256
MetadataAllocator(WitnessTablePackTag)
12551257
.Allocate(totalSize, alignof(const WitnessTable *));
1256-
memcpy((char*) bytes, pack.getElements(), totalSize);
1258+
memcpy((char*) bytes, ptr, totalSize);
12571259

1258-
return WitnessTablePackPointer(bytes, PackLifetime::OnHeap);
1260+
return WitnessTablePackPointer(bytes, PackLifetime::OnHeap).getPointer();
12591261
}
12601262

12611263
/***************************************************************************/

0 commit comments

Comments
 (0)