pattern_match.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 outputs of CalleePatternMatch.
  10. // TODO: Rename or remove this struct.
  11. struct ParameterBlocks {
  12. // The `Call` parameters of the function.
  13. SemIR::InstBlockId call_params_id;
  14. // The return slot.
  15. // TODO: Drop this and just use the last element of above?
  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. // Emits the pattern-match IR for the declaration of a parameterized entity with
  26. // the given implicit and explicit parameter patterns, and the given return slot
  27. // pattern (any of which may be invalid if not applicable). This IR performs the
  28. // callee side of pattern matching, starting at the `ParamPattern` insts, and
  29. // matching them against the corresponding `Call` parameters (see
  30. // entity_with_params_base.h for the definition of that term).
  31. auto CalleePatternMatch(Context& context,
  32. SemIR::InstBlockId implicit_param_patterns_id,
  33. SemIR::InstBlockId param_patterns_id,
  34. SemIR::InstId return_slot_pattern_id)
  35. -> ParameterBlocks;
  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.
  39. auto CallerPatternMatch(Context& context, SemIR::SpecificId specific_id,
  40. SemIR::InstId self_pattern_id,
  41. SemIR::InstBlockId param_patterns_id,
  42. SemIR::InstId return_slot_pattern_id,
  43. SemIR::InstId self_arg_id,
  44. llvm::ArrayRef<SemIR::InstId> arg_refs,
  45. SemIR::InstId return_slot_arg_id) -> SemIR::InstBlockId;
  46. } // namespace Carbon::Check
  47. #endif // CARBON_TOOLCHAIN_CHECK_PATTERN_MATCH_H_