Skip to content

[ABI] Use faux mangled names for associated conformances in witness tables #20472

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
3 changes: 3 additions & 0 deletions docs/ABI/Mangling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ The following symbolic reference kinds are currently implemented:
dependent-associated-conformance ::= '\x05' .{4} // Reference points directly to associated conformance descriptor (NOT IMPLEMENTED)
dependent-associated-conformance ::= '\x06' .{4} // Reference points indirectly to associated conformance descriptor (NOT IMPLEMENTED)

associated-conformance-acceess-function ::= '\x07' .{4} // Reference points directly to associated conformance access function relative to the protocol
associated-conformance-acceess-function ::= '\x08' .{4} // Reference points directly to associated conformance access function relative to the conforming type

Globals
~~~~~~~

Expand Down
4 changes: 4 additions & 0 deletions include/swift/AST/LazyResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class LazyResolver {
/// Mark the given conformance as "used" from the given declaration context.
virtual void markConformanceUsed(ProtocolConformanceRef conformance,
DeclContext *dc) = 0;

/// Fill in the signature conformances of the given protocol conformance.
virtual void checkConformanceRequirements(
NormalProtocolConformance *conformance) = 0;
};

class LazyMemberLoader;
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Runtime/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ MetadataResponse swift_getAssociatedTypeWitness(
///
/// \param wtable The witness table.
/// \param conformingType Metadata for the conforming type.
/// \param assocType Metadata for the sasociated type.
/// \param assocType Metadata for the associated type.
/// \param reqBase "Base" requirement used to compute the witness index
/// \param assocConformance Associated conformance descriptor.
///
Expand Down
8 changes: 8 additions & 0 deletions lib/AST/ProtocolConformance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,14 @@ NormalProtocolConformance::getAssociatedConformance(Type assocType,
LazyResolver *resolver) const {
assert(assocType->isTypeParameter() &&
"associated type must be a type parameter");

// Fill in the signature conformances, if we haven't done so yet.
if (getSignatureConformances().empty()) {
assocType->getASTContext().getLazyResolver()
->checkConformanceRequirements(
const_cast<NormalProtocolConformance *>(this));
}

assert(!getSignatureConformances().empty() &&
"signature conformances not yet computed");

Expand Down
12 changes: 6 additions & 6 deletions lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,15 +788,15 @@ namespace {
continue;

auto witness = entry.getAssociatedTypeProtocolWitness().Witness;
return getDefaultAssociatedConformanceAccessFunction(
AssociatedConformance(Proto, association, requirement),
witness);
AssociatedConformance conformance(Proto, association, requirement);
defineDefaultAssociatedConformanceAccessFunction(conformance, witness);
return IGM.getMangledAssociatedConformance(nullptr, conformance);
}

return nullptr;
}

llvm::Constant *getDefaultAssociatedConformanceAccessFunction(
void defineDefaultAssociatedConformanceAccessFunction(
AssociatedConformance requirement,
ProtocolConformanceRef conformance) {
auto accessor =
Expand Down Expand Up @@ -839,7 +839,7 @@ namespace {
conformance.getConcrete());
auto returnValue = conformanceI->getTable(IGF, &associatedTypeMetadata);
IGF.Builder.CreateRet(returnValue);
return accessor;
return;
}

// For an abstract table, emit a reference to the witness table.
Expand All @@ -852,7 +852,7 @@ namespace {
cast<ArchetypeType>(associatedTypeInContext),
associatedProtocol);
IGF.Builder.CreateRet(returnValue);
return accessor;
return;
}

void addAssociatedTypeNames() {
Expand Down
Loading