diff --git a/toolchain/check/convert.cpp b/toolchain/check/convert.cpp index f1376511f227..1f1920513471 100644 --- a/toolchain/check/convert.cpp +++ b/toolchain/check/convert.cpp @@ -286,7 +286,7 @@ static auto ConvertTupleToArray(Context& context, SemIR::TupleType tuple_type, return SemIR::ErrorInst::SingletonInstId; } - PendingBlock target_block_storage(context); + PendingBlock target_block_storage(&context); PendingBlock* target_block = target.init_block ? target.init_block : &target_block_storage; @@ -604,7 +604,7 @@ static auto ConvertStructToClass(Context& context, SemIR::StructType src_type, SemIR::ClassType dest_type, SemIR::InstId value_id, ConversionTarget target) -> SemIR::InstId { - PendingBlock target_block(context); + PendingBlock target_block(&context); auto& dest_class_info = context.classes().Get(dest_type.class_id); CARBON_CHECK(dest_class_info.inheritance_kind != SemIR::Class::Abstract); auto object_repr_id = @@ -1396,7 +1396,7 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id, auto Initialize(Context& context, SemIR::LocId loc_id, SemIR::InstId target_id, SemIR::InstId value_id) -> SemIR::InstId { - PendingBlock target_block(context); + PendingBlock target_block(&context); return Convert(context, loc_id, value_id, {.kind = ConversionTarget::Initializer, .type_id = context.insts().Get(target_id).type_id(), diff --git a/toolchain/check/pending_block.h b/toolchain/check/pending_block.h index e665b728bb98..4ba7313fb192 100644 --- a/toolchain/check/pending_block.h +++ b/toolchain/check/pending_block.h @@ -17,7 +17,8 @@ namespace Carbon::Check { // that haven't been inserted yet. class PendingBlock { public: - explicit PendingBlock(Context& context) : context_(context) {} + // `context` must not be null. + explicit PendingBlock(Context* context) : context_(context) {} PendingBlock(const PendingBlock&) = delete; auto operator=(const PendingBlock&) -> PendingBlock& = delete; @@ -44,14 +45,14 @@ class PendingBlock { template auto AddInst(LocT loc_id, InstT inst) -> SemIR::InstId { - auto inst_id = AddInstInNoBlock(context_, loc_id, inst); + auto inst_id = AddInstInNoBlock(*context_, loc_id, inst); insts_.push_back(inst_id); return inst_id; } template auto AddInstWithCleanup(LocT loc_id, InstT inst) -> SemIR::InstId { - auto inst_id = AddInstWithCleanupInNoBlock(context_, loc_id, inst); + auto inst_id = AddInstWithCleanupInNoBlock(*context_, loc_id, inst); insts_.push_back(inst_id); return inst_id; } @@ -59,7 +60,7 @@ class PendingBlock { // Insert the pending block of code at the current position. auto InsertHere() -> void { for (auto id : insts_) { - context_.inst_block_stack().AddInstId(id); + context_->inst_block_stack().AddInstId(id); } insts_.clear(); } @@ -67,7 +68,7 @@ class PendingBlock { // Replace the instruction at target_id with the instructions in this block. // The new value for target_id should be value_id. auto MergeReplacing(SemIR::InstId target_id, SemIR::InstId value_id) -> void { - SemIR::LocIdAndInst value = context_.insts().GetWithLocId(value_id); + SemIR::LocIdAndInst value = context_->insts().GetWithLocId(value_id); if (insts_.size() == 1 && insts_[0] == value_id) { // The block is {value_id}. Replace `target_id` with the instruction @@ -77,18 +78,18 @@ class PendingBlock { // includes empty blocks, which `Add` handles. value.inst = SemIR::SpliceBlock{.type_id = value.inst.type_id(), - .block_id = context_.inst_blocks().Add(insts_), + .block_id = context_->inst_blocks().Add(insts_), .result_id = value_id}; } - ReplaceLocIdAndInstBeforeConstantUse(context_, target_id, value); + ReplaceLocIdAndInstBeforeConstantUse(*context_, target_id, value); // Prepare to stash more pending instructions. insts_.clear(); } private: - Context& context_; + Context* context_; llvm::SmallVector insts_; };