impl_lookup.h 2.2 KB

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