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 {
150150 // / generic parameters.
151151 ArrayRef<Type> getReplacementTypes () const ;
152152
153+ // / Retrieve the array of replacement types for the innermost generic
154+ // / parameters.
155+ ArrayRef<Type> getInnermostReplacementTypes () const ;
156+
153157 // / Query whether any replacement types in the map contain archetypes.
154158 bool hasArchetypes () const ;
155159
Original file line number Diff line number Diff line change @@ -1806,7 +1806,7 @@ class TypeAliasType final
18061806 // / Get the direct generic arguments, which correspond to the generic
18071807 // / arguments that are directly applied to the typealias declaration
18081808 // / this type references.
1809- SmallVector <Type, 2 > getDirectGenericArgs () const ;
1809+ ArrayRef <Type> getDirectGenericArgs () const ;
18101810
18111811 // Support for FoldingSet.
18121812 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 {
9797 return getReplacementTypesBuffer ();
9898}
9999
100+ ArrayRef<Type> SubstitutionMap::getInnermostReplacementTypes () const {
101+ if (empty ()) return { };
102+
103+ return getReplacementTypes ().take_back (
104+ getGenericSignature ()->getInnermostGenericParams ().size ());
105+ }
106+
100107GenericSignature SubstitutionMap::getGenericSignature () const {
101108 return storage ? storage->getGenericSignature () : nullptr ;
102109}
Original file line number Diff line number Diff line change @@ -1385,26 +1385,12 @@ Type SugarType::getSinglyDesugaredTypeSlow() {
13851385 return UnderlyingType;
13861386}
13871387
1388- SmallVector <Type, 2 > TypeAliasType::getDirectGenericArgs () const {
1389- SmallVector<Type, 2 > result ;
1388+ ArrayRef <Type> TypeAliasType::getDirectGenericArgs () const {
1389+ if (!typealias-> isGeneric ()) return { } ;
13901390
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 ();
14081394}
14091395
14101396unsigned GenericTypeParamType::getDepth () const {
You can’t perform that action at this time.
0 commit comments