Skip to content

Commit 57c9a2e

Browse files
authored
Switch eval of ArrayIndex to use CARBON_KIND (#4462)
Just a minor cleanup.
1 parent f70221c commit 57c9a2e

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

toolchain/check/eval.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,10 @@ static auto PerformAggregateAccess(EvalContext& eval_context, SemIR::Inst inst)
481481

482482
// Performs an index into a homogeneous aggregate, retrieving the specified
483483
// element.
484-
static auto PerformArrayIndex(EvalContext& eval_context, SemIR::Inst inst)
484+
static auto PerformArrayIndex(EvalContext& eval_context, SemIR::ArrayIndex inst)
485485
-> SemIR::ConstantId {
486-
auto index_inst = inst.As<SemIR::ArrayIndex>();
487486
Phase phase = Phase::Template;
488-
auto index_id = GetConstantValue(eval_context, index_inst.index_id, &phase);
487+
auto index_id = GetConstantValue(eval_context, inst.index_id, &phase);
489488

490489
if (!index_id.is_valid()) {
491490
return MakeNonConstantResult(phase);
@@ -501,7 +500,7 @@ static auto PerformArrayIndex(EvalContext& eval_context, SemIR::Inst inst)
501500
// regardless of whether the array itself is constant.
502501
const auto& index_val = eval_context.ints().Get(index->int_id);
503502
auto aggregate_type_id = eval_context.GetConstantValueAsType(
504-
eval_context.insts().Get(index_inst.array_id).type_id());
503+
eval_context.insts().Get(inst.array_id).type_id());
505504
if (auto array_type =
506505
eval_context.types().TryGetAs<SemIR::ArrayType>(aggregate_type_id)) {
507506
if (auto bound = eval_context.insts().TryGetAs<SemIR::IntLiteral>(
@@ -516,15 +515,14 @@ static auto PerformArrayIndex(EvalContext& eval_context, SemIR::Inst inst)
516515
"array index `{0}` is past the end of type {1}",
517516
TypedInt, SemIR::TypeId);
518517
eval_context.emitter().Emit(
519-
index_inst.index_id, ArrayIndexOutOfBounds,
518+
inst.index_id, ArrayIndexOutOfBounds,
520519
{.type = index->type_id, .value = index_val}, aggregate_type_id);
521520
return SemIR::ConstantId::Error;
522521
}
523522
}
524523
}
525524

526-
auto aggregate_id =
527-
GetConstantValue(eval_context, index_inst.array_id, &phase);
525+
auto aggregate_id = GetConstantValue(eval_context, inst.array_id, &phase);
528526
if (!aggregate_id.is_valid()) {
529527
return MakeNonConstantResult(phase);
530528
}
@@ -1348,8 +1346,10 @@ static auto TryEvalInstInContext(EvalContext& eval_context,
13481346
case SemIR::StructAccess::Kind:
13491347
case SemIR::TupleAccess::Kind:
13501348
return PerformAggregateAccess(eval_context, inst);
1351-
case SemIR::ArrayIndex::Kind:
1352-
return PerformArrayIndex(eval_context, inst);
1349+
1350+
case CARBON_KIND(SemIR::ArrayIndex index): {
1351+
return PerformArrayIndex(eval_context, index);
1352+
}
13531353

13541354
case CARBON_KIND(SemIR::Call call): {
13551355
return MakeConstantForCall(eval_context, inst_id, call);

0 commit comments

Comments
 (0)