Serialize local types and provide a lookup API

rdar://problem/18295292

Locally scoped type declarations were previously not serialized into the
module, which meant that the debugger couldn't reason about the
structure of instances of those types.

Introduce a new mangling for local types:
[file basename MD5][counter][identifier]
This allows the demangle node's data to be used directly for lookup
without having to backtrack in the debugger.

Local decls are now serialized into a LOCAL_TYPE_DECLS table in the
module, which acts as the backing hash table for looking up
[file basename MD5][counter][identifier] -> DeclID mappings.

New tests:
* swift-ide-test mode for testing the demangle/lookup/mangle lifecycle
of a module that contains local decls
* mangling
* module merging with local decls

Swift SVN r24426
This commit is contained in:
David Farler
2015-01-14 22:08:47 +00:00
parent e56448b1ee
commit fab3d491d9
44 changed files with 1177 additions and 194 deletions

View File

@@ -1335,6 +1335,9 @@ DeclContext *ModuleFile::getDeclContext(DeclID DID) {
if (DID == 0)
return FileContext;
if (DID == 1)
return FileContext->getDummyLocalContext();
Decl *D = getDecl(DID);
if (auto ND = dyn_cast<NominalTypeDecl>(D))
@@ -1582,11 +1585,11 @@ T *ModuleFile::createDecl(Args &&... args) {
}
Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
if (DID == 0)
if (DID == 0 || DID == 1)
return nullptr;
assert(DID <= Decls.size() && "invalid decl ID");
auto &declOrOffset = Decls[DID-1];
assert(DID <= (Decls.size() + 1) && "invalid decl ID");
auto &declOrOffset = Decls[DID-2];
if (declOrOffset.isComplete())
return declOrOffset;
@@ -1629,7 +1632,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
~DiscriminatorRAII() {
if (!discriminator.empty() && declOrOffset.isComplete())
if (auto value = dyn_cast_or_null<ValueDecl>(declOrOffset.get()))
moduleFile.PrivateDiscriminatorsByValue[value] = discriminator;
moduleFile.DiscriminatorsByValue[value] = discriminator;
}
};
DiscriminatorRAII discriminatorRAII{*this, declOrOffset};