Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track the type as written in BaseDecl and AdaptDecl. #4564

Merged
merged 13 commits into from
Nov 27, 2024
19 changes: 8 additions & 11 deletions toolchain/check/handle_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,7 @@ auto HandleParseNode(Context& context, Parse::BaseDeclId node_id) -> bool {
class_info.base_id = context.AddInst<SemIR::BaseDecl>(
node_id, {.type_id = field_type_id,
.base_type_inst_id = base_info.inst_id,
.index = SemIR::ElementIndex(
context.struct_type_fields_stack().PeekArray().size())});
.index = SemIR::ElementIndex::Invalid});

if (base_info.type_id != SemIR::TypeId::Error) {
auto base_class_info = context.classes().Get(
Expand Down Expand Up @@ -622,6 +621,7 @@ static auto CheckCompleteAdapterClassType(Context& context,
{.type_id = context.GetBuiltinType(SemIR::BuiltinInstKind::WitnessType),
.object_repr_id = object_repr_id});
}

static auto AddStructTypeFields(
Context& context,
llvm::SmallVector<SemIR::StructTypeField>& struct_type_fields)
Expand Down Expand Up @@ -657,10 +657,10 @@ static auto CheckCompleteClassType(Context& context, Parse::NodeId node_id,
return CheckCompleteAdapterClassType(context, node_id, class_id);
}

bool defining_vtable_ptr = class_info.is_dynamic;
if (auto base_type_id =
class_info.GetBaseType(context.sem_ir(), SemIR::SpecificId::Invalid);
base_type_id.is_valid()) {
bool defining_vptr = class_info.is_dynamic;
auto base_type_id =
class_info.GetBaseType(context.sem_ir(), SemIR::SpecificId::Invalid);
if (base_type_id.is_valid()) {
// TODO: If the base class is template dependent, we will need to decide
// whether to add a vptr as part of instantiation.
if (auto* base_class_info = TryGetAsClass(context, base_type_id);
Expand All @@ -679,16 +679,13 @@ static auto CheckCompleteClassType(Context& context, Parse::NodeId node_id,
.type_id = context.GetPointerType(
context.GetBuiltinType(SemIR::BuiltinInstKind::VtableType))});
}
if (class_info.base_id.is_valid()) {
if (base_type_id.is_valid()) {
auto base_decl = context.insts().GetAs<SemIR::BaseDecl>(class_info.base_id);
base_decl.index =
SemIR::ElementIndex{static_cast<int>(struct_type_fields.size())};
context.ReplaceInstPreservingConstantValue(class_info.base_id, base_decl);
struct_type_fields.push_back(
{.name_id = SemIR::NameId::Base,
.type_id = context.insts()
.GetAs<SemIR::BaseDecl>(class_info.base_id)
.base_type_id});
{.name_id = SemIR::NameId::Base, .type_id = base_type_id});
}

return context.AddInst<SemIR::CompleteTypeWitness>(
Expand Down
Loading