Skip to content

Commit adf33e0

Browse files
committed
Add doc comments
Rename test
1 parent 96fb3d6 commit adf33e0

File tree

6 files changed

+16
-4
lines changed

6 files changed

+16
-4
lines changed

include/swift/AST/FileUnit.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,11 @@ class FileUnit : public DeclContext, public ASTAllocated<FileUnit> {
288288
return nullptr;
289289
}
290290

291-
/// Returns the name to use when referencing entities in this file.
291+
/// Returns the real name of the enclosing module to use when referencing entities in this file.
292+
/// The 'real name' is the actual binary name of the module, which can be different from the 'name'
293+
/// if module aliasing was used (via -module-alias flag).
292294
///
293-
/// Usually this is the module name itself, but certain Clang features allow
295+
/// Usually this is the module real name itself, but certain Clang features allow
294296
/// substituting another name instead.
295297
virtual StringRef getExportedModuleName() const {
296298
return getParentModule()->getRealName().str();

include/swift/ClangImporter/ClangModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ClangModuleUnit final : public LoadedFile {
5959
ModuleDecl *getOverlayModule() const override;
6060

6161
/// Retrieve the "exported" name of the module, which is usually the module
62-
/// name, but might be the name of the public module through which this
62+
/// real name, but might be the name of the public module through which this
6363
/// (private) module is re-exported.
6464
StringRef getExportedModuleName() const override;
6565

lib/AST/Module.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,9 @@ ModuleDecl::ReverseFullNameIterator::ReverseFullNameIterator(
14991499

15001500
StringRef ModuleDecl::ReverseFullNameIterator::operator*() const {
15011501
assert(current && "all name components exhausted");
1502-
1502+
// Return the module's real (binary) name, which can be different from
1503+
// the name if module aliasing was used (-module-alias flag). The real
1504+
// name is used for serialization and loading.
15031505
if (auto *swiftModule = current.dyn_cast<const ModuleDecl *>())
15041506
return swiftModule->getRealName().str();
15051507

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3582,6 +3582,7 @@ StringRef ClangModuleUnit::getExportedModuleName() const {
35823582
if (clangModule && !clangModule->ExportAsModule.empty())
35833583
return clangModule->ExportAsModule;
35843584

3585+
// Return module real name (see FileUnit::getExportedModuleName)
35853586
return getParentModule()->getRealName().str();
35863587
}
35873588

lib/Serialization/Serialization.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,8 @@ IdentifierID Serializer::addModuleRef(const ModuleDecl *module) {
751751
return CURRENT_MODULE_ID;
752752
if (module == this->M->getASTContext().TheBuiltinModule)
753753
return BUILTIN_MODULE_ID;
754+
// Use module 'real name', which can be different from 'name'
755+
// in case module aliasing was used (-module-alias flag)
754756
auto moduleName =
755757
module->getASTContext().getIdentifier(module->getRealName().str());
756758
return addDeclBaseNameRef(moduleName);
@@ -961,6 +963,8 @@ void Serializer::writeHeader(const SerializationOptions &options) {
961963
control_block::RevisionLayout Revision(Out);
962964
control_block::IsOSSALayout IsOSSA(Out);
963965

966+
// Write module 'real name', which can be different from 'name'
967+
// in case module aliasing is used (-module-alias flag)
964968
ModuleName.emit(ScratchRecord, M->getRealName().str());
965969

966970
SmallString<32> versionStringBuf;
@@ -1101,6 +1105,9 @@ void Serializer::writeHeader(const SerializationOptions &options) {
11011105
static void flattenImportPath(const ImportedModule &import,
11021106
SmallVectorImpl<char> &out) {
11031107
llvm::raw_svector_ostream outStream(out);
1108+
// Write module 'real name' (returned by getReverseFullModuleName),
1109+
// which can be different from 'name' in case module aliasing was
1110+
// used (-module-alias flag)
11041111
import.importedModule->getReverseFullModuleName().printForward(
11051112
outStream, StringRef("\0", 1));
11061113

0 commit comments

Comments
 (0)