facet_type.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. // Creates a impl witness instruction for a facet type. The facet type is
  15. // required to be complete if `is_definition` is true or the facet type has
  16. // rewrites. Otherwise a placeholder witness is created, and
  17. // `AllocateFacetTypeImplWitness` can be used at the `impl` definition.
  18. //
  19. // Adds and returns an `ImplWitness` instruction (created with location set to
  20. // `witness_loc_id`) that shows "`Self` type" of type "facet type" (the value of
  21. // the `facet_type_inst_id` instruction) implements interface
  22. // `interface_to_witness`, which must be an interface required by "facet type"
  23. // (as determined by `RequireIdentifiedFacetType`). This witness reflects the
  24. // values assigned to associated constant members of that interface by rewrite
  25. // constraints in the facet type. `self_specific_id` will be the `specific_id`
  26. // of the resulting witness.
  27. //
  28. // `self_type_inst_id` is an instruction that evaluates to the `Self` type of
  29. // the facet type. For example, in `T:! X where ...`, we will bind the `.Self`
  30. // of the `where` facet type to `T`, and in `(X where ...) where ...`, we will
  31. // bind the inner `.Self` to the outer `.Self`.
  32. //
  33. // If the facet type contains a rewrite, we may have deferred converting the
  34. // rewritten value to the type of the associated constant. That conversion
  35. // will also be performed as part of resolution, and may depend on the
  36. // `Self` type.
  37. auto InitialFacetTypeImplWitness(
  38. Context& context, SemIR::LocId witness_loc_id,
  39. SemIR::TypeInstId facet_type_inst_id, SemIR::TypeInstId self_type_inst_id,
  40. const SemIR::SpecificInterface& interface_to_witness,
  41. SemIR::SpecificId self_specific_id, bool is_definition) -> SemIR::InstId;
  42. // Returns `true` if the facet type is complete. Otherwise issues a diagnostic
  43. // and returns `false`.
  44. auto RequireCompleteFacetTypeForImplDefinition(
  45. Context& context, SemIR::LocId loc_id, SemIR::TypeInstId facet_type_inst_id)
  46. -> bool;
  47. // Replaces the placeholder created by `InitialFacetTypeImplWitness` with an
  48. // empty witness table of the right size. Requires the interface designated by
  49. // `interface_id` to be complete.
  50. auto AllocateFacetTypeImplWitness(Context& context,
  51. SemIR::InterfaceId interface_id,
  52. SemIR::InstBlockId witness_id) -> void;
  53. } // namespace Carbon::Check
  54. #endif // CARBON_TOOLCHAIN_CHECK_FACET_TYPE_H_