pattern_match.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/ids.h"
  8. namespace Carbon::Check {
  9. // The pattern-match counterparts of the patterns passed to CalleePatternMatch.
  10. struct ParameterBlocks {
  11. // The implicit parameter list.
  12. SemIR::InstBlockId implicit_params_id;
  13. // The explicit parameter list.
  14. SemIR::InstBlockId params_id;
  15. // The return slot.
  16. SemIR::InstId return_slot_id;
  17. };
  18. // TODO: Find a better place for this overview, once it has stabilized.
  19. //
  20. // The signature pattern of a function call is matched partially by the caller
  21. // and partially by the callee. `ParamPattern` insts mark the boundary
  22. // between the two: pattern insts that are descendants of a `ParamPattern`
  23. // are matched by the callee, and pattern insts that have a `ParamPattern`
  24. // as a descendant are matched by the caller.
  25. //
  26. // "Calling convention arguments" are the values actually passed from caller to
  27. // callee at the semantic IR level, and "calling convention parameters" are
  28. // the corresponding semantic placeholders that they bind to.
  29. // Emits the pattern-match IR for the declaration of a parameterized entity with
  30. // the given implicit and explicit parameter patterns, and the given return slot
  31. // pattern (any of which may be invalid if not applicable). This IR performs the
  32. // callee side of pattern matching, starting at the `ParamPattern` insts, and
  33. // matching them against the corresponding calling-convention parameters.
  34. auto CalleePatternMatch(Context& context,
  35. SemIR::InstBlockId implicit_param_patterns_id,
  36. SemIR::InstBlockId param_patterns_id,
  37. SemIR::InstId return_slot_pattern_id)
  38. -> ParameterBlocks;
  39. // Emits the pattern-match IR for matching the given arguments with the given
  40. // parameter patterns, and returns an inst block with one inst for each
  41. // calling convention argument. This IR performs the caller side of pattern
  42. // matching.
  43. auto CallerPatternMatch(Context& context, SemIR::SpecificId specific_id,
  44. SemIR::InstId self_pattern_id,
  45. SemIR::InstBlockId param_patterns_id,
  46. SemIR::InstId return_slot_pattern_id,
  47. SemIR::InstId self_arg_id,
  48. llvm::ArrayRef<SemIR::InstId> arg_refs,
  49. SemIR::InstId return_slot_arg_id) -> SemIR::InstBlockId;
  50. } // namespace Carbon::Check
  51. #endif // CARBON_TOOLCHAIN_CHECK_PATTERN_MATCH_H_