require_impls.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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_SEM_IR_REQUIRE_IMPLS_H_
  5. #define CARBON_TOOLCHAIN_SEM_IR_REQUIRE_IMPLS_H_
  6. #include "toolchain/base/block_value_store.h"
  7. #include "toolchain/base/canonical_value_store.h"
  8. #include "toolchain/sem_ir/ids.h"
  9. namespace Carbon::SemIR {
  10. // An interface requirement from an interface or named constraint, written
  11. // `require T impls Z`.
  12. //
  13. // While this comes from a `require` declaration, it is not an Entity like most
  14. // other declarations, with a name and parameters, so it does not inherit
  15. // EntityWithParamsBase.
  16. struct RequireImpls : Printable<RequireImpls> {
  17. // The self-type which must implement a given facet type.
  18. TypeInstId self_id;
  19. // Evaluates to the `FacetType` that the self-type must implement.
  20. TypeInstId facet_type_inst_id;
  21. // The `FacetTypeInfo` derived from the `facet_type_inst_id` instruction.
  22. FacetTypeId facet_type_id;
  23. // If the facet type extends `Self`. When true, the `self_id` will be `Self`.
  24. bool extend_self;
  25. // The location of the `require` declaration.
  26. InstId decl_id;
  27. // The interface or named constraint which contains the `require` declaration.
  28. NameScopeId parent_scope_id;
  29. // A `require` declaration is always generic over `Self` since it's inside an
  30. // interface or named constraint definition.
  31. GenericId generic_id;
  32. auto Print(llvm::raw_ostream& out) const -> void {
  33. out << '{';
  34. out << "self_id: " << self_id
  35. << ", facet_type_inst_id: " << facet_type_inst_id
  36. << ", parent_scope: " << parent_scope_id;
  37. out << '}';
  38. }
  39. };
  40. using RequireImplsStore = ValueStore<RequireImplsId, RequireImpls>;
  41. using RequireImplsBlockStore =
  42. BlockValueStore<RequireImplsBlockId, RequireImplsId>;
  43. } // namespace Carbon::SemIR
  44. #endif // CARBON_TOOLCHAIN_SEM_IR_REQUIRE_IMPLS_H_