Repository: carbon-language/carbon-lang
File: toolchain/check/eval.cpp (C++)

Code before:
                eval_context.facet_types().Get(facet_type.facet_type_id);
            // The way to prevent lookup into the interface requirements of a
            // facet type is to put it to the right of a `.Self impls`, which we
            // accomplish by putting them into `self_impls_constraints`.
            llvm::append_range(info.self_impls_constraints,
                               more_info.extend_constraints);
            llvm::append_range(info.self_impls_constraints,
                               more_info.self_impls_constraints);
            // Other requirements are copied in.
            llvm::append_range(info.rewrite_constraints,
                               more_info.rewrite_constraints);
            info.other_requirements |= more_info.other_requirements;
          }
          continue;
        }

        // TODO: Handle `impls` constraints beyond `.Self impls`.
        info.other_requirements = true;
        continue;
      }

      // TODO: Handle other requirements
      info.other_requirements = true;
    }
  }

  auto const_info = GetConstantFacetTypeInfo(
      eval_context, SemIR::LocId(inst_id), info, &phase);
  return MakeFacetTypeResult(eval_context.context(), const_info, phase);
}

// Implementation for `TryEvalInst`, wrapping `Context` with `EvalContext`.
static auto TryEvalInstInContext(EvalContext& eval_context,
                                 SemIR::InstId inst_id, SemIR::Inst inst)
    -> SemIR::ConstantId {
  using EvalInstFn =
      auto(EvalContext & eval_context, SemIR::InstId inst_id, SemIR::Inst inst)
          ->SemIR::ConstantId;
  static constexpr EvalInstFn* EvalInstFns[] = {
#define CARBON_SEM_IR_INST_KIND(Kind) &TryEvalTypedInst<SemIR::Kind>,
#include "toolchain/sem_ir/inst_kind.def"
  };
  [[clang::musttail]] return EvalInstFns[inst.kind().AsInt()](eval_context,
                                                              inst_id, inst);
}

auto TryEvalInstUnsafe(Context& context, SemIR::InstId inst_id,
                       SemIR::Inst inst) -> SemIR::ConstantId {
  EvalContext eval_context(&context, SemIR::LocId(inst_id));
  return TryEvalInstInContext(eval_context, inst_id, inst);
}

Review comment (suggestion):
Note, this seems like it'd end up being structured as an `else` or `switch` from the `if` on 2018-2019 (mainly noting this due to my above comment, regarding flow). Not asking for changes, just stating the understanding as I think about the above comment.

Code after:
            auto facet_type = eval_context.insts().GetAs<SemIR::FacetType>(
                eval_context.constant_values().GetConstantInstId(
                    impls->rhs_id));
            const auto& more_info =
                eval_context.facet_types().Get(facet_type.facet_type_id);
            // The way to prevent lookup into the interface requirements of a
            // facet type is to put it to the right of a `.Self impls`, which we
            // accomplish by putting them into `self_impls_constraints`.
            llvm::append_range(info.self_impls_constraints,
                               more_info.extend_constraints);
            llvm::append_range(info.self_impls_constraints,
                               more_info.self_impls_constraints);
            // Other requirements are copied in.
            llvm::append_range(info.rewrite_constraints,
                               more_info.rewrite_constraints);
            info.other_requirements |= more_info.other_requirements;
          }
          continue;
        }

        // TODO: Handle `impls` constraints beyond `.Self impls`.
        info.other_requirements = true;
        continue;
      }

      // TODO: Handle other requirements
      info.other_requirements = true;
    }
  }

  auto const_info = GetConstantFacetTypeInfo(
      eval_context, SemIR::LocId(inst_id), info, &phase);
  return MakeFacetTypeResult(eval_context.context(), const_info, phase);
}

// Implementation for `TryEvalInst`, wrapping `Context` with `EvalContext`.
static auto TryEvalInstInContext(EvalContext& eval_context,
                                 SemIR::InstId inst_id, SemIR::Inst inst)
    -> SemIR::ConstantId {
  using EvalInstFn =
      auto(EvalContext & eval_context, SemIR::InstId inst_id, SemIR::Inst inst)
          ->SemIR::ConstantId;
  static constexpr EvalInstFn* EvalInstFns[] = {
#define CARBON_SEM_IR_INST_KIND(Kind) &TryEvalTypedInst<SemIR::Kind>,
#include "toolchain/sem_ir/inst_kind.def"
  };
  [[clang::musttail]] return EvalInstFns[inst.kind().AsInt()](eval_context,
                                                              inst_id, inst);
}

auto TryEvalInstUnsafe(Context& context, SemIR::InstId inst_id,