custom_witness.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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_CUSTOM_WITNESS_H_
  5. #define CARBON_TOOLCHAIN_CHECK_CUSTOM_WITNESS_H_
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/sem_ir/ids.h"
  8. namespace Carbon::Check {
  9. // Builds a witness that the given type implements the given interface,
  10. // populating it with the specified set of values. Returns a corresponding
  11. // lookup result. Produces a diagnostic and returns `None` if the specified
  12. // values aren't suitable for the interface.
  13. auto BuildCustomWitness(Context& context, SemIR::LocId loc_id,
  14. SemIR::ConstantId query_self_const_id,
  15. SemIR::SpecificInterfaceId query_specific_interface_id,
  16. llvm::ArrayRef<SemIR::InstId> values) -> SemIR::InstId;
  17. // Builds a witness that the given type is copyable via a primitive copy.
  18. auto BuildPrimitiveCopyWitness(
  19. Context& context, SemIR::LocId loc_id, SemIR::NameScopeId parent_scope_id,
  20. SemIR::ConstantId query_self_const_id,
  21. SemIR::SpecificInterfaceId query_specific_interface_id) -> SemIR::InstId;
  22. // Given an interface, returns the corresponding enum if it's covered by
  23. // `CoreInterface`, or `Unknown` if it's some other interface.
  24. auto GetCoreInterface(Context& context, SemIR::InterfaceId interface_id)
  25. -> SemIR::CoreInterface;
  26. // Maps a `CoreInterface` to its `CoreIdentifier` equivalent.
  27. auto AsCoreIdentifier(SemIR::CoreInterface core_interface) -> CoreIdentifier;
  28. // Returns a witness for a `CoreInterface` `CustomWitness`. A return value of
  29. // `None` indicates a non-final witness should be produced, while `std::nullopt`
  30. // indicates the query is final and no witness can be produced.
  31. //
  32. // If `build_witness` is false, this function always returns `None` as the
  33. // witness, whether it would be final or not. It is used to indicate the
  34. // presence of such a witness without adding instructions for it.
  35. auto LookupCustomWitness(Context& context, SemIR::LocId loc_id,
  36. SemIR::CoreInterface core_interface,
  37. SemIR::ConstantId query_self_const_id,
  38. SemIR::SpecificInterfaceId query_specific_interface_id,
  39. bool build_witness) -> std::optional<SemIR::InstId>;
  40. } // namespace Carbon::Check
  41. #endif // CARBON_TOOLCHAIN_CHECK_CUSTOM_WITNESS_H_