impl.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. // Finds an existing `Impl` if the `impl` is a redeclaration. Otherwise,
  44. // finishes construction of the `impl`, adds it to the ImplStore, and returns
  45. // the new `ImplId`. This ensures all redeclarations share the same `ImplId`.
  46. //
  47. // If the impl is modified with `extend` then the parent's scope is extended
  48. // with it.
  49. auto GetOrAddImpl(Context& context, SemIR::LocId loc_id,
  50. SemIR::LocId implicit_params_loc_id, SemIR::Impl impl,
  51. bool is_definition, Parse::NodeId extend_node)
  52. -> SemIR::ImplId;
  53. } // namespace Carbon::Check
  54. #endif // CARBON_TOOLCHAIN_CHECK_IMPL_H_