Repository: carbon-language/carbon-lang
File: toolchain/check/impl_lookup.h (C/C++)

Code before:
//   facet type is satisfied for the type in `type_const_id`, and provides a
//   witness for accessing the impl of each interface.
//
// - `InstBlockId::None`, indicating lookup failed for at least one required
//   interface in the `query_facet_type_const_id`. The facet type is not
//   satisfied for the type in `type_const_id`. This represents lookup failure,
//   but is not an error, so no diagnostic is emitted.
//
// - An error value, indicating the program is invalid and a diagonstic has been
//   produced, either in this function or before.
auto LookupImplWitness(Context& context, SemIR::LocId loc_id,
                       SemIR::ConstantId query_self_const_id,
                       SemIR::ConstantId query_facet_type_const_id)
    -> SemIR::InstBlockIdOrError;

// Returns whether the query matches against the given impl. This is like a
// `LookupImplWitness` operation but for a single interface, and against only
// the single impl.
auto LookupMatchesImpl(Context& context, SemIR::LocId loc_id,
                       SemIR::ConstantId query_self_const_id,
                       SemIR::SpecificInterface query_specific_interface,
                       SemIR::ImplId target_impl) -> bool;

// The result of EvalLookupSingleImplWitness(). It can be one of:
// - No value. Lookup failed to find an impl declaration.
// - A constant. Lookup found a concrete impl declaration that can be
//   used definitively.
// - A symbolic value. Lookup found an impl but it is not returned since
// lookup
//   will need to be done again with a more specific query to look for
//   specializations.
class [[nodiscard]] EvalImplLookupResult {
 public:
  static auto MakeNone() -> EvalImplLookupResult {
    return EvalImplLookupResult(SemIR::InstId::None);
  }
  static auto MakeFinal(SemIR::InstId inst_id) -> EvalImplLookupResult {
    return EvalImplLookupResult(inst_id);
  }
  static auto MakeNonFinal() -> EvalImplLookupResult {
    return EvalImplLookupResult(FoundNonFinalImpl());
  }

  // True if a concrete impl witness was found or a non-final impl. In the
  // latter case the InstId of the impl's witness is not returned, only the fact
  // that it exists.
  auto has_value() const -> bool {
    return std::holds_alternative<FoundNonFinalImpl>(result_) ||
           std::get<SemIR::InstId>(result_).has_value();
  }


Review comment (suggestion):
Please undo this change
```suggestion
// - A concrete value. Lookup found a concrete impl declaration that can be
```

Code after:
//   facet type is satisfied for the type in `type_const_id`, and provides a
//   witness for accessing the impl of each interface.
//
// - `InstBlockId::None`, indicating lookup failed for at least one required
//   interface in the `query_facet_type_const_id`. The facet type is not
//   satisfied for the type in `type_const_id`. This represents lookup failure,
//   but is not an error, so no diagnostic is emitted.
//
// - An error value, indicating the program is invalid and a diagonstic has been
//   produced, either in this function or before.
auto LookupImplWitness(Context& context, SemIR::LocId loc_id,
                       SemIR::ConstantId query_self_const_id,
                       SemIR::ConstantId query_facet_type_const_id)
    -> SemIR::InstBlockIdOrError;

// Returns whether the query matches against the given impl. This is like a
// `LookupImplWitness` operation but for a single interface, and against only
// the single impl.
auto LookupMatchesImpl(Context& context, SemIR::LocId loc_id,
                       SemIR::ConstantId query_self_const_id,
                       SemIR::SpecificInterface query_specific_interface,
                       SemIR::ImplId target_impl) -> bool;

// The result of EvalLookupSingleImplWitness(). It can be one of:
// - No value. Lookup failed to find an impl declaration.
// - A concrete value. Lookup found a concrete impl declaration that can be
//   used definitively.
// - A symbolic value. Lookup found an impl but it is not returned since lookup
//   will need to be done again with a more specific query to look for
//   specializations.
class [[nodiscard]] EvalImplLookupResult {
 public:
  static auto MakeNone() -> EvalImplLookupResult {
    return EvalImplLookupResult(SemIR::InstId::None);
  }
  static auto MakeFinal(SemIR::InstId inst_id) -> EvalImplLookupResult {
    return EvalImplLookupResult(inst_id);
  }
  static auto MakeNonFinal() -> EvalImplLookupResult {
    return EvalImplLookupResult(FoundNonFinalImpl());
  }

  // True if a concrete impl witness was found or a non-final impl. In the
  // latter case the InstId of the impl's witness is not returned, only the fact
  // that it exists.
  auto has_value() const -> bool {
    return std::holds_alternative<FoundNonFinalImpl>(result_) ||
           std::get<SemIR::InstId>(result_).has_value();
  }

  // True if there is a concrete witness in the result. If false, and