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. // If the facet type extends `Self`. When true, the `self_id` will be `Self`.
  22. bool extend_self;
  23. // The location of the `require` declaration.
  24. InstId decl_id;
  25. // The interface or named constraint which contains the `require` declaration.
  26. NameScopeId parent_scope_id;
  27. // A `require` declaration is always generic over `Self` since it's inside an
  28. // interface or named constraint definition.
  29. GenericId generic_id;
  30. auto Print(llvm::raw_ostream& out) const -> void {
  31. out << '{';
  32. out << "self_id: " << self_id
  33. << ", facet_type_inst_id: " << facet_type_inst_id
  34. << ", extend_self: " << (extend_self ? "true" : "false")
  35. << ", parent_scope: " << parent_scope_id;
  36. out << '}';
  37. }
  38. };
  39. using RequireImplsStore =
  40. ValueStore<RequireImplsId, RequireImpls, Tag<CheckIRId>>;
  41. using RequireImplsBlockStore =
  42. BlockValueStore<RequireImplsBlockId, RequireImplsId, Tag<CheckIRId>>;
  43. } // namespace Carbon::SemIR
  44. #endif // CARBON_TOOLCHAIN_SEM_IR_REQUIRE_IMPLS_H_