-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Requirement Machine] Implement same-element requirements. #67465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7537649
d138b15
20e8e19
c4a1135
61b2503
819556b
f381b3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -367,6 +367,7 @@ void RuleBuilder::addRequirement(const Requirement &req, | |
|
||
case RequirementKind::SameType: { | ||
auto otherType = CanType(req.getSecondType()); | ||
auto elementSymbol = Symbol::forPackElement(Context); | ||
|
||
if (!otherType->isTypeParameter()) { | ||
// A concrete same-type requirement T == C<X, Y> becomes a | ||
|
@@ -380,6 +381,16 @@ void RuleBuilder::addRequirement(const Requirement &req, | |
: Context.getSubstitutionSchemaFromType( | ||
otherType, proto, result)); | ||
|
||
// If 'T' is a parameter pack, this is a same-element | ||
// requirement that becomes the following rewrite rule: | ||
// | ||
// [element].T.[concrete: C<X, Y>] => [element].T | ||
if (subjectType->isParameterPack()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But only if the constraint type does not contain any packs right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that's right. |
||
llvm::SmallVector<Symbol, 3> subjectSymbols{elementSymbol}; | ||
subjectSymbols.append(subjectTerm.begin(), subjectTerm.end()); | ||
subjectTerm = MutableTerm(std::move(subjectSymbols)); | ||
} | ||
|
||
constraintTerm = subjectTerm; | ||
constraintTerm.add(Symbol::forConcreteType(otherType, result, Context)); | ||
break; | ||
|
@@ -390,6 +401,20 @@ void RuleBuilder::addRequirement(const Requirement &req, | |
otherType, *substitutions) | ||
: Context.getMutableTermForType( | ||
otherType, proto)); | ||
|
||
if (subjectType->isParameterPack() != otherType->isParameterPack()) { | ||
// This is a same-element requirement. | ||
llvm::SmallVector<Symbol, 3> symbols{elementSymbol}; | ||
|
||
if (subjectType->isParameterPack()) { | ||
symbols.append(subjectTerm.begin(), subjectTerm.end()); | ||
subjectTerm = MutableTerm(std::move(symbols)); | ||
} else { | ||
symbols.append(constraintTerm.begin(), constraintTerm.end()); | ||
constraintTerm = MutableTerm(std::move(symbols)); | ||
} | ||
} | ||
|
||
break; | ||
} | ||
} | ||
|
@@ -565,4 +590,4 @@ void RuleBuilder::collectPackShapeRules(ArrayRef<GenericTypeParamType *> generic | |
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change RequirementBuilder.cpp to build them in the other order instead?