generic.h 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/entity_with_params_base.h"
  8. #include "toolchain/sem_ir/ids.h"
  9. namespace Carbon::Check {
  10. // Start processing a declaration or definition that might be a generic entity.
  11. auto StartGenericDecl(Context& context) -> void;
  12. // Start processing a declaration or definition that might be a generic entity.
  13. auto StartGenericDefinition(Context& context) -> void;
  14. // Discard the information about the current generic entity. This should be
  15. // called instead of `FinishGenericDecl` if the corresponding `Generic` object
  16. // would not actually be used, or when recovering from an error.
  17. auto DiscardGenericDecl(Context& context) -> void;
  18. // Finish processing a potentially generic declaration and produce a
  19. // corresponding generic object. Returns SemIR::GenericId::None if this
  20. // declaration is not actually generic.
  21. auto BuildGeneric(Context& context, SemIR::InstId decl_id) -> SemIR::GenericId;
  22. // Builds eval block for the declaration.
  23. auto FinishGenericDecl(Context& context, SemIR::LocId loc_id,
  24. SemIR::GenericId generic_id) -> void;
  25. // BuildGeneric() and FinishGenericDecl() combined. Normally you would call this
  26. // function unless the caller has work to do between the two steps.
  27. auto BuildGenericDecl(Context& context, SemIR::InstId decl_id)
  28. -> SemIR::GenericId;
  29. // Merge a redeclaration of an entity that might be a generic into the original
  30. // declaration.
  31. auto FinishGenericRedecl(Context& context, SemIR::GenericId generic_id) -> void;
  32. // Finish processing a potentially generic definition.
  33. auto FinishGenericDefinition(Context& context, SemIR::GenericId generic_id)
  34. -> void;
  35. // Builds and returns an eval block, given the list of canonical symbolic
  36. // constants that the instructions in the eval block should produce. This is
  37. // used when importing a generic.
  38. auto RebuildGenericEvalBlock(Context& context, SemIR::GenericId generic_id,
  39. SemIR::GenericInstIndex::Region region,
  40. llvm::ArrayRef<SemIR::InstId> const_ids)
  41. -> SemIR::InstBlockId;
  42. // Builds a new specific with a given argument list, or finds an existing one if
  43. // this generic has already been referenced with these arguments. Performs
  44. // substitution into the declaration, but not the definition, of the generic.
  45. auto MakeSpecific(Context& context, SemIR::LocId loc_id,
  46. SemIR::GenericId generic_id,
  47. llvm::ArrayRef<SemIR::InstId> args) -> SemIR::SpecificId;
  48. // Builds a new specific or finds an existing one in the case where the argument
  49. // list has already been converted into an instruction block. `args_id` should
  50. // be a canonical instruction block referring to constants.
  51. auto MakeSpecific(Context& context, SemIR::LocId loc_id,
  52. SemIR::GenericId generic_id, SemIR::InstBlockId args_id)
  53. -> SemIR::SpecificId;
  54. // Builds the specific that describes how the generic should refer to itself.
  55. // For example, for a generic `G(T:! type)`, this is the specific `G(T)`. If
  56. // `generic_id` is `None`, returns `None`.
  57. auto MakeSelfSpecific(Context& context, SemIR::LocId loc_id,
  58. SemIR::GenericId generic_id) -> SemIR::SpecificId;
  59. // Resolve the declaration of the given specific, by evaluating the eval block
  60. // of the corresponding generic and storing a corresponding value block in the
  61. // specific.
  62. auto ResolveSpecificDeclaration(Context& context, SemIR::LocId loc_id,
  63. SemIR::SpecificId specific_id) -> void;
  64. // Attempts to resolve the definition of the given specific, by evaluating the
  65. // eval block of the corresponding generic and storing a corresponding value
  66. // block in the specific. Returns false if a definition is not available.
  67. auto ResolveSpecificDefinition(Context& context, SemIR::LocId loc_id,
  68. SemIR::SpecificId specific_id) -> bool;
  69. // Diagnoses if an entity has implicit parameters, indicating it's generic, but
  70. // is missing explicit parameters.
  71. auto DiagnoseIfGenericMissingExplicitParameters(
  72. Context& context, SemIR::EntityWithParamsBase& entity_base) -> void;
  73. } // namespace Carbon::Check
  74. #endif // CARBON_TOOLCHAIN_CHECK_GENERIC_H_