Refactor AddInst-family functions to their own file (#4941)

This in particular uses free functions because it's likely to end up
more consistent with types (versus a wrapper object for InstStore).
Note, this is unlikely to have a performance impact, but if it does, we
can look into related approaches (and we've already discussed using
LTO).

Renames `PendingBlock::AddInst` to `PendingBlock::Add` because
`MakeElementAccessInst` expects the matching name to exist.
This commit is contained in:
Jon Ross-Perkins
2025-02-14 19:44:36 +00:00
committed by GitHub
parent dd7c64bad0
commit 311b4ff03d
44 changed files with 875 additions and 695 deletions
+7 -5
View File
@@ -6,6 +6,7 @@
#include "toolchain/check/context.h"
#include "toolchain/check/convert.h"
#include "toolchain/check/inst.h"
namespace Carbon::Check {
@@ -126,7 +127,7 @@ auto BuildReturnWithNoExpr(Context& context, Parse::ReturnStatementId node_id)
diag.Emit();
}
context.AddInst<SemIR::Return>(node_id, {});
AddInst<SemIR::Return>(context, node_id, {});
}
auto BuildReturnWithExpr(Context& context, Parse::ReturnStatementId node_id,
@@ -167,8 +168,8 @@ auto BuildReturnWithExpr(Context& context, Parse::ReturnStatementId node_id,
ConvertToValueOfType(context, node_id, expr_id, return_info.type_id);
}
context.AddInst<SemIR::ReturnExpr>(
node_id, {.expr_id = expr_id, .dest_id = return_slot_id});
AddInst<SemIR::ReturnExpr>(context, node_id,
{.expr_id = expr_id, .dest_id = return_slot_id});
}
auto BuildReturnVar(Context& context, Parse::ReturnStatementId node_id)
@@ -192,8 +193,9 @@ auto BuildReturnVar(Context& context, Parse::ReturnStatementId node_id)
return_slot_id = SemIR::InstId::None;
}
context.AddInst<SemIR::ReturnExpr>(
node_id, {.expr_id = returned_var_id, .dest_id = return_slot_id});
AddInst<SemIR::ReturnExpr>(
context, node_id,
{.expr_id = returned_var_id, .dest_id = return_slot_id});
}
} // namespace Carbon::Check