@@ -236,18 +236,42 @@ void RequirementBuilder::addRequirementRules(ArrayRef<unsigned> rules) {
236
236
llvm_unreachable (" Invalid symbol kind" );
237
237
}
238
238
239
+ MutableTerm constraintTerm = MutableTerm (rule.getLHS ());
240
+ MutableTerm subjectTerm = MutableTerm (rule.getRHS ());
241
+
242
+ RewriteContext &ctx = this ->System .getRewriteContext ();
243
+
244
+ // Drop the [element] symbol from lhs to determine if we need to swap the
245
+ // sides.
246
+ if (constraintTerm[0 ].getKind () == Symbol::Kind::PackElement) {
247
+ constraintTerm =
248
+ MutableTerm (constraintTerm.begin () + 1 , constraintTerm.end ());
249
+
250
+ // Make sure that the shorter term is ordered first.
251
+ if (constraintTerm.compare (subjectTerm, ctx) == -1 ) {
252
+ MutableTerm tempTerm = subjectTerm;
253
+ subjectTerm = constraintTerm;
254
+ constraintTerm = tempTerm;
255
+ }
256
+ }
257
+
239
258
ASSERT (rule.getLHS ().back ().getKind () != Symbol::Kind::Protocol);
240
259
241
- MutableTerm constraintTerm (rule.getLHS ());
242
260
if (constraintTerm.back ().getKind () == Symbol::Kind::Shape) {
243
261
ASSERT (rule.getRHS ().back ().getKind () == Symbol::Kind::Shape);
244
262
// Strip off the shape symbol from the constraint term.
245
263
constraintTerm = MutableTerm (constraintTerm.begin (),
246
264
constraintTerm.end () - 1 );
247
265
}
248
266
267
+ if (constraintTerm.front ().getKind () == Symbol::Kind::PackElement) {
268
+ // Strip off the element symbol from the constraint term.
269
+ constraintTerm = MutableTerm (constraintTerm.begin () + 1 ,
270
+ constraintTerm.end ());
271
+ }
272
+
249
273
auto constraintType = Map.getTypeForTerm (constraintTerm, GenericParams);
250
- Components[rule. getRHS ( )].Members .push_back (constraintType);
274
+ Components[Term::get (subjectTerm, ctx )].Members .push_back (constraintType);
251
275
};
252
276
253
277
if (Debug) {
@@ -314,6 +338,10 @@ void RequirementBuilder::processConnectedComponents() {
314
338
subjectTerm = MutableTerm (subjectTerm.begin (), subjectTerm.end () - 1 );
315
339
} else {
316
340
kind = RequirementKind::SameType;
341
+ if (subjectTerm.front ().getKind () == Symbol::Kind::PackElement) {
342
+ // Strip off the element symbol from the subject term.
343
+ subjectTerm = MutableTerm (subjectTerm.begin () + 1 , subjectTerm.end ());
344
+ }
317
345
}
318
346
319
347
auto subjectType = Map.getTypeForTerm (subjectTerm, GenericParams);
0 commit comments