pattern_match.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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_PATTERN_MATCH_H_
  5. #define CARBON_TOOLCHAIN_CHECK_PATTERN_MATCH_H_
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/sem_ir/function.h"
  8. #include "toolchain/sem_ir/ids.h"
  9. namespace Carbon::Check {
  10. // TODO: Find a better place for this overview, once it has stabilized.
  11. //
  12. // The signature pattern of a function call is matched partially by the caller
  13. // and partially by the callee. `ParamPattern` insts mark the boundary
  14. // between the two: pattern insts that are descendants of a `ParamPattern`
  15. // are matched by the callee, and pattern insts that have a `ParamPattern`
  16. // as a descendant are matched by the caller.
  17. // Emits the pattern-match IR for the declaration of a parameterized entity with
  18. // the given implicit and explicit parameter patterns, and the given return
  19. // patterns (any of which may be `None` if not applicable). This IR performs the
  20. // callee side of pattern matching, starting at the `ParamPattern` insts, and
  21. // matching them against the corresponding `Call` parameters (see
  22. // entity_with_params_base.h for the definition of that term).
  23. // Returns the IDs of inst blocks consisting of references to the `Call`
  24. // parameter patterns and `Call` parameters of the function, as well as
  25. // the implicit, explicit, and return index ranges of those blocks.
  26. struct CalleePatternMatchResults {
  27. SemIR::InstBlockId call_param_patterns_id;
  28. SemIR::InstBlockId call_params_id;
  29. SemIR::Function::CallParamIndexRanges param_ranges;
  30. };
  31. auto CalleePatternMatch(Context& context,
  32. SemIR::InstBlockId implicit_param_patterns_id,
  33. SemIR::InstBlockId param_patterns_id,
  34. SemIR::InstBlockId return_patterns_id)
  35. -> CalleePatternMatchResults;
  36. // Emits the pattern-match IR for matching the given arguments with the given
  37. // parameter patterns, and returns an inst block of the arguments that should
  38. // be passed to the `Call` inst. `is_operator_syntax` indicates that this call
  39. // was generated from an operator rather than from function call syntax, so
  40. // arguments to `ref` parameters aren't required to have `ref` tags.
  41. auto CallerPatternMatch(Context& context, SemIR::SpecificId specific_id,
  42. SemIR::InstId self_pattern_id,
  43. SemIR::InstBlockId param_patterns_id,
  44. SemIR::InstBlockId return_patterns_id,
  45. SemIR::InstId self_arg_id,
  46. llvm::ArrayRef<SemIR::InstId> arg_refs,
  47. llvm::ArrayRef<SemIR::InstId> return_arg_ids,
  48. bool is_operator_syntax) -> SemIR::InstBlockId;
  49. // Emits the pattern-match IR for a local pattern matching operation with the
  50. // given pattern and scrutinee.
  51. auto LocalPatternMatch(Context& context, SemIR::InstId pattern_id,
  52. SemIR::InstId scrutinee_id) -> void;
  53. } // namespace Carbon::Check
  54. #endif // CARBON_TOOLCHAIN_CHECK_PATTERN_MATCH_H_