impl.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "toolchain/check/impl.h"
  5. #include "toolchain/check/context.h"
  6. #include "toolchain/sem_ir/ids.h"
  7. #include "toolchain/sem_ir/impl.h"
  8. namespace Carbon::Check {
  9. auto BuildImplWitness(Context& context, SemIR::ImplId impl_id)
  10. -> SemIR::InstId {
  11. auto& impl = context.impls().Get(impl_id);
  12. CARBON_CHECK(impl.is_being_defined());
  13. // TODO: Handle non-interface constraints.
  14. auto interface_type =
  15. context.types().TryGetAs<SemIR::InterfaceType>(impl.constraint_id);
  16. if (!interface_type) {
  17. context.TODO(context.insts().GetParseNode(impl.definition_id),
  18. "impl as non-interface");
  19. return SemIR::InstId::BuiltinError;
  20. }
  21. auto interface_id = interface_type->interface_id;
  22. // TODO: Form the witness table.
  23. auto table_id = context.inst_blocks().Add({});
  24. return context.AddInst(SemIR::InterfaceWitness{
  25. context.GetBuiltinType(SemIR::BuiltinKind::WitnessType), interface_id,
  26. table_id});
  27. }
  28. } // namespace Carbon::Check