mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Introduce typed-inst accessors for ConstantValueStore (#6980)
Add `InstIs`, `GetInstAs`, and `TryGetInstAs` which act on the underlying constant instruction in a constant value, to save an explicit call to `GetInstId`. ```carbon context.insts().GetAs<InstT>(context.constant_values().GetInstId(const_id)) ``` can now be written as simply ```carbon context.constant_values().GetInstAs<InstT>(const_id) ``` For future work, we might provide `GetInst()` so that `context.insts().Get(context.constant_values().GetInstId(const_id)` can be shortened also.
This commit is contained in:
@@ -103,8 +103,9 @@ auto SetBlockArgResultBeforeConstantUse(Context& context,
|
||||
auto cond_const_id = context.constant_values().Get(cond_id);
|
||||
if (!cond_const_id.is_concrete()) {
|
||||
// Symbolic or non-constant condition means a non-constant result.
|
||||
} else if (auto literal = context.insts().TryGetAs<SemIR::BoolLiteral>(
|
||||
context.constant_values().GetInstId(cond_const_id))) {
|
||||
} else if (auto literal =
|
||||
context.constant_values().TryGetInstAs<SemIR::BoolLiteral>(
|
||||
cond_const_id)) {
|
||||
const_id = context.constant_values().Get(
|
||||
literal.value().value.ToBool() ? if_true : if_false);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user