mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Parsable interface and type reconstruction support for opaque types.
When printing a swiftinterface, represent opaque result types using an attribute that refers to the mangled name of the defining decl for the opaque type. To turn this back into a reference to the right decl's implicit OpaqueTypeDecl, use type reconstruction. Since type reconstruction doesn't normally concern itself with non-type decls, set up a lookup table in SourceFiles and ModuleFiles to let us handle the mapping from mangled name to opaque type decl in type reconstruction. (Since we're invoking type reconstruction during type checking, when the module hasn't yet been fully validated, we need to plumb a LazyResolver into the ASTBuilder in an unsightly way. Maybe there's a better way to do this... Longer term, at least, this surface design gives space for doing things more the right way--a more request-ified decl validator ought to be able to naturally lazily service this request without the LazyResolver reference, and if type reconstruction in the future learns how to reconstruct non-type decls, then the lookup tables can go away.)
This commit is contained in:
@@ -898,6 +898,9 @@ bool ModuleFile::readIndexBlock(llvm::BitstreamCursor &cursor) {
|
||||
case index_block::LOCAL_TYPE_DECLS:
|
||||
LocalTypeDecls = readLocalDeclTable(scratch, blobData);
|
||||
break;
|
||||
case index_block::OPAQUE_RETURN_TYPE_DECLS:
|
||||
OpaqueReturnTypeDecls = readLocalDeclTable(scratch, blobData);
|
||||
break;
|
||||
case index_block::NESTED_TYPE_DECLS:
|
||||
NestedTypeDecls = readNestedTypeDeclsTable(scratch, blobData);
|
||||
break;
|
||||
@@ -1662,6 +1665,19 @@ TypeDecl *ModuleFile::lookupLocalType(StringRef MangledName) {
|
||||
return cast<TypeDecl>(getDecl(*iter));
|
||||
}
|
||||
|
||||
OpaqueTypeDecl *ModuleFile::lookupOpaqueResultType(StringRef MangledName) {
|
||||
PrettyStackTraceModuleFile stackEntry(*this);
|
||||
|
||||
if (!OpaqueReturnTypeDecls)
|
||||
return nullptr;
|
||||
|
||||
auto iter = OpaqueReturnTypeDecls->find(MangledName);
|
||||
if (iter == OpaqueReturnTypeDecls->end())
|
||||
return nullptr;
|
||||
|
||||
return cast<OpaqueTypeDecl>(getDecl(*iter));
|
||||
}
|
||||
|
||||
TypeDecl *ModuleFile::lookupNestedType(Identifier name,
|
||||
const NominalTypeDecl *parent) {
|
||||
PrettyStackTraceModuleFile stackEntry(*this);
|
||||
@@ -2142,6 +2158,19 @@ ModuleFile::getLocalTypeDecls(SmallVectorImpl<TypeDecl *> &results) {
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ModuleFile::getOpaqueReturnTypeDecls(SmallVectorImpl<OpaqueTypeDecl *> &results)
|
||||
{
|
||||
PrettyStackTraceModuleFile stackEntry(*this);
|
||||
if (!OpaqueReturnTypeDecls)
|
||||
return;
|
||||
|
||||
for (auto DeclID : OpaqueReturnTypeDecls->data()) {
|
||||
auto TD = cast<OpaqueTypeDecl>(getDecl(DeclID));
|
||||
results.push_back(TD);
|
||||
}
|
||||
}
|
||||
|
||||
void ModuleFile::getDisplayDecls(SmallVectorImpl<Decl *> &results) {
|
||||
if (ShadowedModule)
|
||||
ShadowedModule->getDisplayDecls(results);
|
||||
|
||||
Reference in New Issue
Block a user