require_impls.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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_REQUIRE_IMPLS_H_
  5. #define CARBON_TOOLCHAIN_CHECK_REQUIRE_IMPLS_H_
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/sem_ir/ids.h"
  8. #include "toolchain/sem_ir/require_impls.h"
  9. namespace Carbon::Check {
  10. // A type-safe wrapper around the specific id of a RequireImpls entity.
  11. // Constructed from a specific for its enclosing interface or constraint entity.
  12. struct RequireImplsSpecific {
  13. SemIR::SpecificId specific_id;
  14. };
  15. // Get the specific of a RequireImpls from the specific of its enclosing
  16. // interface or named constraint. Since a `require` declaration can not
  17. // introduce new generic bindings, the specific for the RequireImpls can be
  18. // constructed from the enclosing one.
  19. auto GetRequireImplsSpecificFromEnclosingSpecific(
  20. Context& context, const SemIR::RequireImpls& require,
  21. SemIR::SpecificId enclosing_specific_id) -> RequireImplsSpecific;
  22. // Like GetRequireImplsSpecificFromEnclosingSpecific but the `Self` value in the
  23. // specific is replaced by a given facet value.
  24. auto GetRequireImplsSpecificFromEnclosingSpecificWithSelfFacetValue(
  25. Context& context, const SemIR::RequireImpls& require,
  26. SemIR::SpecificId enclosing_specific_id,
  27. SemIR::ConstantId self_facet_value_id) -> RequireImplsSpecific;
  28. // Returns the constant value of `inst_id` from inside a RequireImpls
  29. // declaration, mapped into `enclosing_specific_id`. If an error results, it
  30. // returns ErrorInst.
  31. //
  32. // An error can occur during monomorphization when the self-type was valid as a
  33. // symbolic but becomes invalid with a more concrete specific.
  34. //
  35. // RequireImpls is always generic, so the instructions inside it must have a
  36. // specific applied. That specific is constructed from a specific for the
  37. // enclosing generic entity, with GetRequireImplsSpecificFromEnclosingSpecific.
  38. auto GetConstantValueInRequireImplsSpecific(Context& context,
  39. RequireImplsSpecific specific,
  40. SemIR::InstId inst_id)
  41. -> SemIR::ConstantId;
  42. } // namespace Carbon::Check
  43. #endif // CARBON_TOOLCHAIN_CHECK_REQUIRE_IMPLS_H_