Repository: carbon-language/carbon-lang
File: toolchain/sem_ir/facet_type_info.h (C/C++)

Code before:
  // TODO: Add same-type constraints.
  // TODO: Remove once all requirements are supported.
  bool other_requirements;

  // Sorts and deduplicates constraints. Call after building the value, and then
  // don't mutate this value afterwards.
  auto Canonicalize() -> void;

  auto Print(llvm::raw_ostream& out) const -> void;

  // TODO: Update callers to be able to deal with facet types that aren't a
  // single interface and then remove this function.
  auto TryAsSingleInterface() const -> std::optional<ImplsConstraint> {
    // We are ignoring other requirements for the moment, since this function is
    // (hopefully) temporary.
    if (impls_constraints.size() == 1) {
      return impls_constraints.front();
    }
    return std::nullopt;
  }

  // Returns a FacetTypeInfo that combines `lhs` and `rhs`. It is not
  // canonicalized, so that it can be further modified by the caller if desired.
  static auto Combined(const FacetTypeInfo& lhs, const FacetTypeInfo& rhs)
      -> FacetTypeInfo {
    auto info = FacetTypeInfo{.other_requirements = false};
    llvm::append_range(info.impls_constraints, lhs.impls_constraints);
    llvm::append_range(info.impls_constraints, rhs.impls_constraints);
    llvm::append_range(info.rewrite_constraints, lhs.rewrite_constraints);
    llvm::append_range(info.rewrite_constraints, rhs.rewrite_constraints);
    info.other_requirements |= lhs.other_requirements;
    info.other_requirements |= rhs.other_requirements;
    return info;
  }

  friend auto operator==(const FacetTypeInfo& lhs, const FacetTypeInfo& rhs)
      -> bool {
    return lhs.impls_constraints == rhs.impls_constraints &&
           lhs.rewrite_constraints == rhs.rewrite_constraints &&
           lhs.other_requirements == rhs.other_requirements;
  }
};

constexpr FacetTypeInfo::RewriteConstraint
    FacetTypeInfo::RewriteConstraint::None = {.lhs_const_id = ConstantId::None,
                                              .rhs_const_id = ConstantId::None};

struct CompleteFacetType {
  // TODO: Add additional fields, for example to support types other than
  // `.Self` implementation requirements.
  using RequiredInterface = SpecificInterface;

Review comment (suggestion):
```suggestion
  FacetTypeInfo info = {.other_requirements = false};
```

See initialization at https://github.com/carbon-language/carbon-lang/blob/trunk/docs/project/cpp_style_guide.md

Code after:
  llvm::SmallVector<ImplsConstraint> impls_constraints;

  // Rewrite constraints of the form `.T = U`
  struct RewriteConstraint {
    ConstantId lhs_const_id;
    ConstantId rhs_const_id;

    static const RewriteConstraint None;

    friend auto operator==(const RewriteConstraint& lhs,
                           const RewriteConstraint& rhs) -> bool = default;
  };
  llvm::SmallVector<RewriteConstraint> rewrite_constraints;

  // TODO: Add same-type constraints.
  // TODO: Remove once all requirements are supported.
  bool other_requirements;

  // Sorts and deduplicates constraints. Call after building the value, and then
  // don't mutate this value afterwards.
  auto Canonicalize() -> void;

  auto Print(llvm::raw_ostream& out) const -> void;

  // TODO: Update callers to be able to deal with facet types that aren't a
  // single interface and then remove this function.
  auto TryAsSingleInterface() const -> std::optional<ImplsConstraint> {
    // We are ignoring other requirements for the moment, since this function is
    // (hopefully) temporary.
    if (impls_constraints.size() == 1) {
      return impls_constraints.front();
    }
    return std::nullopt;
  }

  friend auto operator==(const FacetTypeInfo& lhs, const FacetTypeInfo& rhs)
      -> bool {
    return lhs.impls_constraints == rhs.impls_constraints &&
           lhs.rewrite_constraints == rhs.rewrite_constraints &&
           lhs.other_requirements == rhs.other_requirements;
  }
};

constexpr FacetTypeInfo::RewriteConstraint
    FacetTypeInfo::RewriteConstraint::None = {.lhs_const_id = ConstantId::None,
                                              .rhs_const_id = ConstantId::None};

struct CompleteFacetType {
  // TODO: Add additional fields, for example to support types other than
  // `.Self` implementation requirements.
  using RequiredInterface = SpecificInterface;