mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 18:21:16 +01:00
Implement ...where .Self impls... (#5238)
* Also remove facet type deduction, since we decided against it on [2025-04-02](https://docs.google.com/document/d/1Iut5f2TQBrtBNIduF4vJYOKfw7MbS8xH_J01_Q4e6Rk/edit?pli=1&resourcekey=0-mc_vh5UzrzXfU4kO-3tOjA&tab=t.0#heading=h.95phmuvxog9n). --------- Co-authored-by: Josh L <josh11b@users.noreply.github.com> Co-authored-by: Dana Jansens <danakj@orodu.net>
This commit is contained in:
co-authored by
Josh L
Dana Jansens
parent
87f0e9723f
commit
4af0c8f8d1
@@ -991,7 +991,7 @@ static auto GetLocalSpecificInterface(
|
||||
if (auto facet_type = interface_const_inst.TryAs<SemIR::FacetType>()) {
|
||||
const SemIR::FacetTypeInfo& new_facet_type_info =
|
||||
context.local_facet_types().Get(facet_type->facet_type_id);
|
||||
return new_facet_type_info.impls_constraints.front();
|
||||
return *new_facet_type_info.TryAsSingleInterface();
|
||||
} else {
|
||||
auto generic_interface_type =
|
||||
context.local_types().GetAs<SemIR::GenericInterfaceType>(
|
||||
@@ -2450,14 +2450,19 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
|
||||
SemIR::FacetType inst) -> ResolveResult {
|
||||
CARBON_CHECK(inst.type_id == SemIR::TypeType::SingletonTypeId);
|
||||
|
||||
const SemIR::FacetTypeInfo& facet_type_info =
|
||||
const SemIR::FacetTypeInfo& import_facet_type_info =
|
||||
resolver.import_facet_types().Get(inst.facet_type_id);
|
||||
for (auto interface : facet_type_info.impls_constraints) {
|
||||
for (auto interface : import_facet_type_info.extend_constraints) {
|
||||
// We discard this here and recompute it below instead of saving it to avoid
|
||||
// allocations.
|
||||
GetLocalSpecificInterfaceData(resolver, interface);
|
||||
}
|
||||
for (auto rewrite : facet_type_info.rewrite_constraints) {
|
||||
for (auto interface : import_facet_type_info.self_impls_constraints) {
|
||||
// We discard this here and recompute it below instead of saving it to avoid
|
||||
// allocations.
|
||||
GetLocalSpecificInterfaceData(resolver, interface);
|
||||
}
|
||||
for (auto rewrite : import_facet_type_info.rewrite_constraints) {
|
||||
GetLocalConstantId(resolver, rewrite.lhs_const_id);
|
||||
GetLocalConstantId(resolver, rewrite.rhs_const_id);
|
||||
}
|
||||
@@ -2465,25 +2470,32 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
|
||||
return ResolveResult::Retry();
|
||||
}
|
||||
|
||||
llvm::SmallVector<SemIR::FacetTypeInfo::ImplsConstraint> impls_constraints;
|
||||
for (auto interface : facet_type_info.impls_constraints) {
|
||||
SemIR::FacetTypeInfo local_facet_type_info = {
|
||||
.other_requirements = import_facet_type_info.other_requirements};
|
||||
local_facet_type_info.extend_constraints.reserve(
|
||||
import_facet_type_info.extend_constraints.size());
|
||||
for (auto interface : import_facet_type_info.extend_constraints) {
|
||||
auto data = GetLocalSpecificInterfaceData(resolver, interface);
|
||||
impls_constraints.push_back(
|
||||
local_facet_type_info.extend_constraints.push_back(
|
||||
GetLocalSpecificInterface(resolver, interface, data));
|
||||
}
|
||||
llvm::SmallVector<SemIR::FacetTypeInfo::RewriteConstraint>
|
||||
rewrite_constraints;
|
||||
for (auto rewrite : facet_type_info.rewrite_constraints) {
|
||||
rewrite_constraints.push_back(
|
||||
local_facet_type_info.self_impls_constraints.reserve(
|
||||
import_facet_type_info.self_impls_constraints.size());
|
||||
for (auto interface : import_facet_type_info.self_impls_constraints) {
|
||||
auto data = GetLocalSpecificInterfaceData(resolver, interface);
|
||||
local_facet_type_info.self_impls_constraints.push_back(
|
||||
GetLocalSpecificInterface(resolver, interface, data));
|
||||
}
|
||||
local_facet_type_info.rewrite_constraints.reserve(
|
||||
import_facet_type_info.rewrite_constraints.size());
|
||||
for (auto rewrite : import_facet_type_info.rewrite_constraints) {
|
||||
local_facet_type_info.rewrite_constraints.push_back(
|
||||
{.lhs_const_id = GetLocalConstantId(resolver, rewrite.lhs_const_id),
|
||||
.rhs_const_id = GetLocalConstantId(resolver, rewrite.rhs_const_id)});
|
||||
}
|
||||
// TODO: Also process the other requirements.
|
||||
SemIR::FacetTypeId facet_type_id =
|
||||
resolver.local_facet_types().Add(SemIR::FacetTypeInfo{
|
||||
.impls_constraints = impls_constraints,
|
||||
.rewrite_constraints = rewrite_constraints,
|
||||
.other_requirements = facet_type_info.other_requirements});
|
||||
resolver.local_facet_types().Add(std::move(local_facet_type_info));
|
||||
return ResolveAs<SemIR::FacetType>(
|
||||
resolver, {.type_id = SemIR::TypeType::SingletonTypeId,
|
||||
.facet_type_id = facet_type_id});
|
||||
|
||||
Reference in New Issue
Block a user