@@ -1258,26 +1258,39 @@ void RuleBuilder::addAssociatedType(const AssociatedTypeDecl *type,
1258
1258
1259
1259
// / Lowers a desugared generic requirement to a rewrite rule.
1260
1260
// /
1261
- // / If \p proto is null, this is a generic requirement from the top-level
1262
- // / generic signature. The added rewrite rule will be rooted in a generic
1263
- // / parameter symbol.
1261
+ // / Convert a requirement to a rule and add it to the builder.
1262
+ // /
1263
+ // / The types in the requirement must be canonical.
1264
+ // /
1265
+ // / If \p proto is null and \p substitutions is None, this is a generic
1266
+ // / requirement from the top-level generic signature. The added rewrite
1267
+ // / rule will be rooted in a generic parameter symbol.
1264
1268
// /
1265
1269
// / If \p proto is non-null, this is a generic requirement in the protocol's
1266
1270
// / requirement signature. The added rewrite rule will be rooted in a
1267
1271
// / protocol symbol.
1268
- std::pair<MutableTerm, MutableTerm>
1269
- swift::rewriting::getRuleForRequirement (const Requirement &req,
1270
- const ProtocolDecl *proto,
1271
- Optional<ArrayRef<Term>> substitutions,
1272
- RewriteContext &ctx) {
1272
+ // /
1273
+ // / If \p substitutions is not None, this is a conditional requirement
1274
+ // / added by conditional requirement inference. The added rewrite rule
1275
+ // / will be added in the corresponding term from the substitution array.
1276
+ void RuleBuilder::addRequirement (const Requirement &req,
1277
+ const ProtocolDecl *proto,
1278
+ Optional<ArrayRef<Term>> substitutions,
1279
+ Optional<unsigned > requirementID) {
1280
+ if (Dump) {
1281
+ llvm::dbgs () << " + " ;
1282
+ req.dump (llvm::dbgs ());
1283
+ llvm::dbgs () << " \n " ;
1284
+ }
1285
+
1273
1286
assert (!substitutions.hasValue () || proto == nullptr && " Can't have both" );
1274
1287
1275
1288
// Compute the left hand side.
1276
1289
auto subjectType = CanType (req.getFirstType ());
1277
1290
auto subjectTerm = (substitutions
1278
- ? ctx .getRelativeTermForType (
1291
+ ? Context .getRelativeTermForType (
1279
1292
subjectType, *substitutions)
1280
- : ctx .getMutableTermForType (
1293
+ : Context .getMutableTermForType (
1281
1294
subjectType, proto));
1282
1295
1283
1296
// Compute the right hand side.
@@ -1293,7 +1306,7 @@ swift::rewriting::getRuleForRequirement(const Requirement &req,
1293
1306
auto *proto = req.getProtocolDecl ();
1294
1307
1295
1308
constraintTerm = subjectTerm;
1296
- constraintTerm.add (Symbol::forProtocol (proto, ctx ));
1309
+ constraintTerm.add (Symbol::forProtocol (proto, Context ));
1297
1310
break ;
1298
1311
}
1299
1312
@@ -1306,11 +1319,11 @@ swift::rewriting::getRuleForRequirement(const Requirement &req,
1306
1319
// Build the symbol [superclass: C<X, Y>].
1307
1320
SmallVector<Term, 1 > result;
1308
1321
otherType = (substitutions
1309
- ? ctx .getRelativeSubstitutionSchemaFromType (
1322
+ ? Context .getRelativeSubstitutionSchemaFromType (
1310
1323
otherType, *substitutions, result)
1311
- : ctx .getSubstitutionSchemaFromType (
1324
+ : Context .getSubstitutionSchemaFromType (
1312
1325
otherType, proto, result));
1313
- auto superclassSymbol = Symbol::forSuperclass (otherType, result, ctx );
1326
+ auto superclassSymbol = Symbol::forSuperclass (otherType, result, Context );
1314
1327
1315
1328
// Build the term T.[superclass: C<X, Y>].
1316
1329
constraintTerm = subjectTerm;
@@ -1323,7 +1336,7 @@ swift::rewriting::getRuleForRequirement(const Requirement &req,
1323
1336
//
1324
1337
// T.[layout: L] == T
1325
1338
constraintTerm = subjectTerm;
1326
- constraintTerm.add (Symbol::forLayout (req.getLayoutConstraint (), ctx ));
1339
+ constraintTerm.add (Symbol::forLayout (req.getLayoutConstraint (), Context ));
1327
1340
break ;
1328
1341
}
1329
1342
@@ -1337,49 +1350,28 @@ swift::rewriting::getRuleForRequirement(const Requirement &req,
1337
1350
// T.[concrete: C<X, Y>] => T
1338
1351
SmallVector<Term, 1 > result;
1339
1352
otherType = (substitutions
1340
- ? ctx .getRelativeSubstitutionSchemaFromType (
1353
+ ? Context .getRelativeSubstitutionSchemaFromType (
1341
1354
otherType, *substitutions, result)
1342
- : ctx .getSubstitutionSchemaFromType (
1355
+ : Context .getSubstitutionSchemaFromType (
1343
1356
otherType, proto, result));
1344
1357
1345
1358
constraintTerm = subjectTerm;
1346
- constraintTerm.add (Symbol::forConcreteType (otherType, result, ctx ));
1359
+ constraintTerm.add (Symbol::forConcreteType (otherType, result, Context ));
1347
1360
break ;
1348
1361
}
1349
1362
1350
1363
constraintTerm = (substitutions
1351
- ? ctx .getRelativeTermForType (
1364
+ ? Context .getRelativeTermForType (
1352
1365
otherType, *substitutions)
1353
- : ctx .getMutableTermForType (
1366
+ : Context .getMutableTermForType (
1354
1367
otherType, proto));
1355
1368
break ;
1356
1369
}
1357
1370
}
1358
1371
1359
- return std::make_pair (subjectTerm, constraintTerm);
1360
- }
1361
-
1362
- // / Convert a requirement to a rule and add it to the builder.
1363
- // /
1364
- // / The types in the requirement must be canonical.
1365
- // /
1366
- // / If \p substitutions is not None, the interface types in the requirement
1367
- // / are converted to terms relative to these substitutions, using
1368
- // / RewriteContext::getRelativeTermForType().
1369
- void RuleBuilder::addRequirement (const Requirement &req,
1370
- const ProtocolDecl *proto,
1371
- Optional<ArrayRef<Term>> substitutions,
1372
- Optional<unsigned > requirementID) {
1373
- if (Dump) {
1374
- llvm::dbgs () << " + " ;
1375
- req.dump (llvm::dbgs ());
1376
- llvm::dbgs () << " \n " ;
1377
- }
1378
-
1379
- auto rule =
1380
- getRuleForRequirement (req, proto, substitutions, Context);
1381
- RequirementRules.push_back (
1382
- std::make_tuple (rule.first , rule.second , requirementID));
1372
+ RequirementRules.emplace_back (
1373
+ std::move (subjectTerm), std::move (constraintTerm),
1374
+ requirementID);
1383
1375
}
1384
1376
1385
1377
void RuleBuilder::addRequirement (const StructuralRequirement &req,
0 commit comments