Skip to content

Commit 17664c0

Browse files
committed
RequirementMachine: Use RewriteStep::ConcreteTypeWitness in nested type concretization
1 parent 654953c commit 17664c0

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/AST/RequirementMachine/PropertyMap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ class PropertyMap {
228228

229229
MutableTerm computeConstraintTermForTypeWitness(
230230
Term key, CanType concreteType, CanType typeWitness,
231-
const MutableTerm &subjectType, ArrayRef<Term> substitutions) const;
231+
const MutableTerm &subjectType, ArrayRef<Term> substitutions,
232+
RewritePath &path) const;
232233

233234
void recordConcreteConformanceRule(
234235
unsigned concreteRuleID,

lib/AST/RequirementMachine/PropertyUnification.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,8 @@ void PropertyMap::concretizeTypeWitnessInConformance(
614614

615615
MutableTerm constraintType;
616616

617+
RewritePath path;
618+
617619
auto simplify = [&](CanType t) -> CanType {
618620
return CanType(t.transformRec([&](Type t) -> Optional<Type> {
619621
if (!t->isTypeParameter())
@@ -640,10 +642,10 @@ void PropertyMap::concretizeTypeWitnessInConformance(
640642
} else {
641643
constraintType = computeConstraintTermForTypeWitness(
642644
key, concreteType, typeWitness, subjectType,
643-
substitutions);
645+
substitutions, path);
644646
}
645647

646-
inducedRules.emplace_back(subjectType, constraintType);
648+
inducedRules.emplace_back(constraintType, subjectType, path);
647649
if (Debug.contains(DebugFlags::ConcretizeNestedTypes)) {
648650
llvm::dbgs() << "^^ Induced rule " << constraintType
649651
<< " => " << subjectType << "\n";
@@ -720,7 +722,8 @@ RewriteSystem::getConcreteTypeWitness(unsigned index) const {
720722
/// T.[P:A] => V
721723
MutableTerm PropertyMap::computeConstraintTermForTypeWitness(
722724
Term key, CanType concreteType, CanType typeWitness,
723-
const MutableTerm &subjectType, ArrayRef<Term> substitutions) const {
725+
const MutableTerm &subjectType, ArrayRef<Term> substitutions,
726+
RewritePath &path) const {
724727
if (!typeWitness->hasTypeParameter()) {
725728
// Check if we have a shorter representative we can use.
726729
auto domain = key.getRootProtocols();
@@ -767,6 +770,14 @@ MutableTerm PropertyMap::computeConstraintTermForTypeWitness(
767770
Symbol::forConcreteType(
768771
typeWitnessSchema, result, Context));
769772

773+
RewriteSystem::ConcreteTypeWitness witness(*(constraintType.end() - 3),
774+
*(constraintType.end() - 2),
775+
*(constraintType.end() - 1));
776+
unsigned index = System.recordConcreteTypeWitness(witness);
777+
778+
path.add(RewriteStep::forConcreteTypeWitness(
779+
index, /*inverse=*/false));
780+
770781
return constraintType;
771782
}
772783

0 commit comments

Comments
 (0)