Skip to content

Account for -disable-preallocated-instantiation-caches for non-dependent wtables in swift_getWitnessTable #41199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions include/swift/ABI/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -2462,7 +2462,8 @@ struct TargetGenericWitnessTable {
using PrivateDataType = void *[swift::NumGenericMetadataPrivateDataWords];

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

uint16_t getWitnessTablePrivateSizeInWords() const {
Expand Down Expand Up @@ -3536,7 +3537,8 @@ using OpaqueTypeDescriptor = TargetOpaqueTypeDescriptor<InProcess>;
template <typename Runtime>
struct TargetGenericMetadataInstantiationCache {
/// Data that the runtime can use for its own purposes. It is guaranteed
/// to be zero-filled by the compiler.
/// to be zero-filled by the compiler. Might be null when building with
/// -disable-preallocated-instantiation-caches.
TargetPointer<Runtime, void>
PrivateData[swift::NumGenericMetadataPrivateDataWords];
};
Expand Down
5 changes: 4 additions & 1 deletion stdlib/public/runtime/Metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4999,6 +4999,8 @@ WitnessTableCacheEntry::allocate(
static WitnessTable *
getNondependentWitnessTable(const ProtocolConformanceDescriptor *conformance,
const Metadata *type) {
assert(conformance->getGenericWitnessTable()->PrivateData != nullptr);

// Check whether the table has already been instantiated.
auto tablePtr = reinterpret_cast<std::atomic<WitnessTable*> *>(
conformance->getGenericWitnessTable()->PrivateData.get());
Expand Down Expand Up @@ -5065,7 +5067,8 @@ swift::swift_getWitnessTable(const ProtocolConformanceDescriptor *conformance,
// least, not today). However, a generic type conformance may also be
// nondependent if it
auto typeDescription = conformance->getTypeDescriptor();
if (typeDescription && !typeDescription->isGeneric()) {
if (typeDescription && !typeDescription->isGeneric() &&
genericTable->PrivateData != nullptr) {
return getNondependentWitnessTable(conformance, type);
}

Expand Down