mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 18:51:11 +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:
@@ -26,8 +26,8 @@ namespace Carbon::Check {
|
||||
static auto TypeAsClassDecl(Context& context,
|
||||
SemIR::ConstantId query_self_const_id)
|
||||
-> clang::CXXRecordDecl* {
|
||||
auto self_inst_id = context.constant_values().GetInstId(query_self_const_id);
|
||||
auto class_type = context.insts().TryGetAs<SemIR::ClassType>(self_inst_id);
|
||||
auto class_type = context.constant_values().TryGetInstAs<SemIR::ClassType>(
|
||||
query_self_const_id);
|
||||
if (!class_type) {
|
||||
// Not a class.
|
||||
return nullptr;
|
||||
|
||||
Reference in New Issue
Block a user