mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[NFC] AST: Define SubstitutionMap::getInnermostReplacementTypes
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user