impl.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132
  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 = sem_ir_.types().TryGetAs<FacetType>(facet_type_id)) {
  14. const FacetTypeInfo& facet_type_info =
  15. sem_ir_.facet_types().Get(facet_type->facet_type_id);
  16. if (auto interface_type = facet_type_info.TryAsSingleInterface()) {
  17. interface_id = interface_type->interface_id;
  18. specific_id = interface_type->specific_id;
  19. }
  20. }
  21. return LookupBucketRef(
  22. *this, lookup_
  23. .Insert(std::tuple{self_id, interface_id, specific_id},
  24. [] { return ImplOrLookupBucketId::None; })
  25. .value());
  26. }
  27. } // namespace Carbon::SemIR