Serialization: Don't serialize types of various decls

We can recover function, destructor, constructor, enum element
and subscript types from their parameter types and result type
(if present), by calling the AST's various computeType()
methods.

These methods don't do any more work than would be done if
we had deserialized the type and reconstructed it, so let's
just recompute it instead.

Note that we still serialize a ton of function types, due
to XREFs.

With my build configuration, this reduces the size of
Swift.swiftmodule by 237KiB (out of 20MiB).
This commit is contained in:
Slava Pestov
2018-08-10 22:32:52 -07:00
parent cd4909bfa8
commit f3b207ed67
3 changed files with 32 additions and 59 deletions

View File

@@ -3207,8 +3207,8 @@ void Serializer::writeDecl(const Decl *D) {
uint8_t rawDefaultArgumentResilienceExpansion =
getRawStableResilienceExpansion(
fn->getDefaultArgumentResilienceExpansion());
Type ty = fn->getInterfaceType();
Type ty = fn->getInterfaceType();
for (auto dependency : collectDependenciesFromType(ty->getCanonicalType()))
nameComponentsAndDependencies.push_back(addTypeRef(dependency));
@@ -3226,7 +3226,7 @@ void Serializer::writeDecl(const Decl *D) {
fn->hasThrows(),
addGenericEnvironmentRef(
fn->getGenericEnvironment()),
addTypeRef(ty),
addTypeRef(fn->getResultInterfaceType()),
addDeclRef(fn->getOperatorDecl()),
addDeclRef(fn->getOverriddenDecl()),
fn->getFullName().getArgumentNames().size() +
@@ -3263,8 +3263,8 @@ void Serializer::writeDecl(const Decl *D) {
uint8_t rawDefaultArgumentResilienceExpansion =
getRawStableResilienceExpansion(
fn->getDefaultArgumentResilienceExpansion());
Type ty = fn->getInterfaceType();
Type ty = fn->getInterfaceType();
SmallVector<IdentifierID, 4> dependencies;
for (auto dependency : collectDependenciesFromType(ty->getCanonicalType()))
dependencies.push_back(addTypeRef(dependency));
@@ -3283,7 +3283,7 @@ void Serializer::writeDecl(const Decl *D) {
fn->hasThrows(),
addGenericEnvironmentRef(
fn->getGenericEnvironment()),
addTypeRef(ty),
addTypeRef(fn->getResultInterfaceType()),
addDeclRef(fn->getOverriddenDecl()),
addDeclRef(fn->getStorage()),
rawAccessorKind,
@@ -3336,7 +3336,6 @@ void Serializer::writeDecl(const Decl *D) {
unsigned abbrCode = DeclTypeAbbrCodes[EnumElementLayout::Code];
EnumElementLayout::emitRecord(Out, ScratchRecord, abbrCode,
contextID,
addTypeRef(elem->getInterfaceType()),
elem->isImplicit(),
elem->hasAssociatedValues(),
(unsigned)RawValueKind,
@@ -3389,7 +3388,7 @@ void Serializer::writeDecl(const Decl *D) {
accessors.Decls.size(),
addGenericEnvironmentRef(
subscript->getGenericEnvironment()),
addTypeRef(ty),
addTypeRef(subscript->getElementInterfaceType()),
addDeclRef(subscript->getOverriddenDecl()),
rawAccessLevel,
rawSetterAccessLevel,
@@ -3440,7 +3439,6 @@ void Serializer::writeDecl(const Decl *D) {
ctor->getInitKind()),
addGenericEnvironmentRef(
ctor->getGenericEnvironment()),
addTypeRef(ty),
addDeclRef(ctor->getOverriddenDecl()),
rawAccessLevel,
ctor->needsNewVTableEntry(),
@@ -3469,8 +3467,7 @@ void Serializer::writeDecl(const Decl *D) {
dtor->isImplicit(),
dtor->isObjC(),
addGenericEnvironmentRef(
dtor->getGenericEnvironment()),
addTypeRef(dtor->getInterfaceType()));
dtor->getGenericEnvironment()));
break;
}