Skip to content

Commit 37521ad

Browse files
committed
Serialization: Read and write support for public module name
1 parent 3fe97c2 commit 37521ad

File tree

8 files changed

+34
-1
lines changed

8 files changed

+34
-1
lines changed

Diff for: include/swift/AST/FileUnit.h

+6
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ class FileUnit : public DeclContext, public ASTAllocated<FileUnit> {
335335
return getParentModule()->getRealName().str();
336336
}
337337

338+
/// Returns the public facing name of this module, only if it is set
339+
/// explicitly.
340+
virtual StringRef getPublicModuleName() const {
341+
return {};
342+
}
343+
338344
SWIFT_DEBUG_DUMPER(dumpDisplayDecls());
339345
SWIFT_DEBUG_DUMPER(dumpTopLevelDecls());
340346

Diff for: include/swift/Serialization/SerializedModuleLoader.h

+2
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,8 @@ class SerializedASTFile final : public LoadedFile {
520520

521521
virtual StringRef getExportedModuleName() const override;
522522

523+
virtual StringRef getPublicModuleName() const override;
524+
523525
ValueDecl *getMainDecl() const override;
524526

525527
bool hasEntryPoint() const override;

Diff for: include/swift/Serialization/Validation.h

+4
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class ExtendedValidationInfo {
129129
StringRef ModuleABIName;
130130
StringRef ModulePackageName;
131131
StringRef ExportAsName;
132+
StringRef PublicModuleName;
132133
CXXStdlibKind CXXStdlib;
133134
struct {
134135
unsigned ArePrivateImportsEnabled : 1;
@@ -230,6 +231,9 @@ class ExtendedValidationInfo {
230231
StringRef getModulePackageName() const { return ModulePackageName; }
231232
void setModulePackageName(StringRef name) { ModulePackageName = name; }
232233

234+
StringRef getPublicModuleName() const { return PublicModuleName; }
235+
void setPublicModuleName(StringRef name) { PublicModuleName = name; }
236+
233237
StringRef getExportAsName() const { return ExportAsName; }
234238
void setExportAsName(StringRef name) { ExportAsName = name; }
235239

Diff for: lib/Serialization/ModuleFile.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1398,3 +1398,7 @@ StringRef SerializedASTFile::getExportedModuleName() const {
13981398
return name;
13991399
return FileUnit::getExportedModuleName();
14001400
}
1401+
1402+
StringRef SerializedASTFile::getPublicModuleName() const {
1403+
return File.getPublicModuleName();
1404+
}

Diff for: lib/Serialization/ModuleFile.h

+4
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,10 @@ class ModuleFile
587587
return Core->ModuleExportAsName;
588588
}
589589

590+
StringRef getPublicModuleName() const {
591+
return Core->PublicModuleName;
592+
}
593+
590594
/// The ABI name of the module.
591595
StringRef getModuleABIName() const {
592596
return Core->ModuleABIName;

Diff for: lib/Serialization/ModuleFileSharedCore.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ static bool readOptionsBlock(llvm::BitstreamCursor &cursor,
209209
case options_block::SERIALIZE_PACKAGE_ENABLED:
210210
extendedInfo.setSerializePackageEnabled(true);
211211
break;
212+
case options_block::PUBLIC_MODULE_NAME:
213+
extendedInfo.setPublicModuleName(blobData);
214+
break;
212215
default:
213216
// Unknown options record, possibly for use by a future version of the
214217
// module format.
@@ -1474,6 +1477,7 @@ ModuleFileSharedCore::ModuleFileSharedCore(
14741477
ModuleABIName = extInfo.getModuleABIName();
14751478
ModulePackageName = extInfo.getModulePackageName();
14761479
ModuleExportAsName = extInfo.getExportAsName();
1480+
PublicModuleName = extInfo.getPublicModuleName();
14771481

14781482
hasValidControlBlock = true;
14791483
break;

Diff for: lib/Serialization/ModuleFileSharedCore.h

+3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ class ModuleFileSharedCore {
100100
/// Module name to use when referenced in clients module interfaces.
101101
StringRef ModuleExportAsName;
102102

103+
/// Name to use in public facing diagnostics and documentation.
104+
StringRef PublicModuleName;
105+
103106
/// \c true if this module has incremental dependency information.
104107
bool HasIncrementalInfo = false;
105108

Diff for: lib/Serialization/ModuleFormat.h

+7-1
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 = 887; // extravagant opened existentials
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 888; // public-module-name
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///
@@ -950,6 +950,7 @@ namespace options_block {
950950
ALLOW_NON_RESILIENT_ACCESS,
951951
SERIALIZE_PACKAGE_ENABLED,
952952
CXX_STDLIB_KIND,
953+
PUBLIC_MODULE_NAME,
953954
};
954955

955956
using SDKPathLayout = BCRecordLayout<
@@ -1045,6 +1046,11 @@ namespace options_block {
10451046
using SerializePackageEnabled = BCRecordLayout<
10461047
SERIALIZE_PACKAGE_ENABLED
10471048
>;
1049+
1050+
using PublicModuleNameLayout = BCRecordLayout<
1051+
PUBLIC_MODULE_NAME,
1052+
BCBlob
1053+
>;
10481054
}
10491055

10501056
/// The record types within the input block.

0 commit comments

Comments
 (0)