pattern_match.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. // TODO: Find a better place for this overview, once it has stabilized.
  10. //
  11. // The signature pattern of a function call is matched partially by the caller
  12. // and partially by the callee. `ParamPattern` insts mark the boundary
  13. // between the two: pattern insts that are descendants of a `ParamPattern`
  14. // are matched by the callee, and pattern insts that have a `ParamPattern`
  15. // as a descendant are matched by the caller.
  16. // Emits the pattern-match IR for the declaration of a parameterized entity with
  17. // the given implicit and explicit parameter patterns, and the given return slot
  18. // pattern (any of which may be `None` if not applicable). This IR performs the
  19. // callee side of pattern matching, starting at the `ParamPattern` insts, and
  20. // matching them against the corresponding `Call` parameters (see
  21. // entity_with_params_base.h for the definition of that term).
  22. // Returns the ID of an inst block consisting of references to the `Call`
  23. // parameters of the function.
  24. auto CalleePatternMatch(Context& context,
  25. SemIR::InstBlockId implicit_param_patterns_id,
  26. SemIR::InstBlockId param_patterns_id,
  27. SemIR::InstId return_slot_pattern_id)
  28. -> SemIR::InstBlockId;
  29. // Emits the pattern-match IR for matching the given arguments with the given
  30. // parameter patterns, and returns an inst block of the arguments that should
  31. // be passed to the `Call` inst.
  32. auto CallerPatternMatch(Context& context, SemIR::SpecificId specific_id,
  33. SemIR::InstId self_pattern_id,
  34. SemIR::InstBlockId param_patterns_id,
  35. SemIR::InstId return_slot_pattern_id,
  36. SemIR::InstId self_arg_id,
  37. llvm::ArrayRef<SemIR::InstId> arg_refs,
  38. SemIR::InstId return_slot_arg_id) -> SemIR::InstBlockId;
  39. // Emits the pattern-match IR for a local pattern matching operation with the
  40. // given pattern and scrutinee.
  41. auto LocalPatternMatch(Context& context, SemIR::InstId pattern_id,
  42. SemIR::InstId scrutinee_id) -> void;
  43. } // namespace Carbon::Check
  44. #endif // CARBON_TOOLCHAIN_CHECK_PATTERN_MATCH_H_