mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 19:51:09 +01:00
Add CoreInterface for consistent tracking of CoreIdentifier interfaces (#6516)
We're going to want to track `Destroy` and some other interfaces in ways similar to what the C++ logic wants. Rather than having both do their own comparisons with similar values, this tries to centralize logic. Note the prior `context.identifiers().Get(interface.name_id.AsIdentifierId())` is also obsolete due to #6486, this is just replacing it in a single swoop and avoiding string comparisons as a consequence.
This commit is contained in:
@@ -114,29 +114,21 @@ static auto LookupDestroyImpl(Context& context, SemIR::LocId loc_id,
|
||||
}
|
||||
|
||||
auto LookupCppImpl(Context& context, SemIR::LocId loc_id,
|
||||
SemIR::TypeId self_type_id,
|
||||
SemIR::TypeId self_type_id, CoreInterface core_interface,
|
||||
SemIR::SpecificInterface specific_interface,
|
||||
const TypeStructure* best_impl_type_structure,
|
||||
SemIR::LocId best_impl_loc_id) -> SemIR::InstId {
|
||||
// Determine whether this is an interface that we have special knowledge of.
|
||||
auto& interface = context.interfaces().Get(specific_interface.interface_id);
|
||||
if (!context.name_scopes().IsCorePackage(interface.parent_scope_id)) {
|
||||
return SemIR::InstId::None;
|
||||
}
|
||||
if (!interface.name_id.AsIdentifierId().has_value()) {
|
||||
return SemIR::InstId::None;
|
||||
}
|
||||
|
||||
if (context.identifiers().Get(interface.name_id.AsIdentifierId()) == "Copy") {
|
||||
return LookupCopyImpl(context, loc_id, self_type_id, specific_interface);
|
||||
}
|
||||
|
||||
if (context.identifiers().Get(interface.name_id.AsIdentifierId()) ==
|
||||
"Destroy") {
|
||||
return LookupDestroyImpl(context, loc_id, self_type_id, specific_interface);
|
||||
}
|
||||
|
||||
// TODO: Handle other interfaces.
|
||||
switch (core_interface) {
|
||||
case CoreInterface::Copy:
|
||||
return LookupCopyImpl(context, loc_id, self_type_id, specific_interface);
|
||||
case CoreInterface::Destroy:
|
||||
return LookupDestroyImpl(context, loc_id, self_type_id,
|
||||
specific_interface);
|
||||
|
||||
case CoreInterface::Unknown:
|
||||
CARBON_FATAL("shouldn't be called with `Unknown`");
|
||||
}
|
||||
|
||||
// TODO: Infer a C++ type structure and check whether it's less strict than
|
||||
// the best Carbon type structure.
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#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/type_structure.h"
|
||||
#include "toolchain/sem_ir/ids.h"
|
||||
@@ -16,8 +17,8 @@ namespace Carbon::Check {
|
||||
// Performs lookup for an impl witness for a query involving C++ types. Returns
|
||||
// a witness value, or `None` if a synthesized C++ witness should not be used.
|
||||
//
|
||||
// If `interface` is an interface for which we can synthesize a witness based on
|
||||
// C++ operator overloads or special member functions, performs the suitable C++
|
||||
// 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.
|
||||
//
|
||||
@@ -34,7 +35,7 @@ namespace Carbon::Check {
|
||||
// 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,
|
||||
SemIR::TypeId self_type_id,
|
||||
SemIR::TypeId self_type_id, CoreInterface core_interface,
|
||||
SemIR::SpecificInterface specific_interface,
|
||||
const TypeStructure* best_impl_type_structure,
|
||||
SemIR::LocId best_impl_loc_id) -> SemIR::InstId;
|
||||
|
||||
Reference in New Issue
Block a user