mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 18:21:16 +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:
@@ -617,10 +617,7 @@ static auto GetConstantFacetTypeInfo(EvalContext& eval_context,
|
||||
SemIR::LocId loc_id,
|
||||
const SemIR::FacetTypeInfo& orig,
|
||||
Phase* phase) -> SemIR::FacetTypeInfo {
|
||||
SemIR::FacetTypeInfo info = {
|
||||
.builtin_constraint_mask = orig.builtin_constraint_mask,
|
||||
// TODO: Process other requirements.
|
||||
.other_requirements = orig.other_requirements};
|
||||
SemIR::FacetTypeInfo info = {};
|
||||
|
||||
info.extend_constraints.reserve(orig.extend_constraints.size());
|
||||
for (const auto& extend : orig.extend_constraints) {
|
||||
@@ -681,6 +678,9 @@ static auto GetConstantFacetTypeInfo(EvalContext& eval_context,
|
||||
rewrite = {.lhs_id = lhs_id, .rhs_id = rhs_id};
|
||||
}
|
||||
|
||||
// TODO: Process other requirements.
|
||||
info.other_requirements = orig.other_requirements;
|
||||
|
||||
info.Canonicalize();
|
||||
return info;
|
||||
}
|
||||
@@ -1688,8 +1688,7 @@ static auto MakeConstantForBuiltinCall(EvalContext& eval_context,
|
||||
case SemIR::BuiltinFunctionKind::None:
|
||||
CARBON_FATAL("Not a builtin function.");
|
||||
|
||||
case SemIR::BuiltinFunctionKind::NoOp:
|
||||
case SemIR::BuiltinFunctionKind::TypeDestroy: {
|
||||
case SemIR::BuiltinFunctionKind::NoOp: {
|
||||
// Return an empty tuple value.
|
||||
auto type_id = GetTupleType(eval_context.context(), {});
|
||||
return MakeConstantResult(
|
||||
@@ -1699,18 +1698,6 @@ static auto MakeConstantForBuiltinCall(EvalContext& eval_context,
|
||||
phase);
|
||||
}
|
||||
|
||||
case SemIR::BuiltinFunctionKind::TypeCanDestroy: {
|
||||
CARBON_CHECK(arg_ids.empty());
|
||||
auto id = eval_context.facet_types().Add(
|
||||
{.builtin_constraint_mask =
|
||||
SemIR::BuiltinConstraintMask::TypeCanDestroy});
|
||||
return MakeConstantResult(
|
||||
eval_context.context(),
|
||||
SemIR::FacetType{.type_id = SemIR::TypeType::TypeId,
|
||||
.facet_type_id = id},
|
||||
phase);
|
||||
}
|
||||
|
||||
case SemIR::BuiltinFunctionKind::PrimitiveCopy: {
|
||||
return context.constant_values().Get(arg_ids[0]);
|
||||
}
|
||||
@@ -2356,7 +2343,6 @@ auto TryEvalTypedInst<SemIR::WhereExpr>(EvalContext& eval_context,
|
||||
info.extend_constraints.append(base_info.extend_constraints);
|
||||
info.self_impls_constraints.append(base_info.self_impls_constraints);
|
||||
info.rewrite_constraints.append(base_info.rewrite_constraints);
|
||||
info.builtin_constraint_mask.Add(base_info.builtin_constraint_mask);
|
||||
info.other_requirements |= base_info.other_requirements;
|
||||
}
|
||||
} else if (auto rewrite =
|
||||
@@ -2395,7 +2381,6 @@ auto TryEvalTypedInst<SemIR::WhereExpr>(EvalContext& eval_context,
|
||||
// Other requirements are copied in.
|
||||
llvm::append_range(info.rewrite_constraints,
|
||||
more_info.rewrite_constraints);
|
||||
info.builtin_constraint_mask.Add(more_info.builtin_constraint_mask);
|
||||
info.other_requirements |= more_info.other_requirements;
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user