generic.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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_GENERIC_H_
  5. #define CARBON_TOOLCHAIN_CHECK_GENERIC_H_
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/sem_ir/ids.h"
  8. namespace Carbon::Check {
  9. // Start processing a declaration or definition that might be a generic entity.
  10. auto StartGenericDecl(Context& /*context*/) -> void;
  11. // Start processing a declaration or definition that might be a generic entity.
  12. auto StartGenericDefinition(Context& /*context*/,
  13. SemIR::GenericId /*generic_id*/) -> void;
  14. // Finish processing a potentially generic declaration and produce a
  15. // corresponding generic object. Returns SemIR::GenericId::Invalid if this
  16. // declaration is not actually generic.
  17. auto FinishGenericDecl(Context& context, SemIR::InstId decl_id)
  18. -> SemIR::GenericId;
  19. // Merge a redeclaration of an entity that might be a generic into the original
  20. // declaration.
  21. auto FinishGenericRedecl(Context& context, SemIR::InstId decl_id,
  22. SemIR::GenericId generic_id) -> void;
  23. // Finish processing a potentially generic definition.
  24. auto FinishGenericDefinition(Context& context, SemIR::GenericId generic_id)
  25. -> void;
  26. // Builds a new generic instance, or finds an existing one if this instance of
  27. // this generic has already been referenced. Performs substitution into the
  28. // declaration, but not the definition, of the generic.
  29. //
  30. // `args_id` should be a canonical instruction block referring to constants.
  31. auto MakeGenericInstance(Context& context, SemIR::GenericId generic_id,
  32. SemIR::InstBlockId args_id)
  33. -> SemIR::GenericInstanceId;
  34. // Builds the generic instance corresponding to the generic itself. For example,
  35. // for a generic `G(T:! type)`, this is `G(T)`.
  36. auto MakeGenericSelfInstance(Context& context, SemIR::GenericId generic_id)
  37. -> SemIR::GenericInstanceId;
  38. } // namespace Carbon::Check
  39. #endif // CARBON_TOOLCHAIN_CHECK_GENERIC_H_