impl_lookup.h 2.2 KB

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