mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Provide an InstId when evaluating a constant in cases where one is needed (#5202)
For each kind of instruction, specify whether its constant evaluation needs an `InstId` or not. If it does, ensure that all constant evaluation of that instruction provides one. Otherwise, allow calling into the evaluator without providing an `InstId`. This allows us to reliably use the `InstId` in evaluation steps that either need a location or need to look at the original operands of the instruction prior to evaluation, and also to support `TryEvalInst` calls safely for instructions whose evaluation does not need an `InstId`.
This commit is contained in:
@@ -91,11 +91,10 @@ static auto GetSelfFacet(Context& context,
|
||||
auto type_inst_id = context.types().GetInstId(self_type_id);
|
||||
auto witnesses_block_id =
|
||||
context.inst_blocks().AddCanonical({self_witness_id});
|
||||
auto self_value_const_id =
|
||||
TryEvalInst(context, SemIR::InstId::None,
|
||||
SemIR::FacetValue{.type_id = self_facet_type_id,
|
||||
.type_inst_id = type_inst_id,
|
||||
.witnesses_block_id = witnesses_block_id});
|
||||
auto self_value_const_id = TryEvalInst(
|
||||
context, SemIR::FacetValue{.type_id = self_facet_type_id,
|
||||
.type_inst_id = type_inst_id,
|
||||
.witnesses_block_id = witnesses_block_id});
|
||||
return context.constant_values().GetInstId(self_value_const_id);
|
||||
}
|
||||
|
||||
@@ -164,8 +163,8 @@ auto GetSelfSpecificForInterfaceMemberWithSelfType(
|
||||
CARBON_CHECK(entity_name.bind_index_value >= 0);
|
||||
bind_name.entity_name_id =
|
||||
context.entity_names().AddCanonical(entity_name);
|
||||
new_arg_id = context.constant_values().GetInstId(
|
||||
TryEvalInst(context, arg_id, bind_name));
|
||||
new_arg_id =
|
||||
context.constant_values().GetInstId(TryEvalInst(context, bind_name));
|
||||
}
|
||||
arg_ids.push_back(new_arg_id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user