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:
@@ -729,11 +729,8 @@ auto CheckRequireDeclsSatisfied(Context& context, SemIR::LocId loc_id,
|
||||
// requires LookupImplWitness to return a partial result, or take a
|
||||
// diagnostic lambda or something.
|
||||
if (!result.has_value()) {
|
||||
auto facet_type_inst_id =
|
||||
context.constant_values().GetInstId(facet_type_const_id);
|
||||
|
||||
if (!result.has_error_value() &&
|
||||
facet_type_inst_id != SemIR::ErrorInst::InstId) {
|
||||
facet_type_const_id != SemIR::ErrorInst::ConstantId) {
|
||||
CARBON_DIAGNOSTIC(RequireImplsNotImplemented, Error,
|
||||
"interface `{0}` being implemented requires that {1} "
|
||||
"implements {2}",
|
||||
@@ -742,8 +739,8 @@ auto CheckRequireDeclsSatisfied(Context& context, SemIR::LocId loc_id,
|
||||
context.emitter().Emit(
|
||||
loc_id, RequireImplsNotImplemented, impl.interface,
|
||||
context.types().GetTypeIdForTypeConstantId(self_const_id),
|
||||
context.insts()
|
||||
.GetAs<SemIR::FacetType>(facet_type_inst_id)
|
||||
context.constant_values()
|
||||
.GetInstAs<SemIR::FacetType>(facet_type_const_id)
|
||||
.facet_type_id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user