mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 20:20:10 +01:00
Store pointer not reference in ConstantStore (#4398)
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
This commit is contained in:
@@ -10,7 +10,7 @@ namespace Carbon::SemIR {
|
||||
|
||||
auto ConstantStore::GetOrAdd(Inst inst, bool is_symbolic) -> ConstantId {
|
||||
auto result = map_.Insert(inst, [&] {
|
||||
auto inst_id = sem_ir_.insts().AddInNoBlock(LocIdAndInst::NoLoc(inst));
|
||||
auto inst_id = sem_ir_->insts().AddInNoBlock(LocIdAndInst::NoLoc(inst));
|
||||
ConstantId const_id = ConstantId::Invalid;
|
||||
if (is_symbolic) {
|
||||
// The instruction in the constants store is an abstract symbolic
|
||||
@@ -20,11 +20,11 @@ auto ConstantStore::GetOrAdd(Inst inst, bool is_symbolic) -> ConstantId {
|
||||
.generic_id = GenericId::Invalid,
|
||||
.index = GenericInstIndex::Invalid};
|
||||
const_id =
|
||||
sem_ir_.constant_values().AddSymbolicConstant(symbolic_constant);
|
||||
sem_ir_->constant_values().AddSymbolicConstant(symbolic_constant);
|
||||
} else {
|
||||
const_id = SemIR::ConstantId::ForTemplateConstant(inst_id);
|
||||
}
|
||||
sem_ir_.constant_values().Set(inst_id, const_id);
|
||||
sem_ir_->constant_values().Set(inst_id, const_id);
|
||||
constants_.push_back(inst_id);
|
||||
return const_id;
|
||||
});
|
||||
|
||||
@@ -143,7 +143,7 @@ class ConstantValueStore {
|
||||
// Provides storage for instructions representing deduplicated global constants.
|
||||
class ConstantStore {
|
||||
public:
|
||||
explicit ConstantStore(File& sem_ir) : sem_ir_(sem_ir) {}
|
||||
explicit ConstantStore(File* sem_ir) : sem_ir_(sem_ir) {}
|
||||
|
||||
// Adds a new constant instruction, or gets the existing constant with this
|
||||
// value. Returns the ID of the constant.
|
||||
@@ -166,7 +166,7 @@ class ConstantStore {
|
||||
auto size() const -> int { return constants_.size(); }
|
||||
|
||||
private:
|
||||
File& sem_ir_;
|
||||
File* const sem_ir_;
|
||||
Map<Inst, ConstantId> map_;
|
||||
llvm::SmallVector<InstId, 0> constants_;
|
||||
};
|
||||
|
||||
@@ -32,7 +32,7 @@ File::File(CheckIRId check_ir_id, IdentifierId package_id,
|
||||
name_scopes_(&insts_),
|
||||
constant_values_(ConstantId::NotConstant),
|
||||
inst_blocks_(allocator_),
|
||||
constants_(*this) {
|
||||
constants_(this) {
|
||||
// `type` and the error type are both complete types.
|
||||
types_.SetValueRepr(TypeId::TypeType,
|
||||
{.kind = ValueRepr::Copy, .type_id = TypeId::TypeType});
|
||||
|
||||
Reference in New Issue
Block a user