impl.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233
  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/sem_ir/impl.h"
  5. #include "toolchain/sem_ir/file.h"
  6. namespace Carbon::SemIR {
  7. auto ImplStore::GetOrAddLookupBucket(const Impl& impl) -> LookupBucketRef {
  8. auto self_id = sem_ir_.constant_values().GetConstantInstId(impl.self_id);
  9. InterfaceId interface_id = InterfaceId::None;
  10. SpecificId specific_id = SpecificId::None;
  11. auto facet_type_id = TypeId::ForTypeConstant(
  12. sem_ir_.constant_values().Get(impl.constraint_id));
  13. if (auto facet_type =
  14. sem_ir_.types().TryGetAs<SemIR::FacetType>(facet_type_id)) {
  15. const SemIR::FacetTypeInfo& facet_type_info =
  16. sem_ir_.facet_types().Get(facet_type->facet_type_id);
  17. if (auto interface_type = facet_type_info.TryAsSingleInterface()) {
  18. interface_id = interface_type->interface_id;
  19. specific_id = interface_type->specific_id;
  20. }
  21. }
  22. return LookupBucketRef(
  23. *this, lookup_
  24. .Insert(std::tuple{self_id, interface_id, specific_id},
  25. [] { return ImplOrLookupBucketId::None; })
  26. .value());
  27. }
  28. } // namespace Carbon::SemIR