|
|
@@ -25,8 +25,8 @@ static auto SortAndDeduplicate(VecT& vec,
|
|
|
}
|
|
|
|
|
|
// Canonically ordered by the numerical ids.
|
|
|
-static auto ImplsLess(const FacetTypeInfo::ImplsConstraint& lhs,
|
|
|
- const FacetTypeInfo::ImplsConstraint& rhs) -> bool {
|
|
|
+static auto InterfaceLess(const SpecificInterface& lhs,
|
|
|
+ const SpecificInterface& rhs) -> bool {
|
|
|
return std::tie(lhs.interface_id.index, lhs.specific_id.index) <
|
|
|
std::tie(rhs.interface_id.index, rhs.specific_id.index);
|
|
|
}
|
|
|
@@ -39,12 +39,36 @@ static auto RewriteLess(const FacetTypeInfo::RewriteConstraint& lhs,
|
|
|
}
|
|
|
|
|
|
// Canonically ordered by the numerical ids.
|
|
|
-static auto NamedConstraintsLess(const SpecificNamedConstraint& lhs,
|
|
|
- const SpecificNamedConstraint& rhs) -> bool {
|
|
|
+static auto NamedConstraintLess(const SpecificNamedConstraint& lhs,
|
|
|
+ const SpecificNamedConstraint& rhs) -> bool {
|
|
|
return std::tie(lhs.named_constraint_id.index, lhs.specific_id.index) <
|
|
|
std::tie(rhs.named_constraint_id.index, rhs.specific_id.index);
|
|
|
}
|
|
|
|
|
|
+// Canonically ordered by the numerical ids.
|
|
|
+static auto TypeImplsInterfaceLess(const FacetTypeInfo::TypeImplsInterface& lhs,
|
|
|
+ const FacetTypeInfo::TypeImplsInterface& rhs)
|
|
|
+ -> bool {
|
|
|
+ return std::tie(lhs.self_type.index,
|
|
|
+ lhs.specific_interface.interface_id.index,
|
|
|
+ lhs.specific_interface.specific_id.index) <
|
|
|
+ std::tie(rhs.self_type.index,
|
|
|
+ rhs.specific_interface.interface_id.index,
|
|
|
+ rhs.specific_interface.specific_id.index);
|
|
|
+}
|
|
|
+
|
|
|
+// Canonically ordered by the numerical ids.
|
|
|
+static auto TypeImplsNamedConstraintLess(
|
|
|
+ const FacetTypeInfo::TypeImplsNamedConstraint& lhs,
|
|
|
+ const FacetTypeInfo::TypeImplsNamedConstraint& rhs) -> bool {
|
|
|
+ return std::tie(lhs.self_type.index,
|
|
|
+ lhs.specific_named_constraint.named_constraint_id.index,
|
|
|
+ lhs.specific_named_constraint.specific_id.index) <
|
|
|
+ std::tie(rhs.self_type.index,
|
|
|
+ rhs.specific_named_constraint.named_constraint_id.index,
|
|
|
+ rhs.specific_named_constraint.specific_id.index);
|
|
|
+}
|
|
|
+
|
|
|
// Canonically ordered by the numerical ids.
|
|
|
static auto RequiredLess(const IdentifiedFacetType::RequiredImpl& lhs,
|
|
|
const IdentifiedFacetType::RequiredImpl& rhs) -> bool {
|
|
|
@@ -131,6 +155,11 @@ auto FacetTypeInfo::Combine(const FacetTypeInfo& lhs, const FacetTypeInfo& rhs)
|
|
|
CombineVectors(info.self_impls_named_constraints,
|
|
|
lhs.self_impls_named_constraints,
|
|
|
rhs.self_impls_named_constraints);
|
|
|
+ CombineVectors(info.type_impls_interfaces, lhs.type_impls_interfaces,
|
|
|
+ rhs.type_impls_interfaces);
|
|
|
+ CombineVectors(info.type_impls_named_constraints,
|
|
|
+ lhs.type_impls_named_constraints,
|
|
|
+ rhs.type_impls_named_constraints);
|
|
|
CombineVectors(info.rewrite_constraints, lhs.rewrite_constraints,
|
|
|
rhs.rewrite_constraints);
|
|
|
info.other_requirements = lhs.other_requirements || rhs.other_requirements;
|
|
|
@@ -138,13 +167,16 @@ auto FacetTypeInfo::Combine(const FacetTypeInfo& lhs, const FacetTypeInfo& rhs)
|
|
|
}
|
|
|
|
|
|
auto FacetTypeInfo::Canonicalize() -> void {
|
|
|
- SortAndDeduplicate(extend_constraints, ImplsLess);
|
|
|
- SortAndDeduplicate(self_impls_constraints, ImplsLess);
|
|
|
- SubtractSorted(self_impls_constraints, extend_constraints, ImplsLess);
|
|
|
- SortAndDeduplicate(extend_named_constraints, NamedConstraintsLess);
|
|
|
- SortAndDeduplicate(self_impls_named_constraints, NamedConstraintsLess);
|
|
|
+ SortAndDeduplicate(extend_constraints, InterfaceLess);
|
|
|
+ SortAndDeduplicate(self_impls_constraints, InterfaceLess);
|
|
|
+ SubtractSorted(self_impls_constraints, extend_constraints, InterfaceLess);
|
|
|
+ SortAndDeduplicate(extend_named_constraints, NamedConstraintLess);
|
|
|
+ SortAndDeduplicate(self_impls_named_constraints, NamedConstraintLess);
|
|
|
SubtractSorted(self_impls_named_constraints, extend_named_constraints,
|
|
|
- NamedConstraintsLess);
|
|
|
+ NamedConstraintLess);
|
|
|
+ SortAndDeduplicate(type_impls_interfaces, TypeImplsInterfaceLess);
|
|
|
+ SortAndDeduplicate(type_impls_named_constraints,
|
|
|
+ TypeImplsNamedConstraintLess);
|
|
|
SortAndDeduplicate(rewrite_constraints, RewriteLess);
|
|
|
}
|
|
|
|
|
|
@@ -155,7 +187,7 @@ auto FacetTypeInfo::Print(llvm::raw_ostream& out) const -> void {
|
|
|
if (!extend_constraints.empty()) {
|
|
|
out << outer_sep << "extends interface: ";
|
|
|
llvm::ListSeparator sep;
|
|
|
- for (ImplsConstraint req : extend_constraints) {
|
|
|
+ for (auto req : extend_constraints) {
|
|
|
out << sep << req.interface_id;
|
|
|
if (req.specific_id.has_value()) {
|
|
|
out << "(" << req.specific_id << ")";
|
|
|
@@ -166,7 +198,7 @@ auto FacetTypeInfo::Print(llvm::raw_ostream& out) const -> void {
|
|
|
if (!self_impls_constraints.empty()) {
|
|
|
out << outer_sep << "self impls interface: ";
|
|
|
llvm::ListSeparator sep;
|
|
|
- for (ImplsConstraint req : self_impls_constraints) {
|
|
|
+ for (auto req : self_impls_constraints) {
|
|
|
out << sep << req.interface_id;
|
|
|
if (req.specific_id.has_value()) {
|
|
|
out << "(" << req.specific_id << ")";
|
|
|
@@ -174,14 +206,6 @@ auto FacetTypeInfo::Print(llvm::raw_ostream& out) const -> void {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (!rewrite_constraints.empty()) {
|
|
|
- out << outer_sep << "rewrites: ";
|
|
|
- llvm::ListSeparator sep;
|
|
|
- for (RewriteConstraint req : rewrite_constraints) {
|
|
|
- out << sep << req.lhs_id << "=" << req.rhs_id;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
if (!extend_named_constraints.empty()) {
|
|
|
out << outer_sep << "extends named constraint: ";
|
|
|
llvm::ListSeparator sep;
|
|
|
@@ -204,6 +228,39 @@ auto FacetTypeInfo::Print(llvm::raw_ostream& out) const -> void {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if (!type_impls_interfaces.empty()) {
|
|
|
+ out << outer_sep << "type impls interface: ";
|
|
|
+ llvm::ListSeparator sep;
|
|
|
+ for (const auto& type_impls : type_impls_interfaces) {
|
|
|
+ out << sep << type_impls.self_type;
|
|
|
+ out << " impls " << type_impls.specific_interface.interface_id;
|
|
|
+ if (type_impls.specific_interface.specific_id.has_value()) {
|
|
|
+ out << "(" << type_impls.specific_interface.specific_id << ")";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!type_impls_named_constraints.empty()) {
|
|
|
+ out << outer_sep << "type impls interface: ";
|
|
|
+ llvm::ListSeparator sep;
|
|
|
+ for (const auto& type_impls : type_impls_named_constraints) {
|
|
|
+ out << sep << type_impls.self_type;
|
|
|
+ out << " impls "
|
|
|
+ << type_impls.specific_named_constraint.named_constraint_id;
|
|
|
+ if (type_impls.specific_named_constraint.specific_id.has_value()) {
|
|
|
+ out << "(" << type_impls.specific_named_constraint.specific_id << ")";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!rewrite_constraints.empty()) {
|
|
|
+ out << outer_sep << "rewrites: ";
|
|
|
+ llvm::ListSeparator sep;
|
|
|
+ for (auto req : rewrite_constraints) {
|
|
|
+ out << sep << req.lhs_id << "=" << req.rhs_id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (other_requirements) {
|
|
|
out << outer_sep << "+ TODO requirements";
|
|
|
}
|
|
|
@@ -285,7 +342,7 @@ auto AddCanonicalWitnessesBlock(File& sem_ir,
|
|
|
// canonical order in which the witnesses must appear for a given facet type
|
|
|
// so that ImplWitnessAccess can find the appropriate witness.
|
|
|
llvm::sort(sortable, [](auto& lhs, auto& rhs) {
|
|
|
- return ImplsLess(lhs.first, rhs.first);
|
|
|
+ return InterfaceLess(lhs.first, rhs.first);
|
|
|
});
|
|
|
|
|
|
// Update the original list with the new order (reusing to avoid an
|