impl.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_IMPL_H_
  5. #define CARBON_TOOLCHAIN_CHECK_IMPL_H_
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/sem_ir/ids.h"
  8. namespace Carbon::Check {
  9. // Returns the initial witness value for a new `impl` declaration.
  10. //
  11. // `has_definition` is whether this declaration is immediately followed by the
  12. // opening of the definition.
  13. auto ImplWitnessForDeclaration(Context& context, const SemIR::Impl& impl,
  14. bool has_definition) -> SemIR::InstId;
  15. // Update `impl`'s witness at the start of a definition.
  16. auto ImplWitnessStartDefinition(Context& context, SemIR::Impl& impl) -> void;
  17. // Adds the function members to the witness for `impl`.
  18. auto FinishImplWitness(Context& context, SemIR::ImplId impl_id) -> void;
  19. // Sets all unset members of the witness for `impl` to the error instruction and
  20. // sets the witness id in the `Impl` to an error.
  21. auto FillImplWitnessWithErrors(Context& context, SemIR::Impl& impl) -> void;
  22. // Sets the `ImplId` in the `ImplWitnessTable`.
  23. auto AssignImplIdInWitness(Context& context, SemIR::ImplId impl_id,
  24. SemIR::InstId witness_id) -> void;
  25. // Returns whether the impl is either `final` explicitly, or implicitly due to
  26. // being concrete.
  27. auto IsImplEffectivelyFinal(Context& context, const SemIR::Impl& impl) -> bool;
  28. // Checks that the constraint specified for the impl is valid and identified.
  29. // Returns the interface that the impl implements. On error, issues a diagnostic
  30. // and returns `None`.
  31. auto CheckConstraintIsInterface(Context& context, SemIR::InstId impl_decl_id,
  32. SemIR::TypeInstId constraint_id)
  33. -> SemIR::SpecificInterface;
  34. // Returns the implicit `Self` type for an `impl` when it's in a `class`
  35. // declaration.
  36. auto GetImplDefaultSelfType(Context& context) -> SemIR::TypeId;
  37. // For `StartImplDecl`, additional details for an `extend impl` declaration.
  38. struct ExtendImplDecl {
  39. Parse::NodeId self_type_node_id;
  40. SemIR::TypeId constraint_type_id;
  41. Parse::NodeId extend_node_id;
  42. };
  43. // Starts an impl declaration. The caller is responsible for ensuring a generic
  44. // declaration has been started. This returns the produced `ImplId` and
  45. // `ImplDecl`'s `InstId`.
  46. //
  47. // The `impl` should be constructed with a placeholder `ImplDecl` which this
  48. // will add the `ImplId` to.
  49. auto StartImplDecl(Context& context, SemIR::LocId loc_id,
  50. SemIR::LocId implicit_params_loc_id, SemIR::Impl impl,
  51. bool is_definition,
  52. std::optional<ExtendImplDecl> extend_impl)
  53. -> std::pair<SemIR::ImplId, SemIR::InstId>;
  54. } // namespace Carbon::Check
  55. #endif // CARBON_TOOLCHAIN_CHECK_IMPL_H_