Repository: carbon-language/carbon-lang
File: toolchain/check/import_ref.cpp (C++)

Code before:
      local_facet_type_info->self_impls_named_constraints.push_back(
          GetLocalSpecificNamedConstraint(resolver, constraint, data));
    }
  }

  if (local_facet_type_info) {
    local_facet_type_info->rewrite_constraints.reserve(
        import_facet_type_info.rewrite_constraints.size());
  }
  for (auto rewrite : import_facet_type_info.rewrite_constraints) {
    auto lhs_id = GetLocalConstantInstId(resolver, rewrite.lhs_id);
    auto rhs_id = GetLocalConstantInstId(resolver, rewrite.rhs_id);
    if (local_facet_type_info) {
      local_facet_type_info->rewrite_constraints.push_back(
          {.lhs_id = lhs_id, .rhs_id = rhs_id});
    }
  }
}

static auto TryResolveTypedInst(ImportRefResolver& resolver,
                                SemIR::FacetType inst) -> ResolveResult {
  CARBON_CHECK(inst.type_id == SemIR::TypeType::TypeId);

  const SemIR::FacetTypeInfo& import_facet_type_info =
      resolver.import_facet_types().Get(inst.facet_type_id);
  // Ensure values are present, but discard them to avoid allocations.
  BuildFacetTypeInfo(resolver, import_facet_type_info,
                     /*local_facet_type_info=*/nullptr);
  if (resolver.HasNewWork()) {
    return ResolveResult::Retry();
  }

  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-fetch and values to the local `FacetTypeInfo`.
  BuildFacetTypeInfo(resolver, import_facet_type_info, &local_facet_type_info);

  SemIR::FacetTypeId facet_type_id =
      resolver.local_facet_types().Add(std::move(local_facet_type_info));
  return ResolveResult::Deduplicated<SemIR::FacetType>(
      resolver,
      {.type_id = SemIR::TypeType::TypeId, .facet_type_id = facet_type_id});
}

static auto TryResolveTypedInst(ImportRefResolver& resolver,
                                SemIR::FacetValue inst) -> ResolveResult {
  auto type_id = GetLocalConstantId(resolver, inst.type_id);
  auto type_inst_id = GetLocalTypeInstId(resolver, inst.type_inst_id);
  auto witnesses = GetLocalInstBlockContents(resolver, inst.witnesses_block_id);

Review comment (suggestion):
```suggestion
  // Ensure values are imported, but discard them to avoid allocations.
```

Code after:
      local_facet_type_info->self_impls_named_constraints.push_back(
          GetLocalSpecificNamedConstraint(resolver, constraint, data));
    }
  }

  if (local_facet_type_info) {
    local_facet_type_info->rewrite_constraints.reserve(
        import_facet_type_info.rewrite_constraints.size());
  }
  for (auto rewrite : import_facet_type_info.rewrite_constraints) {
    auto lhs_id = GetLocalConstantInstId(resolver, rewrite.lhs_id);
    auto rhs_id = GetLocalConstantInstId(resolver, rewrite.rhs_id);
    if (local_facet_type_info) {
      local_facet_type_info->rewrite_constraints.push_back(
          {.lhs_id = lhs_id, .rhs_id = rhs_id});
    }
  }
}

static auto TryResolveTypedInst(ImportRefResolver& resolver,
                                SemIR::FacetType inst) -> ResolveResult {
  CARBON_CHECK(inst.type_id == SemIR::TypeType::TypeId);

  const SemIR::FacetTypeInfo& import_facet_type_info =
      resolver.import_facet_types().Get(inst.facet_type_id);
  // Ensure values are imported, but discard them to avoid allocations.
  ResolveFacetTypeInfo(resolver, import_facet_type_info,
                       /*local_facet_type_info=*/nullptr);
  if (resolver.HasNewWork()) {
    return ResolveResult::Retry();
  }

  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`.
  ResolveFacetTypeInfo(resolver, import_facet_type_info,
                       &local_facet_type_info);

  SemIR::FacetTypeId facet_type_id =
      resolver.local_facet_types().Add(std::move(local_facet_type_info));
  return ResolveResult::Deduplicated<SemIR::FacetType>(
      resolver,
      {.type_id = SemIR::TypeType::TypeId, .facet_type_id = facet_type_id});
}

static auto TryResolveTypedInst(ImportRefResolver& resolver,
                                SemIR::FacetValue inst) -> ResolveResult {
  auto type_id = GetLocalConstantId(resolver, inst.type_id);
  auto type_inst_id = GetLocalTypeInstId(resolver, inst.type_inst_id);