Sink private-file import support down to SerializedASTFile

Implementing it in LoadedFile is nice in theory, but causes a leak in
practice because that type is ASTContext-allocated and usually never
destroyed.

https://bugs.swift.org/browse/SR-11366
This commit is contained in:
Jordan Rose
2019-08-23 17:25:44 -07:00
parent e479e1398d
commit 764e2b8ce6
5 changed files with 15 additions and 22 deletions

View File

@@ -1387,28 +1387,14 @@ protected:
: FileUnit(Kind, M) {
assert(classof(this) && "invalid kind");
}
/// A map from private/fileprivate decls to the file they were defined in.
llvm::DenseMap<const ValueDecl *, Identifier> FilenameForPrivateDecls;
public:
/// Returns an arbitrary string representing the storage backing this file.
///
/// This is usually a filesystem path.
virtual StringRef getFilename() const;
void addFilenameForPrivateDecl(const ValueDecl *decl, Identifier id) {
assert(!FilenameForPrivateDecls.count(decl) ||
FilenameForPrivateDecls[decl] == id);
FilenameForPrivateDecls[decl] = id;
}
StringRef getFilenameForPrivateDecl(const ValueDecl *decl) {
auto it = FilenameForPrivateDecls.find(decl);
if (it == FilenameForPrivateDecls.end())
return StringRef();
return it->second.str();
virtual StringRef getFilenameForPrivateDecl(const ValueDecl *decl) const {
return StringRef();
}
/// Look up an operator declaration.