mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 08:44:41 +01:00
Change Destroy to use a CustomWitness instead of a blanket impl (#6512)
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.
This commit is contained in:
@@ -2070,6 +2070,36 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
|
||||
return HandleUnsupportedCppOverloadSet(resolver, inst.overload_set_id);
|
||||
}
|
||||
|
||||
static auto TryResolveTypedInst(ImportRefResolver& resolver,
|
||||
SemIR::CustomWitness inst) -> ResolveResult {
|
||||
CARBON_CHECK(resolver.import_types().GetInstId(inst.type_id) ==
|
||||
SemIR::WitnessType::TypeInstId);
|
||||
|
||||
auto elements = GetLocalInstBlockContents(resolver, inst.elements_id);
|
||||
const auto& import_specific_interface =
|
||||
resolver.import_specific_interfaces().Get(
|
||||
inst.query_specific_interface_id);
|
||||
auto data =
|
||||
GetLocalSpecificInterfaceData(resolver, import_specific_interface);
|
||||
|
||||
if (resolver.HasNewWork()) {
|
||||
return ResolveResult::Retry();
|
||||
}
|
||||
|
||||
auto elements_id =
|
||||
GetLocalCanonicalInstBlockId(resolver, inst.elements_id, elements);
|
||||
auto specific_interface =
|
||||
GetLocalSpecificInterface(resolver, import_specific_interface, data);
|
||||
auto query_specific_interface_id =
|
||||
resolver.local_specific_interfaces().Add(specific_interface);
|
||||
|
||||
return ResolveResult::Deduplicated<SemIR::CustomWitness>(
|
||||
resolver, {.type_id = GetSingletonType(resolver.local_context(),
|
||||
SemIR::WitnessType::TypeInstId),
|
||||
.elements_id = elements_id,
|
||||
.query_specific_interface_id = query_specific_interface_id});
|
||||
}
|
||||
|
||||
static auto TryResolveTypedInst(ImportRefResolver& resolver,
|
||||
SemIR::ExportDecl inst) -> ResolveResult {
|
||||
auto value_id = GetLocalConstantId(resolver, inst.value_id);
|
||||
@@ -3082,7 +3112,6 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
|
||||
}
|
||||
|
||||
SemIR::FacetTypeInfo local_facet_type_info = {
|
||||
.builtin_constraint_mask = import_facet_type_info.builtin_constraint_mask,
|
||||
// TODO: Also process the other requirements.
|
||||
.other_requirements = import_facet_type_info.other_requirements};
|
||||
// Re-resolve and add values to the local `FacetTypeInfo`.
|
||||
@@ -3721,6 +3750,9 @@ static auto TryResolveInstCanonical(ImportRefResolver& resolver,
|
||||
case CARBON_KIND(SemIR::CppOverloadSetValue inst): {
|
||||
return TryResolveTypedInst(resolver, inst);
|
||||
}
|
||||
case CARBON_KIND(SemIR::CustomWitness inst): {
|
||||
return TryResolveTypedInst(resolver, inst);
|
||||
}
|
||||
case CARBON_KIND(SemIR::ExportDecl inst): {
|
||||
return TryResolveTypedInst(resolver, inst);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user