Skip to content

Commit eabaed8

Browse files
hborlasimanerush
authored andcommitted
[Requirement Machine] Use element symbols for concrete same-element requirements.
1 parent 0b6f8c8 commit eabaed8

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

lib/AST/RequirementMachine/GenericSignatureQueries.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -311,20 +311,6 @@ bool RequirementMachine::isReducedType(Type type) const {
311311
if (!component->hasTypeParameter())
312312
return Action::SkipNode;
313313

314-
if (auto *expansion = component->getAs<PackExpansionType>()) {
315-
auto pattern = expansion->getPatternType();
316-
auto shape = expansion->getCountType();
317-
if (!Self.isReducedType(pattern))
318-
return Action::Stop;
319-
320-
auto reducedShape =
321-
Self.getReducedShape(shape, Self.getGenericParams());
322-
if (reducedShape->getCanonicalType() != CanType(shape))
323-
return Action::Stop;
324-
325-
return Action::SkipChildren;
326-
}
327-
328314
if (!component->isTypeParameter())
329315
return Action::Continue;
330316

lib/AST/RequirementMachine/RewriteSystem.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,8 @@ void RewriteSystem::verifyRewriteRules(ValidityPolicy policy) const {
611611
}
612612

613613
if (index != 0) {
614-
ASSERT_RULE(symbol.getKind() != Symbol::Kind::GenericParam);
614+
ASSERT_RULE(symbol.getKind() != Symbol::Kind::GenericParam ||
615+
lhs[index - 1].getKind() == Symbol::Kind::PackElement);
615616
}
616617

617618
if (!rule.isRHSSimplified() &&

lib/AST/RequirementMachine/RuleBuilder.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ void RuleBuilder::addRequirement(const Requirement &req,
367367

368368
case RequirementKind::SameType: {
369369
auto otherType = CanType(req.getSecondType());
370+
auto elementSymbol = Symbol::forPackElement(Context);
370371

371372
if (!otherType->isTypeParameter()) {
372373
// A concrete same-type requirement T == C<X, Y> becomes a
@@ -380,6 +381,16 @@ void RuleBuilder::addRequirement(const Requirement &req,
380381
: Context.getSubstitutionSchemaFromType(
381382
otherType, proto, result));
382383

384+
// If 'T' is a parameter pack, this is a same-element
385+
// requirement that becomes the following rewrite rule:
386+
//
387+
// [element].T.[concrete: C<X, Y>] => [element].T
388+
if (subjectType->isParameterPack()) {
389+
llvm::SmallVector<Symbol, 3> subjectSymbols{elementSymbol};
390+
subjectSymbols.append(subjectTerm.begin(), subjectTerm.end());
391+
subjectTerm = MutableTerm(std::move(subjectSymbols));
392+
}
393+
383394
constraintTerm = subjectTerm;
384395
constraintTerm.add(Symbol::forConcreteType(otherType, result, Context));
385396
break;
@@ -393,7 +404,6 @@ void RuleBuilder::addRequirement(const Requirement &req,
393404

394405
if (subjectType->isParameterPack() != otherType->isParameterPack()) {
395406
// This is a same-element requirement.
396-
auto elementSymbol = Symbol::forPackElement(Context);
397407
llvm::SmallVector<Symbol, 3> symbols{elementSymbol};
398408

399409
if (subjectType->isParameterPack()) {

0 commit comments

Comments
 (0)