Skip to content

Commit 319d498

Browse files
committed
[Frontend] -Rmodule-loading shows both source path and cached path
1 parent d313760 commit 319d498

File tree

11 files changed

+115
-15
lines changed

11 files changed

+115
-15
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -989,9 +989,10 @@ REMARK(cross_import_added,none,
989989
(Identifier, Identifier, Identifier))
990990

991991
REMARK(module_loaded,none,
992-
"loaded module at %0"
993-
"%select{|; overlay for a clang dependency}1",
994-
(StringRef, unsigned))
992+
"loaded module %0"
993+
"%select{| (overlay for a clang dependency)}1"
994+
"; source: '%2', loaded: '%3'",
995+
(Identifier, unsigned, StringRef, StringRef))
995996

996997
REMARK(explicit_interface_build_skipped,none,
997998
"Skipped rebuilding module at %0 - up-to-date",

include/swift/AST/FileUnit.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,11 @@ class LoadedFile : public FileUnit {
404404
/// This is usually a filesystem path.
405405
virtual StringRef getFilename() const;
406406

407+
/// Get the path to the file loaded by the compiler. Usually the binary
408+
/// swiftmodule file or a pcm in the cache. Returns an empty string if not
409+
/// applicable.
410+
virtual StringRef getLoadedFilename() const { return StringRef(); }
411+
407412
virtual StringRef getFilenameForPrivateDecl(const ValueDecl *decl) const {
408413
return StringRef();
409414
}

include/swift/AST/Module.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,17 @@ class ModuleDecl
840840
/// string if this is not applicable.
841841
StringRef getModuleFilename() const;
842842

843+
/// Get the path to the file defining this module, what we consider the
844+
/// source of truth about the module. Usually a swiftinterface file for a
845+
/// resilient module, a swiftmodule for a non-resilient module, or the
846+
/// modulemap for a clang module. Returns an empty string if not applicable.
847+
StringRef getModuleSourceFilename() const;
848+
849+
/// Get the path to the file loaded by the compiler. Usually the binary
850+
/// swiftmodule file or a pcm in the cache. Returns an empty string if not
851+
/// applicable.
852+
StringRef getModuleLoadedFilename() const;
853+
843854
/// \returns true if this module is the "swift" standard library module.
844855
bool isStdlibModule() const;
845856

include/swift/ClangImporter/ClangModule.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ class ClangModuleUnit final : public LoadedFile {
110110

111111
virtual StringRef getFilename() const override;
112112

113+
virtual StringRef getLoadedFilename() const override;
114+
113115
virtual const clang::Module *getUnderlyingClangModule() const override {
114116
return getClangModule();
115117
}

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ class SerializedASTFile final : public LoadedFile {
451451

452452
virtual StringRef getFilename() const override;
453453

454+
virtual StringRef getLoadedFilename() const override;
455+
454456
virtual StringRef getModuleDefiningPath() const override;
455457

456458
ValueDecl *getMainDecl() const override;

lib/AST/ASTContext.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,8 +2471,10 @@ ASTContext::getModule(ImportPath::Module ModulePath, bool AllowMemoryCached) {
24712471
if (LangOpts.EnableModuleLoadingRemarks) {
24722472
Diags.diagnose(ModulePath.getSourceRange().Start,
24732473
diag::module_loaded,
2474-
M->getModuleFilename(),
2475-
/*overlay=*/false);
2474+
M->getName(),
2475+
/*overlay=*/false,
2476+
M->getModuleSourceFilename(),
2477+
M->getModuleLoadedFilename());
24762478
}
24772479
return M;
24782480
}
@@ -2504,8 +2506,10 @@ ModuleDecl *ASTContext::getOverlayModule(const FileUnit *FU) {
25042506
if (LangOpts.EnableModuleLoadingRemarks) {
25052507
Diags.diagnose(SourceLoc(),
25062508
diag::module_loaded,
2507-
M->getModuleFilename(),
2508-
/*overlay=*/true);
2509+
M->getName(),
2510+
/*overlay=*/true,
2511+
M->getModuleSourceFilename(),
2512+
M->getModuleLoadedFilename());
25092513
}
25102514
return M;
25112515
}

lib/AST/Module.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,6 +1973,25 @@ StringRef ModuleDecl::getModuleFilename() const {
19731973
return Result;
19741974
}
19751975

1976+
StringRef ModuleDecl::getModuleSourceFilename() const {
1977+
for (auto F : getFiles()) {
1978+
if (auto *SFU = dyn_cast<SynthesizedFileUnit>(F))
1979+
continue;
1980+
return F->getModuleDefiningPath();
1981+
}
1982+
1983+
return StringRef();
1984+
}
1985+
1986+
StringRef ModuleDecl::getModuleLoadedFilename() const {
1987+
for (auto F : getFiles()) {
1988+
if (auto LF = dyn_cast<LoadedFile>(F)) {
1989+
return LF->getLoadedFilename();
1990+
}
1991+
}
1992+
return StringRef();
1993+
}
1994+
19761995
bool ModuleDecl::isStdlibModule() const {
19771996
return !getParent() && getName() == getASTContext().StdlibModuleName;
19781997
}

lib/ClangImporter/ClangImporter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3625,6 +3625,12 @@ StringRef ClangModuleUnit::getFilename() const {
36253625
return StringRef();
36263626
}
36273627

3628+
StringRef ClangModuleUnit::getLoadedFilename() const {
3629+
if (const clang::FileEntry *F = clangModule->getASTFile())
3630+
return F->getName();
3631+
return StringRef();
3632+
}
3633+
36283634
clang::TargetInfo &ClangImporter::getTargetInfo() const {
36293635
return Impl.Instance->getTarget();
36303636
}

lib/Serialization/ModuleFile.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,10 @@ class ModuleFile
718718
return Core->ModuleInputBuffer->getBufferIdentifier();
719719
}
720720

721+
StringRef getModuleLoadedFilename() const {
722+
return Core->ModuleInputBuffer->getBufferIdentifier();
723+
}
724+
721725
StringRef getTargetTriple() const {
722726
return Core->TargetTriple;
723727
}

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,10 @@ StringRef SerializedASTFile::getFilename() const {
15701570
return File.getModuleFilename();
15711571
}
15721572

1573+
StringRef SerializedASTFile::getLoadedFilename() const {
1574+
return File.getModuleLoadedFilename();
1575+
}
1576+
15731577
StringRef SerializedASTFile::getTargetTriple() const {
15741578
return File.getTargetTriple();
15751579
}

0 commit comments

Comments
 (0)