Mangler: Implement hierarchical lookup of generic parameters for the case

where we don't find an ArcheType in the local context.
Fixes rdar://problem/15033772

Swift SVN r8507
This commit is contained in:
Adrian Prantl
2013-09-20 19:00:29 +00:00
parent 62e84f59e4
commit 9f84b92aa4
5 changed files with 36 additions and 16 deletions

View File

@@ -397,6 +397,8 @@ void Mangler::mangleDeclType(ValueDecl *decl, ExplosionKind explosion,
auto result = ClassifyDecl().visit(decl);
assert(result.first || !result.second);
DeclCtx = decl->getDeclContext();
// Bind the contextual archetypes if requested.
llvm::SaveAndRestore<unsigned> oldArchetypesDepth(ArchetypesDepth);
if (result.second) {
@@ -616,12 +618,21 @@ void Mangler::mangleType(CanType type, ExplosionKind explosion,
// archetype ::= 'Qd' <index> <index> # archetype with depth=M+1, index=N
// Mangle generic parameter archetypes.
// Find the archetype information. It may be possible for this to
// fail for local declarations --- that might be okay; it means we
// probably need to insert contexts for all the enclosing contexts.
// And of course, linkage is not critical for such things.
// Find the archetype information.
auto it = Archetypes.find(archetype);
assert(it != Archetypes.end());
while (it == Archetypes.end()) {
// This Archetype comes from an enclosing context -- proceed to
// bind the generic params form all parent contexts.
GenericParamList *GenericParams = nullptr;
do { // Skip over empty parent contexts.
DeclCtx = DeclCtx->getParent();
assert(DeclCtx);
GenericParams = DeclCtx->getGenericParamsOfContext();
} while (!GenericParams);
bindGenericParameters(GenericParams);
it = Archetypes.find(archetype);
}
auto &info = it->second;
assert(ArchetypesDepth >= info.Depth);