From 14396552be75d0fcb9c9e43d4e256076f2467b85 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Tue, 12 Nov 2024 20:55:54 +0000 Subject: [PATCH] WIP --- MODULE.bazel.lock | 4 ++-- common/array_stack.h | 7 +++++++ toolchain/check/handle_class.cpp | 9 +++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index aa644d8bf9053..9d4b7f434bada 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -130,7 +130,7 @@ "//bazel/cc_toolchains:clang_configuration.bzl%clang_toolchain_extension": { "general": { "bzlTransitiveDigest": "YfAlFgFWuxAcofKFZTG3JR3DeQD3yED9F1mzTVz6xoA=", - "usagesDigest": "FiqDwj5QoiCFb1PRYvajLeyuRjRXbsy2CVC+VsEEt7Q=", + "usagesDigest": "gfR4YaqF67HjpCEGrL0eyE8UHB6u6nYKukxqkDtpUnA=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, "envVariables": {}, @@ -147,7 +147,7 @@ "//bazel/llvm_project:llvm_project.bzl%llvm_project": { "general": { "bzlTransitiveDigest": "QG2kkxgw5yvNHGJYbsdwlidT0uFXu5uZMW6KftuXDsI=", - "usagesDigest": "0qlzYSob/rZ/yVQnGrAnMBlAhKszo5qDlauf4tO9tgY=", + "usagesDigest": "xAFaBH1/4TOjTzJ1M7AQoJOUT6PulRTi3jh5H7fQmno=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, "envVariables": {}, diff --git a/common/array_stack.h b/common/array_stack.h index 9021c8a4bdb53..1e6cab296d042 100644 --- a/common/array_stack.h +++ b/common/array_stack.h @@ -47,6 +47,13 @@ class ArrayStack { return llvm::ArrayRef(values_).slice(array_offsets_.back()); } + // Returns the top array from the stack in such a way that the array's + // contents can be modified by the caller. + auto PeekMutableArray() -> llvm::MutableArrayRef { + CARBON_CHECK(!array_offsets_.empty()); + return llvm::MutableArrayRef(values_).slice(array_offsets_.back()); + } + // Returns the array at a specific index. auto PeekArrayAt(int index) const -> llvm::ArrayRef { auto ref = llvm::ArrayRef(values_).slice(array_offsets_[index]); diff --git a/toolchain/check/handle_class.cpp b/toolchain/check/handle_class.cpp index f0ef56f0f9a5e..a0dba32a2b009 100644 --- a/toolchain/check/handle_class.cpp +++ b/toolchain/check/handle_class.cpp @@ -296,6 +296,8 @@ auto HandleParseNode(Context& context, Parse::ClassDefinitionStartId node_id) context.inst_block_stack().Push(); context.node_stack().Push(node_id, class_id); context.struct_type_fields_stack().PushArray(); + context.struct_type_fields_stack().AppendToTop( + {.name_id = SemIR::NameId::Vptr, .type_id = context.GetTupleType({})}); // TODO: Handle the case where there's control flow in the class body. For // example: @@ -668,10 +670,9 @@ static auto CheckCompleteClassType(Context& context, Parse::NodeId node_id, } if (defining_vtable_ptr) { - context.struct_type_fields_stack().PrependToTop( - {.name_id = SemIR::NameId::Vptr, - .type_id = context.GetPointerType( - context.GetBuiltinType(SemIR::BuiltinInstKind::VtableType))}); + context.struct_type_fields_stack().PeekMutableArray().front().type_id = + context.GetPointerType( + context.GetBuiltinType(SemIR::BuiltinInstKind::VtableType)); } auto fields_id = context.struct_type_fields().AddCanonical(