Skip to content

Commit a268f02

Browse files
authored
Account for -disable-preallocated-instantiation-caches for non-dependent wtables in swift_getWitnessTable (#41199)
1 parent ec07330 commit a268f02

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

include/swift/ABI/Metadata.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,7 +2462,8 @@ struct TargetGenericWitnessTable {
24622462
using PrivateDataType = void *[swift::NumGenericMetadataPrivateDataWords];
24632463

24642464
/// Private data for the instantiator. Out-of-line so that the rest
2465-
/// of this structure can be constant.
2465+
/// of this structure can be constant. Might be null when building with
2466+
/// -disable-preallocated-instantiation-caches.
24662467
RelativeDirectPointer<PrivateDataType> PrivateData;
24672468

24682469
uint16_t getWitnessTablePrivateSizeInWords() const {
@@ -3536,7 +3537,8 @@ using OpaqueTypeDescriptor = TargetOpaqueTypeDescriptor<InProcess>;
35363537
template <typename Runtime>
35373538
struct TargetGenericMetadataInstantiationCache {
35383539
/// Data that the runtime can use for its own purposes. It is guaranteed
3539-
/// to be zero-filled by the compiler.
3540+
/// to be zero-filled by the compiler. Might be null when building with
3541+
/// -disable-preallocated-instantiation-caches.
35403542
TargetPointer<Runtime, void>
35413543
PrivateData[swift::NumGenericMetadataPrivateDataWords];
35423544
};

stdlib/public/runtime/Metadata.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4999,6 +4999,8 @@ WitnessTableCacheEntry::allocate(
49994999
static WitnessTable *
50005000
getNondependentWitnessTable(const ProtocolConformanceDescriptor *conformance,
50015001
const Metadata *type) {
5002+
assert(conformance->getGenericWitnessTable()->PrivateData != nullptr);
5003+
50025004
// Check whether the table has already been instantiated.
50035005
auto tablePtr = reinterpret_cast<std::atomic<WitnessTable*> *>(
50045006
conformance->getGenericWitnessTable()->PrivateData.get());
@@ -5065,7 +5067,8 @@ swift::swift_getWitnessTable(const ProtocolConformanceDescriptor *conformance,
50655067
// least, not today). However, a generic type conformance may also be
50665068
// nondependent if it
50675069
auto typeDescription = conformance->getTypeDescriptor();
5068-
if (typeDescription && !typeDescription->isGeneric()) {
5070+
if (typeDescription && !typeDescription->isGeneric() &&
5071+
genericTable->PrivateData != nullptr) {
50695072
return getNondependentWitnessTable(conformance, type);
50705073
}
50715074

0 commit comments

Comments
 (0)