Skip to content

Commit 7789ce8

Browse files
committed
Serialization: Stop serializing cached rename decls.
Rename decls are typically derived from the rename strings attached to a `@available` attributes. It shouldn't be necessary to serialize the cached rename decls since they can be rederived. The only decls that have rename decls and don't have reanme strings are synthesized by ClangImporter and don't get serialized.
1 parent b6353b0 commit 7789ce8

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5615,15 +5615,14 @@ DeclDeserializer::readAvailable_DECL_ATTR(SmallVectorImpl<uint64_t> &scratch,
56155615
DEF_VER_TUPLE_PIECES(Introduced);
56165616
DEF_VER_TUPLE_PIECES(Deprecated);
56175617
DEF_VER_TUPLE_PIECES(Obsoleted);
5618-
DeclID renameDeclID;
56195618
unsigned rawPlatform, messageSize, renameSize;
56205619

56215620
// Decode the record, pulling the version tuple information.
56225621
serialization::decls_block::AvailableDeclAttrLayout::readRecord(
56235622
scratch, isImplicit, isUnavailable, isDeprecated, isNoAsync,
56245623
isPackageDescriptionVersionSpecific, isSPI, isForEmbedded,
56255624
LIST_VER_TUPLE_PIECES(Introduced), LIST_VER_TUPLE_PIECES(Deprecated),
5626-
LIST_VER_TUPLE_PIECES(Obsoleted), rawPlatform, renameDeclID, messageSize,
5625+
LIST_VER_TUPLE_PIECES(Obsoleted), rawPlatform, messageSize,
56275626
renameSize);
56285627

56295628
auto maybePlatform = platformFromUnsigned(rawPlatform);
@@ -5632,11 +5631,6 @@ DeclDeserializer::readAvailable_DECL_ATTR(SmallVectorImpl<uint64_t> &scratch,
56325631

56335632
PlatformKind platform = maybePlatform.value();
56345633

5635-
ValueDecl *renameDecl = nullptr;
5636-
if (renameDeclID) {
5637-
renameDecl = cast<ValueDecl>(MF.getDecl(renameDeclID));
5638-
}
5639-
56405634
StringRef message = blobData.substr(0, messageSize);
56415635
blobData = blobData.substr(messageSize);
56425636
StringRef rename = blobData.substr(0, renameSize);

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5858
/// describe what change you made. The content of this comment isn't important;
5959
/// it just ensures a conflict if two people change the module format.
6060
/// Don't worry about adhering to the 80-column limit for this line.
61-
const uint16_t SWIFTMODULE_VERSION_MINOR = 903; // @main attribute moved
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 904; // @available renamed decl ID removed
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///
@@ -2352,7 +2352,6 @@ namespace decls_block {
23522352
BC_AVAIL_TUPLE, // Deprecated
23532353
BC_AVAIL_TUPLE, // Obsoleted
23542354
BCVBR<5>, // platform
2355-
DeclIDField, // rename declaration (if any)
23562355
BCVBR<5>, // number of bytes in message string
23572356
BCVBR<5>, // number of bytes in rename string
23582357
BCBlob // message, followed by rename

lib/Serialization/Serialization.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3038,7 +3038,8 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
30383038
ENCODE_VER_TUPLE(Deprecated, theAttr->Deprecated)
30393039
ENCODE_VER_TUPLE(Obsoleted, theAttr->Obsoleted)
30403040

3041-
auto renameDeclID = S.addDeclRef(theAttr->RenameDecl);
3041+
assert(theAttr->Rename.empty() || !theAttr->hasCachedRenamedDecl());
3042+
30423043
llvm::SmallString<32> blob;
30433044
blob.append(theAttr->Message);
30443045
blob.append(theAttr->Rename);
@@ -3056,7 +3057,6 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
30563057
LIST_VER_TUPLE_PIECES(Deprecated),
30573058
LIST_VER_TUPLE_PIECES(Obsoleted),
30583059
static_cast<unsigned>(theAttr->getPlatform()),
3059-
renameDeclID,
30603060
theAttr->Message.size(),
30613061
theAttr->Rename.size(),
30623062
blob);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-frontend -emit-module %t/Library.swift -o %t/Library.swiftmodule
5+
// RUN: %target-swift-frontend -emit-module %t/Renamed.swift -o %t/Renamed.swiftmodule -I %t/
6+
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t/
7+
8+
//--- Library.swift
9+
10+
public struct HasRename {
11+
public init(new: Int) { }
12+
}
13+
14+
//--- Renamed.swift
15+
16+
import Library
17+
18+
extension HasRename {
19+
@available(*, renamed: "init(new:)")
20+
public init(old: Int) {
21+
self.init(new: old)
22+
}
23+
}
24+
25+
//--- Client.swift
26+
27+
import Library
28+
import Renamed
29+
30+
_ = HasRename(old: 0)

0 commit comments

Comments
 (0)