[NFC] AST: Define SubstitutionMap::getInnermostReplacementTypes

This commit is contained in:
Anthony Latsis
2020-05-15 12:24:15 +03:00
parent dfbbd727bf
commit eedb335a08
4 changed files with 17 additions and 20 deletions

View File

@@ -150,6 +150,10 @@ public:
/// generic parameters.
ArrayRef<Type> getReplacementTypes() const;
/// Retrieve the array of replacement types for the innermost generic
/// parameters.
ArrayRef<Type> getInnermostReplacementTypes() const;
/// Query whether any replacement types in the map contain archetypes.
bool hasArchetypes() const;

View File

@@ -1806,7 +1806,7 @@ public:
/// Get the direct generic arguments, which correspond to the generic
/// arguments that are directly applied to the typealias declaration
/// this type references.
SmallVector<Type, 2> getDirectGenericArgs() const;
ArrayRef<Type> getDirectGenericArgs() const;
// Support for FoldingSet.
void Profile(llvm::FoldingSetNodeID &id) const;

View File

@@ -97,6 +97,13 @@ ArrayRef<Type> SubstitutionMap::getReplacementTypes() const {
return getReplacementTypesBuffer();
}
ArrayRef<Type> SubstitutionMap::getInnermostReplacementTypes() const {
if (empty()) return { };
return getReplacementTypes().take_back(
getGenericSignature()->getInnermostGenericParams().size());
}
GenericSignature SubstitutionMap::getGenericSignature() const {
return storage ? storage->getGenericSignature() : nullptr;
}

View File

@@ -1385,26 +1385,12 @@ Type SugarType::getSinglyDesugaredTypeSlow() {
return UnderlyingType;
}
SmallVector<Type, 2> TypeAliasType::getDirectGenericArgs() const {
SmallVector<Type, 2> result;
ArrayRef<Type> TypeAliasType::getDirectGenericArgs() const {
if (!typealias->isGeneric()) return { };
// If the typealias is not generic, there are no generic arguments
if (!typealias->isGeneric()) return result;
// If the substitution map is empty, bail out.
auto subMap = getSubstitutionMap();
if (subMap.empty()) return result;
// Retrieve the substitutions for the generic parameters (only).
auto genericSig = subMap.getGenericSignature();
unsigned numAllGenericParams = genericSig->getGenericParams().size();
unsigned numMyGenericParams = typealias->getGenericParams()->size();
result.reserve(numMyGenericParams);
unsigned startIndex = numAllGenericParams - numMyGenericParams;
for (auto gp : genericSig->getGenericParams().slice(startIndex)) {
result.push_back(Type(gp).subst(subMap));
}
return result;
// Otherwise, the innermost replacement types are the direct
// generic arguments.
return getSubstitutionMap().getInnermostReplacementTypes();
}
unsigned GenericTypeParamType::getDepth() const {