generic.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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/generic.h"
  5. #include "common/map.h"
  6. #include "toolchain/base/kind_switch.h"
  7. #include "toolchain/check/eval.h"
  8. #include "toolchain/check/generic_region_stack.h"
  9. #include "toolchain/check/subst.h"
  10. #include "toolchain/check/type.h"
  11. #include "toolchain/check/type_completion.h"
  12. #include "toolchain/sem_ir/constant.h"
  13. #include "toolchain/sem_ir/generic.h"
  14. #include "toolchain/sem_ir/ids.h"
  15. #include "toolchain/sem_ir/inst.h"
  16. #include "toolchain/sem_ir/typed_insts.h"
  17. namespace Carbon::Check {
  18. static auto MakeSelfSpecificId(Context& context, SemIR::GenericId generic_id)
  19. -> SemIR::SpecificId;
  20. auto StartGenericDecl(Context& context) -> void {
  21. context.generic_region_stack().Push();
  22. }
  23. auto StartGenericDefinition(Context& context) -> void {
  24. // Push a generic region even if we don't have a generic_id. We might still
  25. // have locally-introduced generic parameters to track:
  26. //
  27. // fn F() {
  28. // let T:! type = i32;
  29. // var x: T;
  30. // }
  31. context.generic_region_stack().Push();
  32. }
  33. // Adds an instruction `generic_inst_id` to the eval block for a generic region,
  34. // which is the current instruction block. The instruction `generic_inst_id` is
  35. // expected to compute the value of the constant described by `const_inst_id` in
  36. // each specific. Forms and returns a corresponding symbolic constant ID that
  37. // refers to the substituted value of that instruction in each specific.
  38. static auto AddGenericConstantInstToEvalBlock(
  39. Context& context, SemIR::GenericId generic_id,
  40. SemIR::GenericInstIndex::Region region, SemIR::InstId const_inst_id,
  41. SemIR::InstId generic_inst_id, SemIR::ConstantDependence dependence)
  42. -> SemIR::ConstantId {
  43. auto index = SemIR::GenericInstIndex(
  44. region, context.inst_block_stack().PeekCurrentBlockContents().size());
  45. context.inst_block_stack().AddInstId(generic_inst_id);
  46. return context.constant_values().AddSymbolicConstant(
  47. {.inst_id = const_inst_id,
  48. .generic_id = generic_id,
  49. .index = index,
  50. .dependence = dependence});
  51. }
  52. namespace {
  53. // A map from an instruction ID representing a canonical symbolic constant to an
  54. // instruction within an eval block of the generic that computes the specific
  55. // value for that constant.
  56. //
  57. // We arbitrarily use a small size of 256 bytes for the map.
  58. // TODO: Determine a better number based on measurements.
  59. using ConstantsInGenericMap = Map<SemIR::InstId, SemIR::InstId, 256>;
  60. // Substitution callbacks to rebuild a generic constant in the eval block for a
  61. // generic region.
  62. class RebuildGenericConstantInEvalBlockCallbacks final
  63. : public SubstInstCallbacks {
  64. public:
  65. RebuildGenericConstantInEvalBlockCallbacks(
  66. Context& context, SemIR::GenericId generic_id,
  67. SemIR::GenericInstIndex::Region region, SemIR::LocId loc_id,
  68. ConstantsInGenericMap& constants_in_generic)
  69. : context_(context),
  70. generic_id_(generic_id),
  71. region_(region),
  72. loc_id_(loc_id),
  73. constants_in_generic_(constants_in_generic) {}
  74. // Check for instructions for which we already have a mapping into the eval
  75. // block, and substitute them for the instructions in the eval block.
  76. auto Subst(SemIR::InstId& inst_id) const -> bool override {
  77. auto const_id = context_.constant_values().Get(inst_id);
  78. if (!const_id.has_value()) {
  79. // An unloaded import ref should never contain anything we need to
  80. // substitute into. Don't trigger loading it here.
  81. CARBON_CHECK(
  82. context_.insts().Is<SemIR::ImportRefUnloaded>(inst_id),
  83. "Substituting into instruction with invalid constant ID: {0}",
  84. context_.insts().Get(inst_id));
  85. return true;
  86. }
  87. if (!context_.constant_values().DependsOnGenericParameter(const_id)) {
  88. // This instruction doesn't have a symbolic constant value, so can't
  89. // contain any bindings that need to be substituted.
  90. return true;
  91. }
  92. // If this instruction is in the map, return the known result.
  93. if (auto result = constants_in_generic_.Lookup(
  94. context_.constant_values().GetInstId(const_id))) {
  95. // In order to reuse instructions from the generic as often as possible,
  96. // keep this instruction as-is if it already has the desired symbolic
  97. // constant value.
  98. if (const_id != context_.constant_values().Get(result.value())) {
  99. inst_id = result.value();
  100. }
  101. CARBON_CHECK(inst_id.has_value());
  102. return true;
  103. }
  104. // If the instruction is a symbolic binding, build a version in the eval
  105. // block.
  106. if (auto binding =
  107. context_.insts().TryGetAs<SemIR::BindSymbolicName>(inst_id)) {
  108. if (context_.entity_names()
  109. .Get(binding->entity_name_id)
  110. .bind_index()
  111. .has_value()) {
  112. inst_id = Rebuild(inst_id, *binding);
  113. return true;
  114. }
  115. }
  116. if (auto pattern =
  117. context_.insts().TryGetAs<SemIR::SymbolicBindingPattern>(inst_id)) {
  118. inst_id = Rebuild(inst_id, *pattern);
  119. return true;
  120. }
  121. return false;
  122. }
  123. // Build a new instruction in the eval block corresponding to the given
  124. // constant.
  125. auto Rebuild(SemIR::InstId orig_inst_id, SemIR::Inst new_inst) const
  126. -> SemIR::InstId override {
  127. auto& orig_symbolic_const = context_.constant_values().GetSymbolicConstant(
  128. context_.constant_values().Get(orig_inst_id));
  129. auto const_inst_id = orig_symbolic_const.inst_id;
  130. auto dependence = orig_symbolic_const.dependence;
  131. // We might already have an instruction in the eval block if a transitive
  132. // operand of this instruction has the same constant value.
  133. auto result = constants_in_generic_.Insert(const_inst_id, [&] {
  134. // TODO: Add a function on `Context` to add the instruction without
  135. // inserting it into the dependent instructions list or computing a
  136. // constant value for it.
  137. // TODO: Is the location we pick here always appropriate for the new
  138. // instruction?
  139. auto inst_id = context_.sem_ir().insts().AddInNoBlock(
  140. SemIR::LocIdAndInst::UncheckedLoc(loc_id_, new_inst));
  141. auto const_id = AddGenericConstantInstToEvalBlock(
  142. context_, generic_id_, region_, const_inst_id, inst_id, dependence);
  143. context_.constant_values().Set(inst_id, const_id);
  144. return inst_id;
  145. });
  146. return result.value();
  147. }
  148. private:
  149. Context& context_;
  150. SemIR::GenericId generic_id_;
  151. SemIR::GenericInstIndex::Region region_;
  152. SemIR::LocId loc_id_;
  153. ConstantsInGenericMap& constants_in_generic_;
  154. };
  155. } // namespace
  156. // Adds instructions to compute the substituted version of `type_id` in each
  157. // specific into the eval block for the generic, which is the current
  158. // instruction block. Returns a symbolic type ID that refers to the substituted
  159. // type in each specific.
  160. static auto AddGenericTypeToEvalBlock(
  161. Context& context, SemIR::GenericId generic_id,
  162. SemIR::GenericInstIndex::Region region, SemIR::LocId loc_id,
  163. ConstantsInGenericMap& constants_in_generic, SemIR::TypeId type_id)
  164. -> SemIR::TypeId {
  165. // Substitute into the type's constant instruction and rebuild it in the eval
  166. // block.
  167. auto type_inst_id =
  168. SubstInst(context, context.types().GetInstId(type_id),
  169. RebuildGenericConstantInEvalBlockCallbacks(
  170. context, generic_id, region, loc_id, constants_in_generic));
  171. return context.types().GetTypeIdForTypeInstId(type_inst_id);
  172. }
  173. // Adds instructions to compute the substituted value of `inst_id` in each
  174. // specific into the eval block for the generic, which is the current
  175. // instruction block. Returns a symbolic constant instruction ID that refers to
  176. // the substituted constant value in each specific.
  177. static auto AddGenericConstantToEvalBlock(
  178. Context& context, SemIR::GenericId generic_id,
  179. SemIR::GenericInstIndex::Region region,
  180. ConstantsInGenericMap& constants_in_generic, SemIR::InstId inst_id)
  181. -> SemIR::ConstantId {
  182. // Substitute into the constant value and rebuild it in the eval block if
  183. // we've not encountered it before.
  184. auto const_inst_id = context.constant_values().GetConstantInstId(inst_id);
  185. auto new_inst_id =
  186. SubstInst(context, const_inst_id,
  187. RebuildGenericConstantInEvalBlockCallbacks(
  188. context, generic_id, region,
  189. context.insts().GetLocId(inst_id), constants_in_generic));
  190. CARBON_CHECK(new_inst_id != const_inst_id,
  191. "Did not apply any substitutions to symbolic constant {0}",
  192. context.insts().Get(const_inst_id));
  193. return context.constant_values().Get(new_inst_id);
  194. }
  195. // Populates a map of constants in a generic from the constants in the
  196. // declaration region, in preparation for building the definition region.
  197. static auto PopulateConstantsFromDeclaration(
  198. Context& context, SemIR::GenericId generic_id,
  199. ConstantsInGenericMap& constants_in_generic) {
  200. // For the definition region, populate constants from the declaration.
  201. auto decl_eval_block = context.inst_blocks().Get(
  202. context.generics().Get(generic_id).decl_block_id);
  203. constants_in_generic.GrowForInsertCount(decl_eval_block.size());
  204. for (auto inst_id : decl_eval_block) {
  205. auto const_inst_id = context.constant_values().GetConstantInstId(inst_id);
  206. auto result = constants_in_generic.Insert(const_inst_id, inst_id);
  207. CARBON_CHECK(result.is_inserted(),
  208. "Duplicate constant in generic decl eval block: {0}",
  209. context.insts().Get(const_inst_id));
  210. }
  211. }
  212. // Builds and returns a block of instructions whose constant values need to be
  213. // evaluated in order to resolve a generic to a specific.
  214. static auto MakeGenericEvalBlock(Context& context, SemIR::GenericId generic_id,
  215. SemIR::GenericInstIndex::Region region)
  216. -> SemIR::InstBlockId {
  217. context.inst_block_stack().Push();
  218. ConstantsInGenericMap constants_in_generic;
  219. // For the definition region, populate constants from the declaration.
  220. if (region == SemIR::GenericInstIndex::Region::Definition) {
  221. PopulateConstantsFromDeclaration(context, generic_id, constants_in_generic);
  222. }
  223. // The work done in this loop might invalidate iterators into the generic
  224. // region stack, but shouldn't add new dependent instructions to the current
  225. // region.
  226. auto num_dependent_insts =
  227. context.generic_region_stack().PeekDependentInsts().size();
  228. for (auto i : llvm::seq(num_dependent_insts)) {
  229. auto [inst_id, dep_kind] =
  230. context.generic_region_stack().PeekDependentInsts()[i];
  231. // If the type is symbolic, replace it with a type specific to this generic.
  232. if ((dep_kind & GenericRegionStack::DependencyKind::SymbolicType) !=
  233. GenericRegionStack::DependencyKind::None) {
  234. auto inst = context.insts().Get(inst_id);
  235. auto type_id = AddGenericTypeToEvalBlock(
  236. context, generic_id, region, context.insts().GetLocId(inst_id),
  237. constants_in_generic, inst.type_id());
  238. // TODO: Eventually, completeness requirements should be modeled as
  239. // constraints on the generic rather than properties of the type. For now,
  240. // require the transformed type to be complete if the original was.
  241. if (context.types().IsComplete(inst.type_id())) {
  242. CompleteTypeOrCheckFail(context, type_id);
  243. }
  244. inst.SetType(type_id);
  245. context.sem_ir().insts().Set(inst_id, inst);
  246. }
  247. // If the instruction has a symbolic constant value, then make a note that
  248. // we'll need to evaluate this instruction when forming the specific. Update
  249. // the constant value of the instruction to refer to the result of that
  250. // eventual evaluation.
  251. if ((dep_kind & GenericRegionStack::DependencyKind::SymbolicConstant) !=
  252. GenericRegionStack::DependencyKind::None) {
  253. // Update the constant value to refer to this generic.
  254. context.constant_values().Set(
  255. inst_id,
  256. AddGenericConstantToEvalBlock(context, generic_id, region,
  257. constants_in_generic, inst_id));
  258. }
  259. }
  260. CARBON_CHECK(
  261. num_dependent_insts ==
  262. context.generic_region_stack().PeekDependentInsts().size(),
  263. "Building eval block added new dependent insts, for example {0}",
  264. context.insts().Get(context.generic_region_stack()
  265. .PeekDependentInsts()[num_dependent_insts]
  266. .inst_id));
  267. return context.inst_block_stack().Pop();
  268. }
  269. // Builds and returns an eval block, given the list of canonical symbolic
  270. // constants that the instructions in the eval block should produce. This is
  271. // used when importing a generic.
  272. auto RebuildGenericEvalBlock(Context& context, SemIR::GenericId generic_id,
  273. SemIR::GenericInstIndex::Region region,
  274. llvm::ArrayRef<SemIR::InstId> const_ids)
  275. -> SemIR::InstBlockId {
  276. context.inst_block_stack().Push();
  277. ConstantsInGenericMap constants_in_generic;
  278. // For the definition region, populate constants from the declaration.
  279. if (region == SemIR::GenericInstIndex::Region::Definition) {
  280. PopulateConstantsFromDeclaration(context, generic_id, constants_in_generic);
  281. }
  282. constants_in_generic.GrowForInsertCount(const_ids.size());
  283. for (auto [i, inst_id] : llvm::enumerate(const_ids)) {
  284. // Build a constant in the inst block.
  285. AddGenericConstantToEvalBlock(context, generic_id, region,
  286. constants_in_generic, inst_id);
  287. CARBON_CHECK(
  288. context.inst_block_stack().PeekCurrentBlockContents().size() == i + 1,
  289. "Produced {0} instructions when importing {1}",
  290. (context.inst_block_stack().PeekCurrentBlockContents().size() - i),
  291. context.insts().Get(inst_id));
  292. }
  293. return context.inst_block_stack().Pop();
  294. }
  295. auto DiscardGenericDecl(Context& context) -> void {
  296. context.generic_region_stack().Pop();
  297. }
  298. auto BuildGeneric(Context& context, SemIR::InstId decl_id) -> SemIR::GenericId {
  299. auto all_bindings =
  300. context.scope_stack().compile_time_bindings_stack().PeekAllValues();
  301. if (all_bindings.empty()) {
  302. CARBON_CHECK(context.generic_region_stack().PeekDependentInsts().empty(),
  303. "Have dependent instruction {0} in declaration {1} but no "
  304. "compile time bindings are in scope.",
  305. context.insts().Get(context.generic_region_stack()
  306. .PeekDependentInsts()
  307. .front()
  308. .inst_id),
  309. context.insts().Get(decl_id));
  310. context.generic_region_stack().Pop();
  311. return SemIR::GenericId::None;
  312. }
  313. // Build the new Generic object. Note that we intentionally do not hold a
  314. // persistent reference to it throughout this function, because the `generics`
  315. // collection can have items added to it by import resolution while we are
  316. // building this generic.
  317. auto bindings_id = context.inst_blocks().Add(all_bindings);
  318. SemIR::GenericId generic_id = context.generics().Add(
  319. SemIR::Generic{.decl_id = decl_id,
  320. .bindings_id = bindings_id,
  321. .self_specific_id = SemIR::SpecificId::None});
  322. // MakeSelfSpecificId could cause something to be imported, which would
  323. // invalidate the return value of `context.generics().Get(generic_id)`.
  324. auto self_specific_id = MakeSelfSpecificId(context, generic_id);
  325. context.generics().Get(generic_id).self_specific_id = self_specific_id;
  326. return generic_id;
  327. }
  328. auto FinishGenericDecl(Context& context, SemIRLoc loc,
  329. SemIR::GenericId generic_id) -> void {
  330. if (!generic_id.has_value()) {
  331. return;
  332. }
  333. auto decl_block_id = MakeGenericEvalBlock(
  334. context, generic_id, SemIR::GenericInstIndex::Region::Declaration);
  335. context.generic_region_stack().Pop();
  336. context.generics().Get(generic_id).decl_block_id = decl_block_id;
  337. ResolveSpecificDeclaration(context, loc,
  338. context.generics().GetSelfSpecific(generic_id));
  339. }
  340. auto BuildGenericDecl(Context& context, SemIR::InstId decl_id)
  341. -> SemIR::GenericId {
  342. SemIR::GenericId generic_id = BuildGeneric(context, decl_id);
  343. if (generic_id.has_value()) {
  344. FinishGenericDecl(context, decl_id, generic_id);
  345. }
  346. return generic_id;
  347. }
  348. auto FinishGenericRedecl(Context& context, SemIR::InstId /*decl_id*/,
  349. SemIR::GenericId /*generic_id*/) -> void {
  350. // TODO: Compare contents of this declaration with the existing one on the
  351. // generic.
  352. context.generic_region_stack().Pop();
  353. }
  354. auto FinishGenericDefinition(Context& context, SemIR::GenericId generic_id)
  355. -> void {
  356. if (!generic_id.has_value()) {
  357. // TODO: We can have symbolic constants in a context that had a non-generic
  358. // declaration, for example if there's a local generic let binding in a
  359. // function definition. Handle this case somehow -- perhaps by forming
  360. // substituted constant values now.
  361. context.generic_region_stack().Pop();
  362. return;
  363. }
  364. auto definition_block_id = MakeGenericEvalBlock(
  365. context, generic_id, SemIR::GenericInstIndex::Region::Definition);
  366. context.generics().Get(generic_id).definition_block_id = definition_block_id;
  367. context.generic_region_stack().Pop();
  368. }
  369. auto ResolveSpecificDeclaration(Context& context, SemIRLoc loc,
  370. SemIR::SpecificId specific_id) -> void {
  371. // If this is the first time we've formed this specific, evaluate its decl
  372. // block to form information about the specific.
  373. if (!context.specifics().Get(specific_id).decl_block_id.has_value()) {
  374. // Set a placeholder value as the decl block ID so we won't attempt to
  375. // recursively resolve the same specific.
  376. context.specifics().Get(specific_id).decl_block_id =
  377. SemIR::InstBlockId::Empty;
  378. auto decl_block_id =
  379. TryEvalBlockForSpecific(context, loc, specific_id,
  380. SemIR::GenericInstIndex::Region::Declaration);
  381. // Note that TryEvalBlockForSpecific may reallocate the list of specifics,
  382. // so re-lookup the specific here.
  383. context.specifics().Get(specific_id).decl_block_id = decl_block_id;
  384. }
  385. }
  386. auto MakeSpecific(Context& context, SemIRLoc loc, SemIR::GenericId generic_id,
  387. SemIR::InstBlockId args_id) -> SemIR::SpecificId {
  388. auto specific_id = context.specifics().GetOrAdd(generic_id, args_id);
  389. ResolveSpecificDeclaration(context, loc, specific_id);
  390. return specific_id;
  391. }
  392. auto MakeSpecific(Context& context, SemIRLoc loc, SemIR::GenericId generic_id,
  393. llvm::ArrayRef<SemIR::InstId> args) -> SemIR::SpecificId {
  394. auto args_id = context.inst_blocks().AddCanonical(args);
  395. return MakeSpecific(context, loc, generic_id, args_id);
  396. }
  397. static auto MakeSelfSpecificId(Context& context, SemIR::GenericId generic_id)
  398. -> SemIR::SpecificId {
  399. if (!generic_id.has_value()) {
  400. return SemIR::SpecificId::None;
  401. }
  402. auto& generic = context.generics().Get(generic_id);
  403. auto args = context.inst_blocks().Get(generic.bindings_id);
  404. // Form a canonical argument list for the generic.
  405. llvm::SmallVector<SemIR::InstId> arg_ids;
  406. arg_ids.reserve(args.size());
  407. for (auto arg_id : args) {
  408. arg_ids.push_back(context.constant_values().GetConstantInstId(arg_id));
  409. }
  410. auto args_id = context.inst_blocks().AddCanonical(arg_ids);
  411. return context.specifics().GetOrAdd(generic_id, args_id);
  412. }
  413. auto MakeSelfSpecific(Context& context, SemIRLoc loc,
  414. SemIR::GenericId generic_id) -> SemIR::SpecificId {
  415. // Build a corresponding specific.
  416. SemIR::SpecificId specific_id = MakeSelfSpecificId(context, generic_id);
  417. // TODO: This could be made more efficient. We don't need to perform
  418. // substitution here; we know we want identity mappings for all constants and
  419. // types. We could also consider not storing the mapping at all in this case.
  420. ResolveSpecificDeclaration(context, loc, specific_id);
  421. return specific_id;
  422. }
  423. auto ResolveSpecificDefinition(Context& context, SemIRLoc loc,
  424. SemIR::SpecificId specific_id) -> bool {
  425. // TODO: Handle recursive resolution of the same generic definition.
  426. auto& specific = context.specifics().Get(specific_id);
  427. auto generic_id = specific.generic_id;
  428. CARBON_CHECK(generic_id.has_value(), "Specific with no generic ID");
  429. if (!specific.definition_block_id.has_value()) {
  430. // Evaluate the eval block for the definition of the generic.
  431. auto& generic = context.generics().Get(generic_id);
  432. if (!generic.definition_block_id.has_value()) {
  433. // The generic is not defined yet.
  434. return false;
  435. }
  436. auto definition_block_id = TryEvalBlockForSpecific(
  437. context, loc, specific_id, SemIR::GenericInstIndex::Region::Definition);
  438. // Note that TryEvalBlockForSpecific may reallocate the list of specifics,
  439. // so re-lookup the specific here.
  440. context.specifics().Get(specific_id).definition_block_id =
  441. definition_block_id;
  442. }
  443. return true;
  444. }
  445. auto GetInstForSpecific(Context& context, SemIR::SpecificId specific_id)
  446. -> SemIR::InstId {
  447. CARBON_CHECK(specific_id.has_value());
  448. const auto& specific = context.specifics().Get(specific_id);
  449. const auto& generic = context.generics().Get(specific.generic_id);
  450. auto decl = context.insts().Get(generic.decl_id);
  451. CARBON_KIND_SWITCH(decl) {
  452. case CARBON_KIND(SemIR::ClassDecl class_decl): {
  453. return context.types().GetInstId(
  454. GetClassType(context, class_decl.class_id, specific_id));
  455. }
  456. case CARBON_KIND(SemIR::InterfaceDecl interface_decl): {
  457. return context.types().GetInstId(
  458. GetInterfaceType(context, interface_decl.interface_id, specific_id));
  459. }
  460. case SemIR::FunctionDecl::Kind: {
  461. return context.constant_values().GetInstId(TryEvalInst(
  462. context, SemIR::InstId::None,
  463. SemIR::SpecificFunction{
  464. .type_id = GetSingletonType(
  465. context, SemIR::SpecificFunctionType::SingletonInstId),
  466. .callee_id = generic.decl_id,
  467. .specific_id = specific_id}));
  468. }
  469. case SemIR::AssociatedConstantDecl::Kind: {
  470. // TODO: We don't have a good instruction to use here.
  471. return generic.decl_id;
  472. }
  473. default: {
  474. CARBON_FATAL("Unknown kind for generic declaration {0}", decl);
  475. }
  476. }
  477. }
  478. } // namespace Carbon::Check