Eliminate the list of protocols from ExtensionDecl. NFC

Swift SVN r31349
This commit is contained in:
Doug Gregor
2015-08-19 21:33:52 +00:00
parent 83cb1e69bb
commit ee7803a87a
7 changed files with 32 additions and 76 deletions

View File

@@ -1652,9 +1652,6 @@ class ExtensionDecl final : public Decl, public DeclContext,
/// moves the trailing where clause into the generic parameter list.
TrailingWhereClause *TrailingWhere;
/// \brief The set of protocols to which this extension conforms.
ArrayRef<ProtocolDecl *> Protocols;
/// \brief The next extension in the linked list of extensions.
///
/// The bit indicates whether this extension has been resolved to refer to
@@ -1808,19 +1805,6 @@ public:
assert(getMaxAccessibility() == maxAccess && "not enough bits");
}
/// \brief Retrieve the set of protocols to which this extension conforms.
ArrayRef<ProtocolDecl *> getProtocols() const {
return Protocols;
}
void setProtocols(ArrayRef<ProtocolDecl *> protocols) {
Protocols = protocols;
}
void overrideProtocols(ArrayRef<ProtocolDecl *> protocols) {
Protocols = protocols;
}
void setConformanceLoader(LazyMemberLoader *resolver, uint64_t contextData);
DeclRange getMembers(bool forceDelayedMembers = true) const;

View File

@@ -51,7 +51,7 @@ const uint16_t VERSION_MAJOR = 0;
/// To ensure that two separate changes don't silently get merged into one
/// in source control, you should also update the comment to briefly
/// describe what change you made.
const uint16_t VERSION_MINOR = 215; // Last change: nominal inherited lists
const uint16_t VERSION_MINOR = 216; // Last change: extension protocols
using DeclID = Fixnum<31>;
using DeclIDField = BCFixed<31>;
@@ -971,8 +971,8 @@ namespace decls_block {
TypeIDField, // base type
DeclContextIDField, // context decl
BCFixed<1>, // implicit flag
BCVBR<4>, // # of protocols
BCArray<DeclIDField> // protocols and inherited types
BCVBR<4>, // # of protocol conformances
BCArray<TypeIDField> // inherited types
// Trailed by the generic parameter lists, members record, and then
// conformance info (if any).
>;

View File

@@ -3914,19 +3914,16 @@ namespace {
/// given declaration.
void addObjCProtocolConformances(Decl *decl,
ArrayRef<ProtocolDecl*> protocols) {
// Set the protocols.
if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) {
// Copy the list of protocols.
MutableArrayRef<ProtocolDecl *> allProtocols
= Impl.SwiftContext.AllocateCopy(protocols);
// Set the protocols.
if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) {
if (auto proto = dyn_cast<ProtocolDecl>(nominal))
proto->setDirectlyInheritedProtocols(allProtocols);
else
nominal->setProtocols(allProtocols);
} else {
auto ext = cast<ExtensionDecl>(decl);
ext->setProtocols(allProtocols);
}
// Protocols don't require conformances.
@@ -3940,12 +3937,12 @@ namespace {
;
auto dc = decl->getInnermostDeclContext();
auto &ctx = Impl.SwiftContext;
for (unsigned i = 0, n = allProtocols.size(); i != n; ++i) {
for (unsigned i = 0, n = protocols.size(); i != n; ++i) {
// FIXME: Build a superclass conformance if the superclass
// conforms.
auto conformance
= ctx.getConformance(dc->getDeclaredTypeOfContext(),
allProtocols[i], SourceLoc(),
protocols[i], SourceLoc(),
dc,
ProtocolConformanceState::Incomplete);
Impl.scheduleFinishProtocolConformance(conformance);

View File

@@ -561,14 +561,6 @@ void TypeChecker::checkInheritanceClause(Decl *decl,
inherited.setInvalidType(Context);
}
// Record the protocols to which this declaration conforms along with the
// superclass.
if (auto ext = dyn_cast<ExtensionDecl>(decl)) {
assert(!superclassTy && "Extensions can't add superclasses");
ext->setProtocols(Context.AllocateCopy(allProtocols));
return;
}
if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) {
// FIXME: If we already set the protocols, bail out. We'd rather not have
// to check this.
@@ -2877,7 +2869,9 @@ public:
!isPrivateConformer(D));
}
D->overrideProtocols(TC.Context.AllocateCopy(protocols));
if (auto nominal = dyn_cast<NominalTypeDecl>(D)) {
nominal->overrideProtocols(TC.Context.AllocateCopy(protocols));
}
// Diagnose any conflicts attributed to this declaration context.
for (const auto &diag : diagnostics) {
@@ -6468,13 +6462,6 @@ TypeChecker::getDirectConformsTo(NominalTypeDecl *nominal) {
return nominal->getProtocols();
}
ArrayRef<ProtocolDecl *>
TypeChecker::getDirectConformsTo(ExtensionDecl *ext) {
validateExtension(ext);
checkInheritanceClause(ext);
return ext->getProtocols();
}
/// Build a default initializer string for the given pattern.
///
/// This string is suitable for display in diagnostics.

View File

@@ -964,9 +964,6 @@ public:
/// or superclasses need to be extracted separately.
ArrayRef<ProtocolDecl *> getDirectConformsTo(NominalTypeDecl *nominal);
/// Retrieve the set of protocols to which this extension directly conforms.
ArrayRef<ProtocolDecl *> getDirectConformsTo(ExtensionDecl *extension);
/// \brief Add any implicitly-defined constructors required for the given
/// struct or class.
void addImplicitConstructors(NominalTypeDecl *typeDecl);

View File

@@ -3038,12 +3038,12 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
TypeID baseID;
DeclContextID contextID;
bool isImplicit;
unsigned numProtocols;
ArrayRef<uint64_t> rawProtocolAndInheriteIDs;
unsigned numConformances;
ArrayRef<uint64_t> rawInheritedIDs;
decls_block::ExtensionLayout::readRecord(scratch, baseID, contextID,
isImplicit, numProtocols,
rawProtocolAndInheriteIDs);
isImplicit, numConformances,
rawInheritedIDs);
auto DC = getDeclContext(contextID);
if (declOrOffset.isComplete())
@@ -3063,19 +3063,13 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
if (isImplicit)
extension->setImplicit();
auto protocols = ctx.Allocate<ProtocolDecl *>(numProtocols);
for (unsigned i = 0; i != numProtocols; ++i) {
protocols[i] = cast<ProtocolDecl>(getDecl(rawProtocolAndInheriteIDs[i]));
}
extension->setProtocols(protocols);
unsigned numInherited = rawProtocolAndInheriteIDs.size() - numProtocols;
auto inheritedTypes = ctx.Allocate<TypeLoc>(numInherited);
for (unsigned i = 0; i != numInherited; ++i) {
uint64_t rawID = rawProtocolAndInheriteIDs[i + numProtocols];
inheritedTypes[i] = TypeLoc::withoutLoc(getType(rawID));
}
auto inheritedTypes = ctx.Allocate<TypeLoc>(rawInheritedIDs.size());
for_each(inheritedTypes, rawInheritedIDs,
[this](TypeLoc &tl, uint64_t rawID) {
tl = TypeLoc::withoutLoc(getType(rawID));;
});
extension->setInherited(inheritedTypes);
extension->setCheckedInheritanceClause();
// Generic parameters.
GenericParamList *genericParams = maybeReadGenericParams(DC,
@@ -3105,12 +3099,11 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
skipRecord(DeclTypeCursor, decls_block::MEMBERS);
extension->setConformanceLoader(
this,
encodeLazyConformanceContextData(protocols.size(),
encodeLazyConformanceContextData(numConformances,
DeclTypeCursor.GetCurrentBitNo()));
nominal->addExtension(extension);
extension->setValidated(true);
extension->setCheckedInheritanceClause();
break;
}

View File

@@ -1966,20 +1966,21 @@ void Serializer::writeDecl(const Decl *D) {
// parameters.
(void)addDeclRef(baseTy->getAnyNominal());
SmallVector<DeclID, 8> protocolsAndInherited;
for (auto proto : extension->getLocalProtocols())
protocolsAndInherited.push_back(addDeclRef(proto));
unsigned numProtocols = protocolsAndInherited.size();
auto conformances = extension->getLocalConformances(
ConformanceLookupKind::All,
nullptr, /*sorted=*/true);
SmallVector<TypeID, 8> inheritedTypes;
for (auto inherited : extension->getInherited())
protocolsAndInherited.push_back(addTypeRef(inherited.getType()));
inheritedTypes.push_back(addTypeRef(inherited.getType()));
unsigned abbrCode = DeclTypeAbbrCodes[ExtensionLayout::Code];
ExtensionLayout::emitRecord(Out, ScratchRecord, abbrCode,
addTypeRef(baseTy),
contextID,
extension->isImplicit(),
numProtocols,
protocolsAndInherited);
conformances.size(),
inheritedTypes);
bool isClassExtension = false;
if (auto baseNominal = baseTy->getAnyNominal()) {
@@ -1990,10 +1991,7 @@ void Serializer::writeDecl(const Decl *D) {
writeGenericParams(extension->getGenericParams(), DeclTypeAbbrCodes);
writeRequirements(extension->getGenericRequirements());
writeMembers(extension->getMembers(), isClassExtension);
writeConformances(extension->getLocalConformances(
ConformanceLookupKind::All,
nullptr, /*sorted=*/true),
DeclTypeAbbrCodes);
writeConformances(conformances, DeclTypeAbbrCodes);
break;
}