Files
carbon-lang/toolchain/sem_ir/field.h
T
Nicholas Bishop 682f9fef16 Add FieldStore and fix field initializer imports (#7287)
As suggested in [1], replace `FieldInitializerMap` with a `FieldStore`.
The corresponding `FieldId` is now stored in `FieldDecl`. To make room
for the `FieldId`, the `ElementIndex` is now stored in the `Field`,
along with the initializer.

In import_ref.cpp, resolving `FieldDecl` initializers is now supported,
and in convert.cpp `LoadImportRef` is called to do so. The
`field_initializer_import.carbon` test now passes.

Printing a `FieldDecl` instruction now prints the initializer as well,
if present. See field_initializer.carbon for an example.

[1]:
https://github.com/carbon-language/carbon-lang/pull/7238#discussion_r3283217158
2026-06-01 19:02:01 +00:00

33 lines
936 B
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CARBON_TOOLCHAIN_SEM_IR_FIELD_H_
#define CARBON_TOOLCHAIN_SEM_IR_FIELD_H_
#include "toolchain/base/value_store.h"
#include "toolchain/sem_ir/ids.h"
namespace Carbon::SemIR {
// A class field.
struct Field : public Printable<Field> {
ElementIndex index;
SemIR::InstId initializer_id;
auto Print(llvm::raw_ostream& out) const -> void {
out << "{index: " << index << ", initializer_id: " << initializer_id << "}";
}
};
using FieldStore = ValueStore<FieldId, Field, Tag<CheckIRId>>;
} // namespace Carbon::SemIR
namespace Carbon {
extern template class ValueStore<SemIR::FieldId, SemIR::Field,
Tag<SemIR::CheckIRId>>;
} // namespace Carbon
#endif // CARBON_TOOLCHAIN_SEM_IR_FIELD_H_