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

Code before:
    auto info = GetNestedInfo(adapted_type_id);
    info.abstract_class_id = abstract_class_id;
    return info;
  }
  // Otherwise, the value representation for a class is a pointer to the
  // object representation.
  // TODO: Support customized value representations for classes.
  // TODO: Pick a better value representation when possible.
  return {.value_repr = MakePointerValueRepr(
              class_info.GetObjectRepr(context_->sem_ir(), inst.specific_id),
              SemIR::ValueRepr::ObjectAggregate),
          .abstract_class_id = abstract_class_id};
}

auto TypeCompleter::BuildInfoForInst(SemIR::TypeId /*type_id*/,
                                     SemIR::ConstType inst) const
    -> SemIR::CompleteTypeInfo {
  // The value representation of `const T` is the same as that of `T`.
  // Objects are not modifiable through their value representations.
  return GetNestedInfo(context_->types().GetTypeIdForTypeInstId(inst.inner_id));
}

auto TypeCompleter::BuildInfoForInst(SemIR::TypeId /*type_id*/,
                                     SemIR::PartialType inst) const
    -> SemIR::CompleteTypeInfo {
  // The value representation of `const T` is the same as that of `T`.
  // Objects are not modifiable through their value representations.
  return GetNestedInfo(context_->types().GetTypeIdForTypeInstId(inst.inner_id));
}

auto TypeCompleter::BuildInfoForInst(
    SemIR::TypeId /*type_id*/, SemIR::ImplWitnessAssociatedConstant inst) const
    -> SemIR::CompleteTypeInfo {
  return GetNestedInfo(inst.type_id);
}

// Builds and returns the value representation for the given type. All nested
// types, as found by AddNestedIncompleteTypes, are known to be complete.
auto TypeCompleter::BuildInfo(SemIR::TypeId type_id, SemIR::Inst inst) const
    -> SemIR::CompleteTypeInfo {
  // Use overload resolution to select the implementation, producing compile
  // errors when BuildInfoForInst isn't defined for a given instruction.
  CARBON_KIND_SWITCH(inst) {
#define CARBON_SEM_IR_INST_KIND(Name)             \
  case CARBON_KIND(SemIR::Name typed_inst): {     \
    return BuildInfoForInst(type_id, typed_inst); \
  }
#include "toolchain/sem_ir/inst_kind.def"
  }
}


Review comment (suggestion):
```suggestion
  // The value representation of `partial T` is the same as that of `T`.
```

Code after:
    auto info = GetNestedInfo(adapted_type_id);
    info.abstract_class_id = abstract_class_id;
    return info;
  }
  // Otherwise, the value representation for a class is a pointer to the
  // object representation.
  // TODO: Support customized value representations for classes.
  // TODO: Pick a better value representation when possible.
  return {.value_repr = MakePointerValueRepr(
              class_info.GetObjectRepr(context_->sem_ir(), inst.specific_id),
              SemIR::ValueRepr::ObjectAggregate),
          .abstract_class_id = abstract_class_id};
}

auto TypeCompleter::BuildInfoForInst(SemIR::TypeId /*type_id*/,
                                     SemIR::ConstType inst) const
    -> SemIR::CompleteTypeInfo {
  // The value representation of `const T` is the same as that of `T`.
  // Objects are not modifiable through their value representations.
  return GetNestedInfo(context_->types().GetTypeIdForTypeInstId(inst.inner_id));
}

auto TypeCompleter::BuildInfoForInst(SemIR::TypeId /*type_id*/,
                                     SemIR::PartialType inst) const
    -> SemIR::CompleteTypeInfo {
  // The value representation of `partial T` is the same as that of `T`.
  // Objects are not modifiable through their value representations.
  return GetNestedInfo(context_->types().GetTypeIdForTypeInstId(inst.inner_id));
}

auto TypeCompleter::BuildInfoForInst(
    SemIR::TypeId /*type_id*/, SemIR::ImplWitnessAssociatedConstant inst) const
    -> SemIR::CompleteTypeInfo {
  return GetNestedInfo(inst.type_id);
}

// Builds and returns the value representation for the given type. All nested
// types, as found by AddNestedIncompleteTypes, are known to be complete.
auto TypeCompleter::BuildInfo(SemIR::TypeId type_id, SemIR::Inst inst) const
    -> SemIR::CompleteTypeInfo {
  // Use overload resolution to select the implementation, producing compile
  // errors when BuildInfoForInst isn't defined for a given instruction.
  CARBON_KIND_SWITCH(inst) {
#define CARBON_SEM_IR_INST_KIND(Name)             \
  case CARBON_KIND(SemIR::Name typed_inst): {     \
    return BuildInfoForInst(type_id, typed_inst); \
  }
#include "toolchain/sem_ir/inst_kind.def"
  }
}