facet_type.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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_FACET_TYPE_H_
  5. #define CARBON_TOOLCHAIN_CHECK_FACET_TYPE_H_
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/sem_ir/ids.h"
  8. namespace Carbon::Check {
  9. // Create a FacetType typed instruction object consisting of a single
  10. // interface. The `specific_id` specifies arguments in the case the interface is
  11. // generic.
  12. auto FacetTypeFromInterface(Context& context, SemIR::InterfaceId interface_id,
  13. SemIR::SpecificId specific_id) -> SemIR::FacetType;
  14. // Adds and returns an `ImplWitness` instruction (created with location set to
  15. // `witness_loc_id`) that shows "`Self` type" of type "facet type" (the value of
  16. // the `facet_type_inst_id` instruction) implements interface
  17. // `interface_to_witness`, which must be an interface required by "facet type"
  18. // (as determined by `RequireCompleteFacetType`). This witness reflects the
  19. // values assigned to associated constant members of that interface by rewrite
  20. // constraints in the facet type. `self_specific_id` will be the `specific_id`
  21. // of the resulting witness.
  22. //
  23. // `self_type_inst_id` is an instruction that evaluates to the `Self` type of
  24. // the facet type. For example, in `T:! X where ...`, we will bind the `.Self`
  25. // of the `where` facet type to `T`, and in `(X where ...) where ...`, we will
  26. // bind the inner `.Self` to the outer `.Self`.
  27. //
  28. // If the facet type contains a rewrite, we may have deferred converting the
  29. // rewritten value to the type of the associated constant. That conversion
  30. // will also be performed as part of resolution, and may depend on the
  31. // `Self` type.
  32. auto ResolveFacetTypeImplWitness(
  33. Context& context, SemIR::LocId witness_loc_id,
  34. SemIR::InstId facet_type_inst_id, SemIR::InstId self_type_inst_id,
  35. const SemIR::SpecificInterface& interface_to_witness,
  36. SemIR::SpecificId self_specific_id) -> SemIR::InstId;
  37. } // namespace Carbon::Check
  38. #endif // CARBON_TOOLCHAIN_CHECK_FACET_TYPE_H_