@@ -844,10 +844,17 @@ void RuleBuilder::addAssociatedType(const AssociatedTypeDecl *type,
844
844
std::pair<MutableTerm, MutableTerm>
845
845
swift::rewriting::getRuleForRequirement (const Requirement &req,
846
846
const ProtocolDecl *proto,
847
+ Optional<ArrayRef<Term>> substitutions,
847
848
RewriteContext &ctx) {
849
+ assert (!substitutions.hasValue () || proto == nullptr && " Can't have both" );
850
+
848
851
// Compute the left hand side.
849
852
auto subjectType = CanType (req.getFirstType ());
850
- auto subjectTerm = ctx.getMutableTermForType (subjectType, proto);
853
+ auto subjectTerm = (substitutions
854
+ ? ctx.getRelativeTermForType (
855
+ subjectType, *substitutions)
856
+ : ctx.getMutableTermForType (
857
+ subjectType, proto));
851
858
852
859
// Compute the right hand side.
853
860
MutableTerm constraintTerm;
@@ -873,11 +880,13 @@ swift::rewriting::getRuleForRequirement(const Requirement &req,
873
880
auto otherType = CanType (req.getSecondType ());
874
881
875
882
// Build the symbol [superclass: C<X, Y>].
876
- SmallVector<Term, 1 > substitutions;
877
- otherType = ctx.getSubstitutionSchemaFromType (otherType, proto,
878
- substitutions);
879
- auto superclassSymbol = Symbol::forSuperclass (otherType, substitutions,
880
- ctx);
883
+ SmallVector<Term, 1 > result;
884
+ otherType = (substitutions
885
+ ? ctx.getRelativeSubstitutionSchemaFromType (
886
+ otherType, *substitutions, result)
887
+ : ctx.getSubstitutionSchemaFromType (
888
+ otherType, proto, result));
889
+ auto superclassSymbol = Symbol::forSuperclass (otherType, result, ctx);
881
890
882
891
// Build the term T.[superclass: C<X, Y>].
883
892
constraintTerm = subjectTerm;
@@ -890,8 +899,7 @@ swift::rewriting::getRuleForRequirement(const Requirement &req,
890
899
//
891
900
// T.[layout: L] == T
892
901
constraintTerm = subjectTerm;
893
- constraintTerm.add (Symbol::forLayout (req.getLayoutConstraint (),
894
- ctx));
902
+ constraintTerm.add (Symbol::forLayout (req.getLayoutConstraint (), ctx));
895
903
break ;
896
904
}
897
905
@@ -903,17 +911,23 @@ swift::rewriting::getRuleForRequirement(const Requirement &req,
903
911
// rewrite rule
904
912
//
905
913
// T.[concrete: C<X, Y>] => T
906
- SmallVector<Term, 1 > substitutions;
907
- otherType = ctx.getSubstitutionSchemaFromType (otherType, proto,
908
- substitutions);
914
+ SmallVector<Term, 1 > result;
915
+ otherType = (substitutions
916
+ ? ctx.getRelativeSubstitutionSchemaFromType (
917
+ otherType, *substitutions, result)
918
+ : ctx.getSubstitutionSchemaFromType (
919
+ otherType, proto, result));
909
920
910
921
constraintTerm = subjectTerm;
911
- constraintTerm.add (Symbol::forConcreteType (otherType, substitutions,
912
- ctx));
922
+ constraintTerm.add (Symbol::forConcreteType (otherType, result, ctx));
913
923
break ;
914
924
}
915
925
916
- constraintTerm = ctx.getMutableTermForType (otherType, proto);
926
+ constraintTerm = (substitutions
927
+ ? ctx.getRelativeTermForType (
928
+ otherType, *substitutions)
929
+ : ctx.getMutableTermForType (
930
+ otherType, proto));
917
931
break ;
918
932
}
919
933
}
@@ -929,7 +943,9 @@ void RuleBuilder::addRequirement(const Requirement &req,
929
943
llvm::dbgs () << " \n " ;
930
944
}
931
945
932
- RequirementRules.push_back (getRuleForRequirement (req, proto, Context));
946
+ RequirementRules.push_back (
947
+ getRuleForRequirement (req, proto, /* substitutions=*/ None,
948
+ Context));
933
949
}
934
950
935
951
void RuleBuilder::addRequirement (const StructuralRequirement &req,
0 commit comments