function.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_FUNCTION_H_
  5. #define CARBON_TOOLCHAIN_CHECK_FUNCTION_H_
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/check/decl_name_stack.h"
  8. #include "toolchain/check/subst.h"
  9. #include "toolchain/sem_ir/function.h"
  10. #include "toolchain/sem_ir/ids.h"
  11. namespace Carbon::Check {
  12. // Returns the ID of the self parameter pattern, or None.
  13. // TODO: Do this during initial traversal of implicit params.
  14. auto FindSelfPattern(Context& context,
  15. SemIR::InstBlockId implicit_param_patterns_id)
  16. -> SemIR::InstId;
  17. // Checks that `new_function` has the same return type as `prev_function`, or if
  18. // `prev_function_id` is specified, a specific version of `prev_function`.
  19. // Prints a suitable diagnostic and returns false if not. Never checks for a
  20. // syntactic match.
  21. auto CheckFunctionReturnTypeMatches(Context& context,
  22. const SemIR::Function& new_function,
  23. const SemIR::Function& prev_function,
  24. SemIR::SpecificId prev_specific_id,
  25. bool diagnose = true) -> bool;
  26. // Checks that `new_function` has the same parameter types and return type as
  27. // `prev_function`, or if `prev_function_id` is specified, a specific version of
  28. // `prev_function`. Prints a suitable diagnostic and returns false if not.
  29. //
  30. // `check_syntax` is false if the redeclaration can be called via a thunk with
  31. // implicit conversions from the original declaration.
  32. // `check_self` is false if the self declaration does not have to match (for
  33. // instance in impls of virtual functions).
  34. auto CheckFunctionTypeMatches(Context& context,
  35. const SemIR::Function& new_function,
  36. const SemIR::Function& prev_function,
  37. SemIR::SpecificId prev_specific_id,
  38. bool check_syntax, bool check_self,
  39. bool diagnose = true) -> bool;
  40. inline auto CheckFunctionTypeMatches(Context& context,
  41. const SemIR::Function& new_function,
  42. const SemIR::Function& prev_function)
  43. -> bool {
  44. return CheckFunctionTypeMatches(context, new_function, prev_function,
  45. SemIR::SpecificId::None,
  46. /*check_syntax=*/true, /*check_self=*/true);
  47. }
  48. // Checks that the scrutinee type of `return_pattern_id` in `specific_id` is
  49. // concrete. If so, it returns that type; if not, it issues an error and returns
  50. // SemIR::ErrorInst::TypeId. `return_pattern_id` must be part of a function's
  51. // return form, or the error message will be nonsensical.
  52. auto CheckFunctionReturnPatternType(Context& context, SemIR::LocId loc_id,
  53. SemIR::InstId return_pattern_id,
  54. SemIR::SpecificId specific_id)
  55. -> SemIR::TypeId;
  56. // Checks that a function declaration's signature is suitable to support a
  57. // function definition. This requires the parameter types to be complete and the
  58. // return type to be concrete.
  59. auto CheckFunctionDefinitionSignature(Context& context,
  60. SemIR::FunctionId function_id) -> void;
  61. } // namespace Carbon::Check
  62. #endif // CARBON_TOOLCHAIN_CHECK_FUNCTION_H_