eval_inst.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "toolchain/check/eval_inst.h"
  5. #include <variant>
  6. #include "toolchain/check/action.h"
  7. #include "toolchain/check/facet_type.h"
  8. #include "toolchain/check/generic.h"
  9. #include "toolchain/check/impl_lookup.h"
  10. #include "toolchain/check/import_ref.h"
  11. #include "toolchain/check/inst.h"
  12. #include "toolchain/check/type.h"
  13. #include "toolchain/check/type_completion.h"
  14. #include "toolchain/diagnostics/diagnostic.h"
  15. #include "toolchain/sem_ir/ids.h"
  16. #include "toolchain/sem_ir/typed_insts.h"
  17. namespace Carbon::Check {
  18. // Performs an access into an aggregate, retrieving the specified element.
  19. static auto PerformAggregateAccess(Context& context, SemIR::Inst inst)
  20. -> ConstantEvalResult {
  21. auto access_inst = inst.As<SemIR::AnyAggregateAccess>();
  22. if (auto aggregate = context.insts().TryGetAs<SemIR::AnyAggregateValue>(
  23. access_inst.aggregate_id)) {
  24. auto elements = context.inst_blocks().Get(aggregate->elements_id);
  25. auto index = static_cast<size_t>(access_inst.index.index);
  26. CARBON_CHECK(index < elements.size(), "Access out of bounds.");
  27. // `Phase` is not used here. If this element is a concrete constant, then
  28. // so is the result of indexing, even if the aggregate also contains a
  29. // symbolic context.
  30. return ConstantEvalResult::Existing(
  31. context.constant_values().Get(elements[index]));
  32. }
  33. return ConstantEvalResult::NewSamePhase(inst);
  34. }
  35. auto EvalConstantInst(Context& /*context*/, SemIR::ArrayInit inst)
  36. -> ConstantEvalResult {
  37. // TODO: Add an `ArrayValue` to represent a constant array object
  38. // representation instead of using a `TupleValue`.
  39. return ConstantEvalResult::NewSamePhase(
  40. SemIR::TupleValue{.type_id = inst.type_id, .elements_id = inst.inits_id});
  41. }
  42. auto EvalConstantInst(Context& context, SemIR::InstId inst_id,
  43. SemIR::ArrayType inst) -> ConstantEvalResult {
  44. auto bound_inst = context.insts().Get(inst.bound_id);
  45. auto int_bound = bound_inst.TryAs<SemIR::IntValue>();
  46. if (!int_bound) {
  47. CARBON_CHECK(context.constant_values().Get(inst.bound_id).is_symbolic(),
  48. "Unexpected inst {0} for template constant int", bound_inst);
  49. return ConstantEvalResult::NewSamePhase(inst);
  50. }
  51. // TODO: We should check that the size of the resulting array type
  52. // fits in 64 bits, not just that the bound does. Should we use a
  53. // 32-bit limit for 32-bit targets?
  54. const auto& bound_val = context.ints().Get(int_bound->int_id);
  55. if (context.types().IsSignedInt(int_bound->type_id) &&
  56. bound_val.isNegative()) {
  57. CARBON_DIAGNOSTIC(ArrayBoundNegative, Error,
  58. "array bound of {0} is negative", TypedInt);
  59. context.emitter().Emit(
  60. context.insts().GetAs<SemIR::ArrayType>(inst_id).bound_id,
  61. ArrayBoundNegative, {.type = int_bound->type_id, .value = bound_val});
  62. return ConstantEvalResult::Error;
  63. }
  64. if (bound_val.getActiveBits() > 64) {
  65. CARBON_DIAGNOSTIC(ArrayBoundTooLarge, Error,
  66. "array bound of {0} is too large", TypedInt);
  67. context.emitter().Emit(
  68. context.insts().GetAs<SemIR::ArrayType>(inst_id).bound_id,
  69. ArrayBoundTooLarge, {.type = int_bound->type_id, .value = bound_val});
  70. return ConstantEvalResult::Error;
  71. }
  72. return ConstantEvalResult::NewSamePhase(inst);
  73. }
  74. auto EvalConstantInst(Context& context, SemIR::AsCompatible inst)
  75. -> ConstantEvalResult {
  76. // AsCompatible changes the type of the source instruction; its constant
  77. // value, if there is one, needs to be modified to be of the same type.
  78. auto value_id = context.constant_values().Get(inst.source_id);
  79. CARBON_CHECK(value_id.is_constant());
  80. auto value_inst =
  81. context.insts().Get(context.constant_values().GetInstId(value_id));
  82. value_inst.SetType(inst.type_id);
  83. return ConstantEvalResult::NewAnyPhase(value_inst);
  84. }
  85. auto EvalConstantInst(Context& context, SemIR::BindAlias inst)
  86. -> ConstantEvalResult {
  87. // An alias evaluates to the value it's bound to.
  88. return ConstantEvalResult::Existing(
  89. context.constant_values().Get(inst.value_id));
  90. }
  91. auto EvalConstantInst(Context& /*context*/, SemIR::BindValue /*inst*/)
  92. -> ConstantEvalResult {
  93. // TODO: Handle this once we've decided how to represent constant values of
  94. // reference expressions.
  95. return ConstantEvalResult::TODO;
  96. }
  97. auto EvalConstantInst(Context& context, SemIR::ClassElementAccess inst)
  98. -> ConstantEvalResult {
  99. return PerformAggregateAccess(context, inst);
  100. }
  101. auto EvalConstantInst(Context& context, SemIR::ClassDecl inst)
  102. -> ConstantEvalResult {
  103. // If the class has generic parameters, we don't produce a class type, but a
  104. // callable whose return value is a class type.
  105. if (context.classes().Get(inst.class_id).has_parameters()) {
  106. return ConstantEvalResult::NewSamePhase(SemIR::StructValue{
  107. .type_id = inst.type_id, .elements_id = SemIR::InstBlockId::Empty});
  108. }
  109. // A non-generic class declaration evaluates to the class type.
  110. return ConstantEvalResult::NewSamePhase(
  111. SemIR::ClassType{.type_id = SemIR::TypeType::SingletonTypeId,
  112. .class_id = inst.class_id,
  113. .specific_id = SemIR::SpecificId::None});
  114. }
  115. auto EvalConstantInst(Context& /*context*/, SemIR::ClassInit inst)
  116. -> ConstantEvalResult {
  117. // TODO: Add a `ClassValue` to represent a constant class object
  118. // representation instead of using a `StructValue`.
  119. return ConstantEvalResult::NewSamePhase(SemIR::StructValue{
  120. .type_id = inst.type_id, .elements_id = inst.elements_id});
  121. }
  122. auto EvalConstantInst(Context& context, SemIR::ConstType inst)
  123. -> ConstantEvalResult {
  124. // `const (const T)` evaluates to `const T`.
  125. if (context.insts().Is<SemIR::ConstType>(inst.inner_id)) {
  126. return ConstantEvalResult::Existing(
  127. context.constant_values().Get(inst.inner_id));
  128. }
  129. // Otherwise, `const T` evaluates to itself.
  130. return ConstantEvalResult::NewSamePhase(inst);
  131. }
  132. auto EvalConstantInst(Context& context, SemIR::Converted inst)
  133. -> ConstantEvalResult {
  134. // A conversion evaluates to the result of the conversion.
  135. return ConstantEvalResult::Existing(
  136. context.constant_values().Get(inst.result_id));
  137. }
  138. auto EvalConstantInst(Context& /*context*/, SemIR::Deref /*inst*/)
  139. -> ConstantEvalResult {
  140. // TODO: Handle this.
  141. return ConstantEvalResult::TODO;
  142. }
  143. auto EvalConstantInst(Context& context, SemIR::ExportDecl inst)
  144. -> ConstantEvalResult {
  145. // An export instruction evaluates to the exported declaration.
  146. return ConstantEvalResult::Existing(
  147. context.constant_values().Get(inst.value_id));
  148. }
  149. auto EvalConstantInst(Context& context, SemIR::FacetAccessType inst)
  150. -> ConstantEvalResult {
  151. if (auto facet_value = context.insts().TryGetAs<SemIR::FacetValue>(
  152. inst.facet_value_inst_id)) {
  153. return ConstantEvalResult::Existing(
  154. context.constant_values().Get(facet_value->type_inst_id));
  155. }
  156. return ConstantEvalResult::NewSamePhase(inst);
  157. }
  158. auto EvalConstantInst(Context& context, SemIR::FacetAccessWitness inst)
  159. -> ConstantEvalResult {
  160. // TODO: The `index` we are given is an index into the required_interfaces of
  161. // the original facet type, but we're using it to index into the witnesses of
  162. // the substituted facet type. There is no reason to expect those witnesses to
  163. // be in the same order, or even for there to be the same number of witnesses.
  164. if (auto facet_value = context.insts().TryGetAs<SemIR::FacetValue>(
  165. inst.facet_value_inst_id)) {
  166. auto impl_witness_inst_id = context.inst_blocks().Get(
  167. facet_value->witnesses_block_id)[inst.index.index];
  168. return ConstantEvalResult::Existing(
  169. context.constant_values().Get(impl_witness_inst_id));
  170. }
  171. return ConstantEvalResult::NewSamePhase(inst);
  172. }
  173. auto EvalConstantInst(Context& context, SemIR::InstId inst_id,
  174. SemIR::FloatType inst) -> ConstantEvalResult {
  175. return ValidateFloatType(context, inst_id, inst)
  176. ? ConstantEvalResult::NewSamePhase(inst)
  177. : ConstantEvalResult::Error;
  178. }
  179. auto EvalConstantInst(Context& /*context*/, SemIR::FunctionDecl inst)
  180. -> ConstantEvalResult {
  181. // A function declaration evaluates to a function object, which is an empty
  182. // object of function type.
  183. // TODO: Eventually we may need to handle captures here.
  184. return ConstantEvalResult::NewSamePhase(SemIR::StructValue{
  185. .type_id = inst.type_id, .elements_id = SemIR::InstBlockId::Empty});
  186. }
  187. auto EvalConstantInst(Context& context, SemIR::InstId inst_id,
  188. SemIR::LookupImplWitness inst) -> ConstantEvalResult {
  189. auto result = EvalLookupSingleImplWitness(
  190. context, context.insts().GetLocId(inst_id), inst);
  191. if (!result.has_value()) {
  192. // We use NotConstant to communicate back to impl lookup that the lookup
  193. // failed. This can not happen for a deferred symbolic lookup in a generic
  194. // eval block, since we only add the deferred lookup instruction (being
  195. // evaluated here) to the SemIR if the lookup succeeds.
  196. return ConstantEvalResult::NotConstant;
  197. }
  198. if (!result.has_concrete_value()) {
  199. return ConstantEvalResult::NewSamePhase(inst);
  200. }
  201. return ConstantEvalResult::Existing(
  202. context.constant_values().Get(result.concrete_witness()));
  203. }
  204. auto EvalConstantInst(Context& context, SemIR::InstId inst_id,
  205. SemIR::ImplWitnessAccess inst) -> ConstantEvalResult {
  206. // This is PerformAggregateAccess followed by GetConstantValueInSpecific.
  207. if (auto witness =
  208. context.insts().TryGetAs<SemIR::ImplWitness>(inst.witness_id)) {
  209. auto elements = context.inst_blocks().Get(witness->elements_id);
  210. // `elements` can be empty if there is only a forward declaration of the
  211. // impl.
  212. if (!elements.empty()) {
  213. auto index = static_cast<size_t>(inst.index.index);
  214. CARBON_CHECK(index < elements.size(), "Access out of bounds.");
  215. auto element = elements[index];
  216. if (element.has_value()) {
  217. LoadImportRef(context, element);
  218. return ConstantEvalResult::Existing(GetConstantValueInSpecific(
  219. context.sem_ir(), witness->specific_id, element));
  220. }
  221. }
  222. CARBON_DIAGNOSTIC(
  223. ImplAccessMemberBeforeSet, Error,
  224. "accessing member from impl before it has a defined value");
  225. // TODO: Add note pointing to the impl declaration.
  226. context.emitter().Emit(inst_id, ImplAccessMemberBeforeSet);
  227. return ConstantEvalResult::Error;
  228. }
  229. return ConstantEvalResult::NewSamePhase(inst);
  230. }
  231. auto EvalConstantInst(Context& context,
  232. SemIR::ImplWitnessAssociatedConstant inst)
  233. -> ConstantEvalResult {
  234. return ConstantEvalResult::Existing(
  235. context.constant_values().Get(inst.inst_id));
  236. }
  237. auto EvalConstantInst(Context& /*context*/, SemIR::ImportRefUnloaded inst)
  238. -> ConstantEvalResult {
  239. CARBON_FATAL("ImportRefUnloaded should be loaded before TryEvalInst: {0}",
  240. inst);
  241. }
  242. auto EvalConstantInst(Context& context, SemIR::InitializeFrom inst)
  243. -> ConstantEvalResult {
  244. // Initialization is not performed in-place during constant evaluation, so
  245. // just return the value of the initializer.
  246. return ConstantEvalResult::Existing(
  247. context.constant_values().Get(inst.src_id));
  248. }
  249. auto EvalConstantInst(Context& context, SemIR::InstId inst_id,
  250. SemIR::IntType inst) -> ConstantEvalResult {
  251. return ValidateIntType(context, inst_id, inst)
  252. ? ConstantEvalResult::NewSamePhase(inst)
  253. : ConstantEvalResult::Error;
  254. }
  255. auto EvalConstantInst(Context& context, SemIR::InterfaceDecl inst)
  256. -> ConstantEvalResult {
  257. // If the interface has generic parameters, we don't produce an interface
  258. // type, but a callable whose return value is an interface type.
  259. if (context.interfaces().Get(inst.interface_id).has_parameters()) {
  260. return ConstantEvalResult::NewSamePhase(SemIR::StructValue{
  261. .type_id = inst.type_id, .elements_id = SemIR::InstBlockId::Empty});
  262. }
  263. // A non-generic interface declaration evaluates to a facet type.
  264. return ConstantEvalResult::NewSamePhase(FacetTypeFromInterface(
  265. context, inst.interface_id, SemIR::SpecificId::None));
  266. }
  267. auto EvalConstantInst(Context& context, SemIR::NameRef inst)
  268. -> ConstantEvalResult {
  269. // A name reference evaluates to the value the name resolves to.
  270. return ConstantEvalResult::Existing(
  271. context.constant_values().Get(inst.value_id));
  272. }
  273. auto EvalConstantInst(Context& context, SemIR::InstId inst_id,
  274. SemIR::RequireCompleteType inst) -> ConstantEvalResult {
  275. auto witness_type_id =
  276. GetSingletonType(context, SemIR::WitnessType::SingletonInstId);
  277. // If the type is a concrete constant, require it to be complete now.
  278. auto complete_type_id = inst.complete_type_id;
  279. if (context.types().GetConstantId(complete_type_id).is_concrete()) {
  280. if (!TryToCompleteType(context, complete_type_id, inst_id, [&] {
  281. CARBON_DIAGNOSTIC(IncompleteTypeInMonomorphization, Error,
  282. "{0} evaluates to incomplete type {1}",
  283. SemIR::TypeId, SemIR::TypeId);
  284. return context.emitter().Build(
  285. inst_id, IncompleteTypeInMonomorphization,
  286. context.insts()
  287. .GetAs<SemIR::RequireCompleteType>(inst_id)
  288. .complete_type_id,
  289. complete_type_id);
  290. })) {
  291. return ConstantEvalResult::Error;
  292. }
  293. return ConstantEvalResult::NewSamePhase(SemIR::CompleteTypeWitness{
  294. .type_id = witness_type_id,
  295. .object_repr_id = context.types().GetObjectRepr(complete_type_id)});
  296. }
  297. // If it's not a concrete constant, require it to be complete once it
  298. // becomes one.
  299. return ConstantEvalResult::NewSamePhase(inst);
  300. }
  301. auto EvalConstantInst(Context& context, SemIR::SpecificConstant inst)
  302. -> ConstantEvalResult {
  303. // Pull the constant value out of the specific.
  304. return ConstantEvalResult::Existing(SemIR::GetConstantValueInSpecific(
  305. context.sem_ir(), inst.specific_id, inst.inst_id));
  306. }
  307. auto EvalConstantInst(Context& context, SemIR::InstId inst_id,
  308. SemIR::SpecificImplFunction inst) -> ConstantEvalResult {
  309. auto callee_inst = context.insts().Get(inst.callee_id);
  310. // If the callee is not a function value, we're not ready to evaluate this
  311. // yet. Build a symbolic `SpecificImplFunction` constant.
  312. if (!callee_inst.Is<SemIR::StructValue>()) {
  313. return ConstantEvalResult::NewSamePhase(inst);
  314. }
  315. auto callee_type_id = callee_inst.type_id();
  316. auto callee_fn_type =
  317. context.types().TryGetAs<SemIR::FunctionType>(callee_type_id);
  318. if (!callee_fn_type) {
  319. return ConstantEvalResult::NewSamePhase(inst);
  320. }
  321. // If the callee function found in the impl witness is not generic, the result
  322. // is simply that function.
  323. // TODO: We could do this even before the callee is concrete.
  324. auto generic_id =
  325. context.functions().Get(callee_fn_type->function_id).generic_id;
  326. if (!generic_id.has_value()) {
  327. return ConstantEvalResult::Existing(
  328. context.constant_values().Get(inst.callee_id));
  329. }
  330. // Find the arguments to use.
  331. auto enclosing_specific_id = callee_fn_type->specific_id;
  332. auto enclosing_args = context.inst_blocks().Get(
  333. context.specifics().GetArgsOrEmpty(enclosing_specific_id));
  334. auto interface_fn_args = context.inst_blocks().Get(
  335. context.specifics().GetArgsOrEmpty(inst.specific_id));
  336. // Form new specific for the generic callee function. The arguments for this
  337. // specific are the enclosing arguments of the callee followed by the
  338. // remaining arguments from the interface function. Impl checking has ensured
  339. // that these arguments can also be used for the function in the impl witness.
  340. auto num_params = context.inst_blocks()
  341. .Get(context.generics().Get(generic_id).bindings_id)
  342. .size();
  343. llvm::SmallVector<SemIR::InstId> args;
  344. args.reserve(num_params);
  345. args.append(enclosing_args.begin(), enclosing_args.end());
  346. int remaining_params = num_params - args.size();
  347. CARBON_CHECK(static_cast<int>(interface_fn_args.size()) >= remaining_params);
  348. args.append(interface_fn_args.end() - remaining_params,
  349. interface_fn_args.end());
  350. auto specific_id = MakeSpecific(context, inst_id, generic_id, args);
  351. context.definitions_required_by_use().push_back({inst_id, specific_id});
  352. return ConstantEvalResult::NewSamePhase(
  353. SemIR::SpecificFunction{.type_id = inst.type_id,
  354. .callee_id = inst.callee_id,
  355. .specific_id = specific_id});
  356. }
  357. auto EvalConstantInst(Context& context, SemIR::InstId inst_id,
  358. SemIR::SpecificFunction inst) -> ConstantEvalResult {
  359. if (!SemIR::GetCalleeFunction(context.sem_ir(), inst.callee_id)
  360. .self_type_id.has_value()) {
  361. // This is not an associated function. Those will be required to be defined
  362. // as part of checking that the impl is complete.
  363. context.definitions_required_by_use().push_back(
  364. {inst_id, inst.specific_id});
  365. }
  366. // Create new constant for a specific function.
  367. return ConstantEvalResult::NewSamePhase(inst);
  368. }
  369. auto EvalConstantInst(Context& context, SemIR::SpliceBlock inst)
  370. -> ConstantEvalResult {
  371. // SpliceBlock evaluates to the result value that is (typically) within the
  372. // block. This can be constant even if the block contains other non-constant
  373. // instructions.
  374. return ConstantEvalResult::Existing(
  375. context.constant_values().Get(inst.result_id));
  376. }
  377. auto EvalConstantInst(Context& context, SemIR::SpliceInst inst)
  378. -> ConstantEvalResult {
  379. // The constant value of a SpliceInst is the constant value of the instruction
  380. // being spliced. Note that `inst.inst_id` is the instruction being spliced,
  381. // so we need to go through another round of obtaining the constant value in
  382. // addition to the one performed by the eval infrastructure.
  383. if (auto inst_value =
  384. context.insts().TryGetAs<SemIR::InstValue>(inst.inst_id)) {
  385. return ConstantEvalResult::Existing(
  386. context.constant_values().Get(inst_value->inst_id));
  387. }
  388. // TODO: Consider creating a new `ValueOfInst` instruction analogous to
  389. // `TypeOfInst` to defer determining the constant value until we know the
  390. // instruction. Alternatively, produce a symbolic `SpliceInst` constant.
  391. return ConstantEvalResult::NotConstant;
  392. }
  393. auto EvalConstantInst(Context& context, SemIR::StructAccess inst)
  394. -> ConstantEvalResult {
  395. return PerformAggregateAccess(context, inst);
  396. }
  397. auto EvalConstantInst(Context& /*context*/, SemIR::StructInit inst)
  398. -> ConstantEvalResult {
  399. return ConstantEvalResult::NewSamePhase(SemIR::StructValue{
  400. .type_id = inst.type_id, .elements_id = inst.elements_id});
  401. }
  402. auto EvalConstantInst(Context& /*context*/, SemIR::Temporary /*inst*/)
  403. -> ConstantEvalResult {
  404. // TODO: Handle this. Can we just return the value of `init_id`?
  405. return ConstantEvalResult::TODO;
  406. }
  407. auto EvalConstantInst(Context& context, SemIR::TupleAccess inst)
  408. -> ConstantEvalResult {
  409. return PerformAggregateAccess(context, inst);
  410. }
  411. auto EvalConstantInst(Context& /*context*/, SemIR::TupleInit inst)
  412. -> ConstantEvalResult {
  413. return ConstantEvalResult::NewSamePhase(SemIR::TupleValue{
  414. .type_id = inst.type_id, .elements_id = inst.elements_id});
  415. }
  416. auto EvalConstantInst(Context& context, SemIR::TypeOfInst inst)
  417. -> ConstantEvalResult {
  418. // Grab the type from the instruction produced as our operand.
  419. if (auto inst_value =
  420. context.insts().TryGetAs<SemIR::InstValue>(inst.inst_id)) {
  421. return ConstantEvalResult::Existing(context.types().GetConstantId(
  422. context.insts().Get(inst_value->inst_id).type_id()));
  423. }
  424. return ConstantEvalResult::NewSamePhase(inst);
  425. }
  426. auto EvalConstantInst(Context& context, SemIR::UnaryOperatorNot inst)
  427. -> ConstantEvalResult {
  428. // `not true` -> `false`, `not false` -> `true`.
  429. // All other uses of unary `not` are non-constant.
  430. auto const_id = context.constant_values().Get(inst.operand_id);
  431. if (const_id.is_concrete()) {
  432. auto value = context.insts().GetAs<SemIR::BoolLiteral>(
  433. context.constant_values().GetInstId(const_id));
  434. value.value = SemIR::BoolValue::From(!value.value.ToBool());
  435. return ConstantEvalResult::NewSamePhase(value);
  436. }
  437. return ConstantEvalResult::NotConstant;
  438. }
  439. auto EvalConstantInst(Context& context, SemIR::ValueOfInitializer inst)
  440. -> ConstantEvalResult {
  441. // Values of value expressions and initializing expressions are represented in
  442. // the same way during constant evaluation, so just return the value of the
  443. // operand.
  444. return ConstantEvalResult::Existing(
  445. context.constant_values().Get(inst.init_id));
  446. }
  447. auto EvalConstantInst(Context& context, SemIR::ValueParamPattern inst)
  448. -> ConstantEvalResult {
  449. // TODO: Treat this as a non-expression (here and in GetExprCategory)
  450. // once generic deduction doesn't need patterns to have constant values.
  451. return ConstantEvalResult::Existing(
  452. context.constant_values().Get(inst.subpattern_id));
  453. }
  454. } // namespace Carbon::Check