generic.cpp 22 KB

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