impl.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 `impl_function_id` is a valid implementation of the function
  29. // described in the interface as `interface_function_id`. Returns the value to
  30. // put into the corresponding slot in the witness table, which can be
  31. // `ErrorInst::InstId` if the function is not usable.
  32. auto CheckAssociatedFunctionImplementation(
  33. Context& context, SemIR::FunctionType interface_function_type,
  34. SemIR::InstId impl_decl_id, SemIR::TypeId self_type_id,
  35. SemIR::InstId witness_inst_id, bool defer_thunk_definition)
  36. -> SemIR::InstId;
  37. // Checks that the constraint specified for the impl is valid and identified.
  38. // Returns the interface that the impl implements. On error, issues a diagnostic
  39. // and returns `None`.
  40. auto CheckConstraintIsInterface(Context& context, SemIR::InstId impl_decl_id,
  41. SemIR::TypeInstId constraint_id)
  42. -> SemIR::SpecificInterface;
  43. // Returns the implicit `Self` type for an `impl` when it's in a `class`
  44. // declaration.
  45. auto GetImplDefaultSelfType(Context& context) -> SemIR::TypeId;
  46. // For `StartImplDecl`, additional details for an `extend impl` declaration.
  47. struct ExtendImplDecl {
  48. Parse::NodeId self_type_node_id;
  49. SemIR::TypeId constraint_type_id;
  50. Parse::NodeId extend_node_id;
  51. };
  52. // Starts an impl declaration. The caller is responsible for ensuring a generic
  53. // declaration has been started. This returns the produced `ImplId` and
  54. // `ImplDecl`'s `InstId`.
  55. //
  56. // The `impl` should be constructed with a placeholder `ImplDecl` which this
  57. // will add the `ImplId` to.
  58. auto StartImplDecl(Context& context, SemIR::LocId loc_id,
  59. SemIR::LocId implicit_params_loc_id, SemIR::Impl impl,
  60. bool is_definition,
  61. std::optional<ExtendImplDecl> extend_impl)
  62. -> std::pair<SemIR::ImplId, SemIR::InstId>;
  63. } // namespace Carbon::Check
  64. #endif // CARBON_TOOLCHAIN_CHECK_IMPL_H_