File tree Expand file tree Collapse file tree 4 files changed +17
-20
lines changed Expand file tree Collapse file tree 4 files changed +17
-20
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,10 @@ class SubstitutionMap {
150
150
// / generic parameters.
151
151
ArrayRef<Type> getReplacementTypes () const ;
152
152
153
+ // / Retrieve the array of replacement types for the innermost generic
154
+ // / parameters.
155
+ ArrayRef<Type> getInnermostReplacementTypes () const ;
156
+
153
157
// / Query whether any replacement types in the map contain archetypes.
154
158
bool hasArchetypes () const ;
155
159
Original file line number Diff line number Diff line change @@ -1806,7 +1806,7 @@ class TypeAliasType final
1806
1806
// / Get the direct generic arguments, which correspond to the generic
1807
1807
// / arguments that are directly applied to the typealias declaration
1808
1808
// / this type references.
1809
- SmallVector <Type, 2 > getDirectGenericArgs () const ;
1809
+ ArrayRef <Type> getDirectGenericArgs () const ;
1810
1810
1811
1811
// Support for FoldingSet.
1812
1812
void Profile (llvm::FoldingSetNodeID &id) const ;
Original file line number Diff line number Diff line change @@ -97,6 +97,13 @@ ArrayRef<Type> SubstitutionMap::getReplacementTypes() const {
97
97
return getReplacementTypesBuffer ();
98
98
}
99
99
100
+ ArrayRef<Type> SubstitutionMap::getInnermostReplacementTypes () const {
101
+ if (empty ()) return { };
102
+
103
+ return getReplacementTypes ().take_back (
104
+ getGenericSignature ()->getInnermostGenericParams ().size ());
105
+ }
106
+
100
107
GenericSignature SubstitutionMap::getGenericSignature () const {
101
108
return storage ? storage->getGenericSignature () : nullptr ;
102
109
}
Original file line number Diff line number Diff line change @@ -1385,26 +1385,12 @@ Type SugarType::getSinglyDesugaredTypeSlow() {
1385
1385
return UnderlyingType;
1386
1386
}
1387
1387
1388
- SmallVector <Type, 2 > TypeAliasType::getDirectGenericArgs () const {
1389
- SmallVector<Type, 2 > result ;
1388
+ ArrayRef <Type> TypeAliasType::getDirectGenericArgs () const {
1389
+ if (!typealias-> isGeneric ()) return { } ;
1390
1390
1391
- // If the typealias is not generic, there are no generic arguments
1392
- if (!typealias->isGeneric ()) return result;
1393
-
1394
- // If the substitution map is empty, bail out.
1395
- auto subMap = getSubstitutionMap ();
1396
- if (subMap.empty ()) return result;
1397
-
1398
- // Retrieve the substitutions for the generic parameters (only).
1399
- auto genericSig = subMap.getGenericSignature ();
1400
- unsigned numAllGenericParams = genericSig->getGenericParams ().size ();
1401
- unsigned numMyGenericParams = typealias->getGenericParams ()->size ();
1402
- result.reserve (numMyGenericParams);
1403
- unsigned startIndex = numAllGenericParams - numMyGenericParams;
1404
- for (auto gp : genericSig->getGenericParams ().slice (startIndex)) {
1405
- result.push_back (Type (gp).subst (subMap));
1406
- }
1407
- return result;
1391
+ // Otherwise, the innermost replacement types are the direct
1392
+ // generic arguments.
1393
+ return getSubstitutionMap ().getInnermostReplacementTypes ();
1408
1394
}
1409
1395
1410
1396
unsigned GenericTypeParamType::getDepth () const {
You can’t perform that action at this time.
0 commit comments