Skip to content

Commit 490c26f

Browse files
committed
AST: Remove a usage of TypeSubstitutionMap
1 parent f8b667a commit 490c26f

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

lib/AST/ASTDemangler.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -305,29 +305,29 @@ Type ASTBuilder::createBoundGenericType(GenericTypeDecl *decl,
305305
if (auto *nominalDecl = dyn_cast<NominalTypeDecl>(decl))
306306
return BoundGenericType::get(nominalDecl, parent, args);
307307

308-
// Combine the substitutions from our parent type with our generic
309-
// arguments.
310-
TypeSubstitutionMap subs;
311-
if (parent)
312-
subs = parent->getContextSubstitutions(decl->getDeclContext());
313-
314308
auto *aliasDecl = cast<TypeAliasDecl>(decl);
309+
auto *dc = aliasDecl->getDeclContext();
315310

316-
auto genericSig = aliasDecl->getGenericSignature();
317-
for (unsigned i = 0, e = args.size(); i < e; ++i) {
318-
auto origTy = genericSig.getInnermostGenericParams()[i];
319-
auto substTy = args[i];
311+
SmallVector<Type, 2> subs;
320312

321-
subs[origTy->getCanonicalType()->castTo<GenericTypeParamType>()] =
322-
substTy;
313+
// Combine the substitutions from our parent type with our generic
314+
// arguments.
315+
if (dc->isLocalContext()) {
316+
for (auto *param : dc->getGenericSignatureOfContext().getGenericParams()) {
317+
subs.push_back(param);
318+
}
319+
} else if (parent) {
320+
auto parentSubs = parent->getContextSubstitutionMap(
321+
dc).getReplacementTypes();
322+
subs.append(parentSubs.begin(), parentSubs.end());
323323
}
324324

325-
auto subMap = SubstitutionMap::get(genericSig,
326-
QueryTypeSubstitutionMap{subs},
327-
LookUpConformanceInModule());
328-
if (!subMap)
329-
return Type();
325+
auto genericSig = aliasDecl->getGenericSignature();
326+
ASSERT(genericSig.getInnermostGenericParams().size() == args.size());
327+
subs.append(args.begin(), args.end());
330328

329+
auto subMap = SubstitutionMap::get(genericSig, subs,
330+
LookUpConformanceInModule());
331331
return aliasDecl->getDeclaredInterfaceType().subst(subMap);
332332
}
333333

0 commit comments

Comments
 (0)