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.
|
/// generic parameters.
|
||||||
ArrayRef<Type> getReplacementTypes() const;
|
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.
|
/// Query whether any replacement types in the map contain archetypes.
|
||||||
bool hasArchetypes() const;
|
bool hasArchetypes() const;
|
||||||
|
|
||||||
|
|||||||
@@ -1806,7 +1806,7 @@ public:
|
|||||||
/// Get the direct generic arguments, which correspond to the generic
|
/// Get the direct generic arguments, which correspond to the generic
|
||||||
/// arguments that are directly applied to the typealias declaration
|
/// arguments that are directly applied to the typealias declaration
|
||||||
/// this type references.
|
/// this type references.
|
||||||
SmallVector<Type, 2> getDirectGenericArgs() const;
|
ArrayRef<Type> getDirectGenericArgs() const;
|
||||||
|
|
||||||
// Support for FoldingSet.
|
// Support for FoldingSet.
|
||||||
void Profile(llvm::FoldingSetNodeID &id) const;
|
void Profile(llvm::FoldingSetNodeID &id) const;
|
||||||
|
|||||||
@@ -97,6 +97,13 @@ ArrayRef<Type> SubstitutionMap::getReplacementTypes() const {
|
|||||||
return getReplacementTypesBuffer();
|
return getReplacementTypesBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ArrayRef<Type> SubstitutionMap::getInnermostReplacementTypes() const {
|
||||||
|
if (empty()) return { };
|
||||||
|
|
||||||
|
return getReplacementTypes().take_back(
|
||||||
|
getGenericSignature()->getInnermostGenericParams().size());
|
||||||
|
}
|
||||||
|
|
||||||
GenericSignature SubstitutionMap::getGenericSignature() const {
|
GenericSignature SubstitutionMap::getGenericSignature() const {
|
||||||
return storage ? storage->getGenericSignature() : nullptr;
|
return storage ? storage->getGenericSignature() : nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1385,26 +1385,12 @@ Type SugarType::getSinglyDesugaredTypeSlow() {
|
|||||||
return UnderlyingType;
|
return UnderlyingType;
|
||||||
}
|
}
|
||||||
|
|
||||||
SmallVector<Type, 2> TypeAliasType::getDirectGenericArgs() const {
|
ArrayRef<Type> TypeAliasType::getDirectGenericArgs() const {
|
||||||
SmallVector<Type, 2> result;
|
if (!typealias->isGeneric()) return { };
|
||||||
|
|
||||||
// If the typealias is not generic, there are no generic arguments
|
// Otherwise, the innermost replacement types are the direct
|
||||||
if (!typealias->isGeneric()) return result;
|
// generic arguments.
|
||||||
|
return getSubstitutionMap().getInnermostReplacementTypes();
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned GenericTypeParamType::getDepth() const {
|
unsigned GenericTypeParamType::getDepth() const {
|
||||||
|
|||||||
Reference in New Issue
Block a user