impl_lookup.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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_CPP_IMPL_LOOKUP_H_
  5. #define CARBON_TOOLCHAIN_CHECK_CPP_IMPL_LOOKUP_H_
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/check/custom_witness.h"
  8. #include "toolchain/check/impl_lookup.h"
  9. #include "toolchain/check/interface.h"
  10. #include "toolchain/check/type_structure.h"
  11. #include "toolchain/sem_ir/ids.h"
  12. #include "toolchain/sem_ir/specific_interface.h"
  13. namespace Carbon::Check {
  14. // Performs lookup for an impl witness for a query involving C++ types.
  15. // Shouldn't be called with `CoreInterface::Unknown`, because only core
  16. // interfaces can have lookup results. Returns a witness value, or `None` if a
  17. // synthesized C++ witness should not be used.
  18. //
  19. // Given a known `core_interface`, we can synthesize a witness based on C++
  20. // operator overloads or special member functions. Performs the suitable C++
  21. // lookup to determine if this interface should be considered implemented for
  22. // the specified type, and if so, synthesizes and returns a suitable witness.
  23. //
  24. // `best_impl_type_structure` provides the type structure of the best-matching
  25. // impl declaration. If this is better than every viable C++ candidate, a "none"
  26. // result will be returned. If this is worse than the best viable C++ candidate
  27. // according to C++ rules, a witness for the C++ candidate will be returned.
  28. // Otherwise, it is at least as good as the best viable C++ candidate, but there
  29. // is some C++ candidate that has a better type structure, in which case the
  30. // result is ambiguous and we diagnose an error. This parameter can be null if
  31. // there is no usable impl for this query.
  32. //
  33. // `best_impl_loc_id` gives the location of the impl corresponding to the best
  34. // type structure, and can be `None` if `best_impl_type_structure` is null. This
  35. // parameter is used only for ambiguity diagnostics.
  36. auto LookupCppImpl(Context& context, SemIR::LocId loc_id,
  37. SemIR::CoreInterface core_interface,
  38. SemIR::ConstantId query_self_const_id,
  39. SemIR::SpecificInterfaceId query_specific_interface_id,
  40. const TypeStructure* best_impl_type_structure,
  41. SemIR::LocId best_impl_loc_id) -> SemIR::InstId;
  42. } // namespace Carbon::Check
  43. #endif // CARBON_TOOLCHAIN_CHECK_CPP_IMPL_LOOKUP_H_