generic.h 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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) -> void;
  13. // Discard the information about the current generic entity. This should be
  14. // called instead of `FinishGenericDecl` if the corresponding `Generic` object
  15. // would not actually be used, or when recovering from an error.
  16. auto DiscardGenericDecl(Context& context) -> void;
  17. // Finish processing a potentially generic declaration and produce a
  18. // corresponding generic object. Returns SemIR::GenericId::None if this
  19. // declaration is not actually generic.
  20. auto BuildGeneric(Context& context, SemIR::InstId decl_id) -> SemIR::GenericId;
  21. // Builds eval block for the declaration.
  22. auto FinishGenericDecl(Context& context, SemIRLoc loc,
  23. SemIR::GenericId generic_id) -> void;
  24. // BuildGeneric() and FinishGenericDecl() combined. Normally you would call this
  25. // function unless the caller has work to do between the two steps.
  26. auto BuildGenericDecl(Context& context, SemIR::InstId decl_id)
  27. -> SemIR::GenericId;
  28. // Merge a redeclaration of an entity that might be a generic into the original
  29. // declaration.
  30. auto FinishGenericRedecl(Context& context, SemIR::InstId decl_id,
  31. 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, SemIRLoc loc, SemIR::GenericId generic_id,
  46. llvm::ArrayRef<SemIR::InstId> args) -> SemIR::SpecificId;
  47. // Builds a new specific or finds an existing one in the case where the argument
  48. // list has already been converted into an instruction block. `args_id` should
  49. // be a canonical instruction block referring to constants.
  50. auto MakeSpecific(Context& context, SemIRLoc loc, SemIR::GenericId generic_id,
  51. SemIR::InstBlockId args_id) -> SemIR::SpecificId;
  52. // Builds the specific that describes how the generic should refer to itself.
  53. // For example, for a generic `G(T:! type)`, this is the specific `G(T)`. If
  54. // `generic_id` is `None`, returns `None`.
  55. auto MakeSelfSpecific(Context& context, SemIRLoc loc,
  56. SemIR::GenericId generic_id) -> SemIR::SpecificId;
  57. // Attempts to resolve the definition of the given specific, by evaluating the
  58. // eval block of the corresponding generic and storing a corresponding value
  59. // block in the specific. Returns false if a definition is not available.
  60. auto ResolveSpecificDefinition(Context& context, SemIRLoc loc,
  61. SemIR::SpecificId specific_id) -> bool;
  62. // Returns an instruction describing the entity named by the given specific.
  63. // This is used to name the entity in diagnostics.
  64. auto GetInstForSpecific(Context& context, SemIR::SpecificId specific_id)
  65. -> SemIR::InstId;
  66. } // namespace Carbon::Check
  67. #endif // CARBON_TOOLCHAIN_CHECK_GENERIC_H_