@@ -61,9 +61,15 @@ struct NormalizedConstraint {
6161 unsigned Kind : 5 ;
6262 unsigned Placeholder : 1 ;
6363 unsigned PackSubstitutionIndex : 26 ;
64- // Indexes and Args are part of the common initial sequences
65- // of constraints that do have a mapping.
64+ // Indexes, IndexesForSubsumption, and Args are part of the common initial
65+ // sequences of constraints that do have a mapping.
66+
67+ // Indexes of the parameters used in a constraint expression.
6668 OccurenceList Indexes;
69+ // Indexes of the parameters named directly in a constraint expression.
70+ // FIXME: we should try to reduce the size of this struct?
71+ OccurenceList IndexesForSubsumption;
72+
6773 TemplateArgumentLoc *Args;
6874 TemplateParameterList *ParamList;
6975 ExprOrConcept ConstraintExpr;
@@ -77,6 +83,7 @@ struct NormalizedConstraint {
7783 unsigned FoldOperator : 1 ;
7884 unsigned Placeholder : 26 ;
7985 OccurenceList Indexes;
86+ OccurenceList IndexesForSubsumption;
8087 TemplateArgumentLoc *Args;
8188 TemplateParameterList *ParamList;
8289 const Expr *Pattern;
@@ -119,6 +126,7 @@ struct NormalizedConstraint {
119126 /* Placeholder=*/ 0 ,
120127 PackIndex.toInternalRepresentation (),
121128 /* Indexes=*/ {},
129+ /* IndexesForSubsumption=*/ {},
122130 /* Args=*/ nullptr ,
123131 /* ParamList=*/ nullptr ,
124132 ConstraintExpr,
@@ -131,6 +139,7 @@ struct NormalizedConstraint {
131139 llvm::to_underlying (OpKind),
132140 /* Placeholder=*/ 0 ,
133141 /* Indexes=*/ {},
142+ /* IndexesForSubsumption=*/ {},
134143 /* Args=*/ nullptr ,
135144 /* ParamList=*/ nullptr ,
136145 Pattern,
@@ -145,6 +154,7 @@ struct NormalizedConstraint {
145154 : ConceptId{{llvm::to_underlying (ConstraintKind::ConceptId),
146155 /* Placeholder=*/ 0 , PackIndex.toInternalRepresentation (),
147156 /* Indexes=*/ {},
157+ /* IndexesForSubsumption=*/ {},
148158 /* Args=*/ nullptr , /* ParamList=*/ nullptr , ConceptId,
149159 ConstraintDecl},
150160 SubConstraint,
@@ -166,6 +176,11 @@ struct NormalizedConstraint {
166176 return Atomic.Indexes ;
167177 }
168178
179+ const OccurenceList &mappingOccurenceListForSubsumption () const {
180+ assert (hasParameterMapping () && " This constraint has no parameter mapping" );
181+ return Atomic.IndexesForSubsumption ;
182+ }
183+
169184 llvm::MutableArrayRef<TemplateArgumentLoc> getParameterMapping () const {
170185 return {Atomic.Args , Atomic.Indexes .count ()};
171186 }
@@ -175,11 +190,16 @@ struct NormalizedConstraint {
175190 }
176191
177192 void updateParameterMapping (OccurenceList Indexes,
193+ OccurenceList IndexesForSubsumption,
178194 llvm::MutableArrayRef<TemplateArgumentLoc> Args,
179195 TemplateParameterList *ParamList) {
180196 assert (getKind () != ConstraintKind::Compound);
181197 assert (Indexes.count () == Args.size ());
182- Atomic.Indexes = Indexes;
198+ assert (IndexesForSubsumption.size () == Indexes.size ());
199+ assert ((Indexes & IndexesForSubsumption) == Indexes);
200+
201+ Atomic.IndexesForSubsumption = std::move (IndexesForSubsumption);
202+ Atomic.Indexes = std::move (Indexes);
183203 Atomic.Args = Args.data ();
184204 Atomic.ParamList = ParamList;
185205 }
@@ -198,10 +218,17 @@ struct NormalizedConstraint {
198218 llvm::ArrayRef<TemplateArgumentLoc> OtherParameterMapping =
199219 Other.getParameterMapping ();
200220
221+ const OccurenceList &Indexes = mappingOccurenceListForSubsumption ();
222+ const OccurenceList &OtherIndexes =
223+ Other.mappingOccurenceListForSubsumption ();
224+
201225 if (ParameterMapping.size () != OtherParameterMapping.size ())
202226 return false ;
203-
204227 for (unsigned I = 0 , S = ParameterMapping.size (); I < S; ++I) {
228+ if (Indexes[I] != OtherIndexes[I])
229+ return false ;
230+ if (!Indexes[I])
231+ continue ;
205232 llvm::FoldingSetNodeID IDA, IDB;
206233 C.getCanonicalTemplateArgument (ParameterMapping[I].getArgument ())
207234 .Profile (IDA, C);
@@ -296,6 +323,7 @@ class NormalizedConstraintWithParamMapping : public NormalizedConstraint {
296323 using NormalizedConstraint::hasMatchingParameterMapping;
297324 using NormalizedConstraint::hasParameterMapping;
298325 using NormalizedConstraint::mappingOccurenceList;
326+ using NormalizedConstraint::mappingOccurenceListForSubsumption;
299327 using NormalizedConstraint::updateParameterMapping;
300328
301329 const NamedDecl *getConstraintDecl () const { return Atomic.ConstraintDecl ; }
0 commit comments