interface.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_with_self_specific_id,
  27. SemIR::GenericId generic_id, SemIR::SpecificId enclosing_specific_id)
  28. -> 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(
  32. Context& context, SemIR::SpecificId interface_with_self_specific_id,
  33. SemIR::InstId decl_id) -> SemIR::TypeId;
  34. // Creates a symbolic binding for `Self` of type `type_id` in the scope of
  35. // `scope_id`.
  36. //
  37. // Returns the symbolic binding instruction.
  38. auto AddSelfSymbolicBindingToScope(Context& context,
  39. SemIR::LocId definition_loc_id,
  40. SemIR::TypeId type_id,
  41. SemIR::NameScopeId scope_id,
  42. bool is_template) -> SemIR::InstId;
  43. // Given a search result `lookup_result` for `name`, returns the previous valid
  44. // declaration of `name` if there is one. The `entity` is a new decl of the same
  45. // `name`, and the existing decl need to be of the same entity type. Otherwise,
  46. // produces diagnostics if needed and returns nullopt.
  47. template <typename EntityT>
  48. requires SameAsOneOf<EntityT, SemIR::Interface, SemIR::NamedConstraint>
  49. auto TryGetExistingDecl(Context& context, const NameComponent& name,
  50. SemIR::ScopeLookupResult lookup_result,
  51. const EntityT& entity, bool is_definition)
  52. -> std::optional<SemIR::Inst>;
  53. } // namespace Carbon::Check
  54. #endif // CARBON_TOOLCHAIN_CHECK_INTERFACE_H_