AST: Refactor GenericParamList::getSubstitutionMap() to take a GenericSignature, NFC

This function takes a substitution array and produces a
contextual type substitution map, so it is the contextual
type equivalent of GenericSignature::getSubstitutionMap(),
which produces an interface type substitution map.

The new version takes a GenericSignature, just like the new
getForwardingSubstitutions(), so that it can walk the
requirements of the signature rather than walking the
AllArchetypes list.

Also, this new version now produces a mapping from
archetypes to conformances in addition to the type mapping,
which will allow it to be used in a few places that had
hand-coded logic.
This commit is contained in:
Slava Pestov
2016-08-20 03:12:29 -07:00
parent 64ce6698eb
commit b8ae9c1391
6 changed files with 74 additions and 23 deletions

View File

@@ -358,16 +358,33 @@ SpecializedProtocolConformance::getTypeWitnessSubstAndDecl(
}
// Otherwise, perform substitutions to create this witness now.
TypeSubstitutionMap substitutionMap = GenericConformance->getGenericParams()
->getSubstitutionMap(GenericSubstitutions);
auto conformingDC = getDeclContext();
auto conformingModule = conformingDC->getParentModule();
auto *genericParams = GenericConformance->getGenericParams();
auto *genericSig = GenericConformance->getGenericSignature();
TypeSubstitutionMap substitutionMap;
// FIXME: We could have a new version of Type::subst() that
// takes a conformanceMap in addition to a substitutionMap,
// but for now this is ignored below
ArchetypeConformanceMap conformanceMap;
// Compute a context type substitution map from the
// substitution array stored in this conformance
genericParams->getSubstitutionMap(conformingModule, genericSig,
GenericSubstitutions,
substitutionMap,
conformanceMap);
auto genericWitnessAndDecl
= GenericConformance->getTypeWitnessSubstAndDecl(assocType, resolver);
auto &genericWitness = genericWitnessAndDecl.first;
auto *typeDecl = genericWitnessAndDecl.second;
auto conformingDC = getDeclContext();
auto conformingModule = conformingDC->getParentModule();
// Apply the substitution we computed above
auto specializedType
= genericWitness.getReplacement().subst(conformingModule, substitutionMap,
None);