Skip to content

Commit 68d6a39

Browse files
committed
[Requirement Machine] Use element symbols for concrete same-element requirements.
1 parent 79be266 commit 68d6a39

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

lib/AST/RequirementMachine/GenericSignatureQueries.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -308,20 +308,6 @@ bool RequirementMachine::isReducedType(Type type) const {
308308
if (!component->hasTypeParameter())
309309
return Action::SkipChildren;
310310

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

lib/AST/RequirementMachine/RewriteSystem.cpp

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

627627
if (index != 0) {
628-
ASSERT_RULE(symbol.getKind() != Symbol::Kind::GenericParam);
628+
ASSERT_RULE(symbol.getKind() != Symbol::Kind::GenericParam ||
629+
lhs[index - 1].getKind() == Symbol::Kind::PackElement);
629630
}
630631

631632
if (!rule.isRHSSimplified() &&

lib/AST/RequirementMachine/RuleBuilder.cpp

Lines changed: 12 additions & 2 deletions
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()) {
@@ -580,4 +590,4 @@ void RuleBuilder::collectPackShapeRules(ArrayRef<GenericTypeParamType *> generic
580590
}
581591
}
582592
}
583-
}
593+
}

0 commit comments

Comments
 (0)