Skip to content

[IRGen] Give property behavior conformances protocol conformance descriptors #19553

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
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
26 changes: 17 additions & 9 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,10 +680,7 @@ void IRGenModule::emitRuntimeRegistration() {
}

// Register Swift protocol conformances if we added any.
if (!ProtocolConformances.empty()) {

llvm::Constant *conformances = emitProtocolConformances();

if (llvm::Constant *conformances = emitProtocolConformances()) {
llvm::Constant *beginIndices[] = {
llvm::ConstantInt::get(Int32Ty, 0),
llvm::ConstantInt::get(Int32Ty, 0),
Expand Down Expand Up @@ -2461,18 +2458,29 @@ void IRGenModule::addProtocolConformance(

/// Emit the protocol conformance list and return it.
llvm::Constant *IRGenModule::emitProtocolConformances() {
// Do nothing if the list is empty.
if (ProtocolConformances.empty())
// Emit the conformances.
bool anyReflectedConformances = false;
for (auto *conformance : ProtocolConformances) {
// Emit the protocol conformance now.
emitProtocolConformance(conformance);

if (conformance->isBehaviorConformance())
continue;

anyReflectedConformances = true;
}

if (!anyReflectedConformances)
return nullptr;

// Define the global variable for the conformance list.

ConstantInitBuilder builder(*this);
auto descriptorArray = builder.beginArray(RelativeAddressTy);

for (auto *conformance : ProtocolConformances) {
// Emit the protocol conformance now.
emitProtocolConformance(conformance);
// Behavior conformances cannot be reflected.
if (conformance->isBehaviorConformance())
continue;

auto entity = LinkEntity::forProtocolConformanceDescriptor(conformance);
auto descriptor =
Expand Down
14 changes: 5 additions & 9 deletions lib/IRGen/GenProto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1267,13 +1267,9 @@ llvm::Value *uniqueForeignWitnessTableRef(IRGenFunction &IGF,
/// Add reference to the protocol conformance descriptor that generated
/// this table.
void addProtocolConformanceDescriptor() {
if (Conformance.isBehaviorConformance()) {
Table.addNullPointer(IGM.Int8PtrTy);
} else {
auto descriptor =
IGM.getAddrOfProtocolConformanceDescriptor(&Conformance);
Table.addBitCast(descriptor, IGM.Int8PtrTy);
}
auto descriptor =
IGM.getAddrOfProtocolConformanceDescriptor(&Conformance);
Table.addBitCast(descriptor, IGM.Int8PtrTy);
}

/// A base protocol is witnessed by a pointer to the conformance
Expand Down Expand Up @@ -2483,12 +2479,12 @@ void IRGenModule::emitSILWitnessTable(SILWitnessTable *wt) {
// Always emit an accessor function.
wtableBuilder.buildAccessFunction(global);

addProtocolConformance(conf);

// Behavior conformances can't be reflected.
if (conf->isBehaviorConformance())
return;

addProtocolConformance(conf);

// Trigger the lazy emission of the foreign type metadata.
CanType conformingType = conf->getType()->getCanonicalType();
if (requiresForeignTypeMetadata(conformingType)) {
Expand Down