interface.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #ifndef CARBON_TOOLCHAIN_CHECK_INTERFACE_H_
  5. #define CARBON_TOOLCHAIN_CHECK_INTERFACE_H_
  6. #include <optional>
  7. #include "toolchain/check/context.h"
  8. #include "toolchain/check/decl_name_stack.h"
  9. #include "toolchain/check/name_component.h"
  10. #include "toolchain/parse/node_ids.h"
  11. #include "toolchain/sem_ir/entity_with_params_base.h"
  12. #include "toolchain/sem_ir/ids.h"
  13. #include "toolchain/sem_ir/name_scope.h"
  14. #include "toolchain/sem_ir/typed_insts.h"
  15. namespace Carbon::Check {
  16. // Builds and returns an associated entity for `interface_id` corresponding to
  17. // the declaration `decl_id`, which can be an associated function or an
  18. // associated constant. Registers the associated entity in the list for the
  19. // interface.
  20. auto BuildAssociatedEntity(Context& context, SemIR::InterfaceId interface_id,
  21. SemIR::InstId decl_id) -> SemIR::InstId;
  22. // Gets the self specific of a generic declaration that is an interface member,
  23. // given a specific for the interface plus a type to use as `Self`.
  24. auto GetSelfSpecificForInterfaceMemberWithSelfType(
  25. Context& context, SemIR::LocId loc_id,
  26. SemIR::SpecificId interface_specific_id, SemIR::GenericId generic_id,
  27. SemIR::SpecificId enclosing_specific_id, SemIR::TypeId self_type_id,
  28. SemIR::InstId witness_inst_id) -> SemIR::SpecificId;
  29. // Gets the type of the specified associated entity, given the specific for the
  30. // interface and the type of `Self`.
  31. auto GetTypeForSpecificAssociatedEntity(Context& context, SemIR::LocId loc_id,
  32. SemIR::SpecificId interface_specific_id,
  33. SemIR::InstId decl_id,
  34. SemIR::TypeId self_type_id,
  35. SemIR::InstId self_witness_id)
  36. -> SemIR::TypeId;
  37. // Creates a symbolic binding for `Self` of type `type_id` in the scope of
  38. // `scope_id`, and add the name `Self` for the compile time binding.
  39. //
  40. // Returns the symbolic binding instruction.
  41. auto AddSelfGenericParameter(Context& context, SemIR::LocId definition_loc_id,
  42. SemIR::TypeId type_id, SemIR::NameScopeId scope_id,
  43. bool is_template) -> SemIR::InstId;
  44. // Given a search result `lookup_result` for `name`, returns the previous valid
  45. // declaration of `name` if there is one. The `entity` is a new decl of the same
  46. // `name`, and the existing decl need to be of the same entity type. Otherwise,
  47. // produces diagnostics if needed and returns nullopt.
  48. template <typename EntityT>
  49. requires SameAsOneOf<EntityT, SemIR::Interface, SemIR::NamedConstraint>
  50. auto TryGetExistingDecl(Context& context, const NameComponent& name,
  51. SemIR::ScopeLookupResult lookup_result,
  52. const EntityT& entity, bool is_definition)
  53. -> std::optional<SemIR::Inst>;
  54. } // namespace Carbon::Check
  55. #endif // CARBON_TOOLCHAIN_CHECK_INTERFACE_H_