mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-03 22:02:51 +01:00
Pursuant to recent decisions on #6124, switch `Destroy` to use a `CustomWitness` for its implementation. Right now this is manufacturing no-op implementation functions on each lookup, which obviously isn't ideal but is intended as a first pass. I'm mostly trying to find the right balance between updating the approach to reflect new decisions, while still breaking apart work in a way. The `CoreInterface` logic is intended to build on `CoreIdentifier` support. We have a number of additional interfaces that require specialized logic, and that'll extend pretty far with C++ interop, so it seemed easiest to have a generic function for it. That's what's replacing the logic inside C++ interop that was doing string comparisons (which could have already been moved to `CoreIdentifier`, I just missed it in my first pass). This adds `CustomWitness` support because the `Destroy` witnesses can be imported cross-file. `CustomWitness` was previously only used for C++ types, which don't yet support import, which is why that wasn't previously an issue. The addition of `query_specific_interface_id` is similarly needed in order to get correct sorting of witness blocks when imported. This PR also removes builtin constraint logic (note this is in a separate commit to help review; it's not a separate PR because it's difficult to split apart without tests breaking). This had been made generic with the expectation that destroy, copy, move, and conversions would all need related support. Under the new decision, we are not going to do blanket impls and will instead just manufacture a `CustomWitness` for everything. A lot of SemIR fingerprints change, but that's probably because the addition of `Destroy` on core classes is yielding structural changes.
50 lines
2.4 KiB
C++
50 lines
2.4 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#ifndef CARBON_TOOLCHAIN_CHECK_CPP_IMPL_LOOKUP_H_
|
|
#define CARBON_TOOLCHAIN_CHECK_CPP_IMPL_LOOKUP_H_
|
|
|
|
#include "toolchain/check/context.h"
|
|
#include "toolchain/check/custom_witness.h"
|
|
#include "toolchain/check/impl_lookup.h"
|
|
#include "toolchain/check/interface.h"
|
|
#include "toolchain/check/type_structure.h"
|
|
#include "toolchain/sem_ir/ids.h"
|
|
#include "toolchain/sem_ir/specific_interface.h"
|
|
|
|
namespace Carbon::Check {
|
|
|
|
// Performs lookup for an impl witness for a query involving C++ types.
|
|
// Shouldn't be called with `CoreInterface::Unknown`, because only core
|
|
// interfaces can have lookup results. Returns a witness value, or `None` if a
|
|
// synthesized C++ witness should not be used.
|
|
//
|
|
// Given a known `core_interface`, we can synthesize a witness based on C++
|
|
// operator overloads or special member functions. Performs the suitable C++
|
|
// lookup to determine if this interface should be considered implemented for
|
|
// the specified type, and if so, synthesizes and returns a suitable witness.
|
|
//
|
|
// `best_impl_type_structure` provides the type structure of the best-matching
|
|
// impl declaration. If this is better than every viable C++ candidate, a "none"
|
|
// result will be returned. If this is worse than the best viable C++ candidate
|
|
// according to C++ rules, a witness for the C++ candidate will be returned.
|
|
// Otherwise, it is at least as good as the best viable C++ candidate, but there
|
|
// is some C++ candidate that has a better type structure, in which case the
|
|
// result is ambiguous and we diagnose an error. This parameter can be null if
|
|
// there is no usable impl for this query.
|
|
//
|
|
// `best_impl_loc_id` gives the location of the impl corresponding to the best
|
|
// type structure, and can be `None` if `best_impl_type_structure` is null. This
|
|
// parameter is used only for ambiguity diagnostics.
|
|
auto LookupCppImpl(Context& context, SemIR::LocId loc_id,
|
|
CoreInterface core_interface,
|
|
SemIR::ConstantId query_self_const_id,
|
|
SemIR::SpecificInterfaceId query_specific_interface_id,
|
|
const TypeStructure* best_impl_type_structure,
|
|
SemIR::LocId best_impl_loc_id) -> SemIR::InstId;
|
|
|
|
} // namespace Carbon::Check
|
|
|
|
#endif // CARBON_TOOLCHAIN_CHECK_CPP_IMPL_LOOKUP_H_
|