Skip to content

Commit e479e13

Browse files
committed
[Serialization] Use the module interface as the name of the file
...rather than the buffer, for a compiled module that came from a module interface. This was already happening at a higher level (ModuleDecl::getModuleFilename) so pushing it down to the low-level ModuleFile::getModuleFilename doesn't really change things much. The important fix that goes with this is that SerializedASTFile no longer leaks this name by storing it outside of ModuleFile. https://bugs.swift.org/browse/SR-11365
1 parent d8c823e commit e479e13

File tree

7 files changed

+8
-25
lines changed

7 files changed

+8
-25
lines changed

include/swift/AST/Module.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -872,10 +872,6 @@ class FileUnit : public DeclContext {
872872
return getParentModule()->getName().str();
873873
}
874874

875-
/// If this is a module imported from a parseable interface, return the path
876-
/// to the interface file, otherwise an empty StringRef.
877-
virtual StringRef getParseableInterface() const { return {}; }
878-
879875
/// Traverse the decls within this file.
880876
///
881877
/// \returns true if traversal was aborted, false if it completed

include/swift/Serialization/ModuleFile.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ class ModuleFile
7878
/// The target the module was built for.
7979
StringRef TargetTriple;
8080

81+
/// The name of the module interface this module was compiled from.
82+
///
83+
/// Empty if this module didn't come from an interface file.
84+
StringRef ModuleInterfacePath;
85+
8186
/// The Swift compatibility version in use when this module was built.
8287
version::Version CompatibilityVersion;
8388

@@ -762,6 +767,8 @@ class ModuleFile
762767
void getDisplayDecls(SmallVectorImpl<Decl*> &results);
763768

764769
StringRef getModuleFilename() const {
770+
if (!ModuleInterfacePath.empty())
771+
return ModuleInterfacePath;
765772
// FIXME: This seems fragile, maybe store the filename separately ?
766773
return ModuleInputBuffer->getBufferIdentifier();
767774
}

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,6 @@ class SerializedASTFile final : public LoadedFile {
251251

252252
ModuleFile &File;
253253

254-
/// The parseable interface this module was generated from if any.
255-
/// Used for debug info.
256-
std::string ParseableInterface;
257-
258254
bool IsSIB;
259255

260256
~SerializedASTFile() = default;
@@ -351,13 +347,6 @@ class SerializedASTFile final : public LoadedFile {
351347

352348
virtual const clang::Module *getUnderlyingClangModule() const override;
353349

354-
/// If this is a module imported from a parseable interface, return the path
355-
/// to the interface file, otherwise an empty StringRef.
356-
virtual StringRef getParseableInterface() const override {
357-
return ParseableInterface;
358-
}
359-
void setParseableInterface(StringRef PI) { ParseableInterface = PI; }
360-
361350
virtual bool getAllGenericSignatures(
362351
SmallVectorImpl<GenericSignature*> &genericSignatures)
363352
override;

include/swift/Serialization/Validation.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ struct ValidationInfo {
9292
class ExtendedValidationInfo {
9393
SmallVector<StringRef, 4> ExtraClangImporterOpts;
9494
StringRef SDKPath;
95-
StringRef ParseableInterface;
9695
struct {
9796
unsigned ArePrivateImportsEnabled : 1;
9897
unsigned IsSIB : 1;
@@ -114,8 +113,6 @@ class ExtendedValidationInfo {
114113
void addExtraClangImporterOption(StringRef option) {
115114
ExtraClangImporterOpts.push_back(option);
116115
}
117-
StringRef getParseableInterface() const { return ParseableInterface; }
118-
void setParseableInterface(StringRef PI) { ParseableInterface = PI; }
119116

120117
bool isSIB() const { return Bits.IsSIB; }
121118
void setIsSIB(bool val) {

lib/AST/Module.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,10 +1249,6 @@ StringRef ModuleDecl::getModuleFilename() const {
12491249
// per-file names. Modules can consist of more than one file.
12501250
StringRef Result;
12511251
for (auto F : getFiles()) {
1252-
Result = F->getParseableInterface();
1253-
if (!Result.empty())
1254-
return Result;
1255-
12561252
if (auto SF = dyn_cast<SourceFile>(F)) {
12571253
if (!Result.empty())
12581254
return StringRef();

lib/Serialization/ModuleFile.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,8 +1352,7 @@ ModuleFile::ModuleFile(
13521352
break;
13531353
}
13541354
case input_block::PARSEABLE_INTERFACE_PATH: {
1355-
if (extInfo)
1356-
extInfo->setParseableInterface(blobData);
1355+
ModuleInterfacePath = blobData;
13571356
break;
13581357
}
13591358
default:

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,6 @@ FileUnit *SerializedModuleLoaderBase::loadAST(
548548
// We've loaded the file. Now try to bring it into the AST.
549549
auto fileUnit = new (Ctx) SerializedASTFile(M, *loadedModuleFile,
550550
extendedInfo.isSIB());
551-
fileUnit->setParseableInterface(extendedInfo.getParseableInterface());
552551
M.addFile(*fileUnit);
553552
if (extendedInfo.isTestable())
554553
M.setTestingEnabled();

0 commit comments

Comments
 (0)