impl.cpp 1.3 KB

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