inst_namer.cpp 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  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/sem_ir/inst_namer.h"
  5. #include <string>
  6. #include <utility>
  7. #include <variant>
  8. #include "common/ostream.h"
  9. #include "common/raw_string_ostream.h"
  10. #include "llvm/ADT/STLExtras.h"
  11. #include "llvm/ADT/SmallVector.h"
  12. #include "llvm/ADT/StableHashing.h"
  13. #include "toolchain/base/kind_switch.h"
  14. #include "toolchain/base/shared_value_stores.h"
  15. #include "toolchain/base/value_ids.h"
  16. #include "toolchain/lex/tokenized_buffer.h"
  17. #include "toolchain/parse/tree.h"
  18. #include "toolchain/sem_ir/entity_with_params_base.h"
  19. #include "toolchain/sem_ir/function.h"
  20. #include "toolchain/sem_ir/ids.h"
  21. #include "toolchain/sem_ir/inst_kind.h"
  22. #include "toolchain/sem_ir/pattern.h"
  23. #include "toolchain/sem_ir/singleton_insts.h"
  24. #include "toolchain/sem_ir/type_info.h"
  25. #include "toolchain/sem_ir/typed_insts.h"
  26. namespace Carbon::SemIR {
  27. class InstNamer::NamingContext {
  28. public:
  29. explicit NamingContext(InstNamer* inst_namer, InstNamer::ScopeId scope_id,
  30. InstId inst_id);
  31. // Names the single instruction. Use bound names where available. Otherwise,
  32. // assign a backup name.
  33. //
  34. // Insts with a type_id are required to add names; other insts may
  35. // optionally set a name. All insts may push other insts to be named.
  36. auto NameInst() -> void;
  37. private:
  38. // Adds the instruction's name.
  39. auto AddInstName(std::string name) -> void;
  40. // Adds the instruction's name by `NameId`.
  41. auto AddInstNameId(NameId name_id, llvm::StringRef suffix = "") -> void {
  42. AddInstName((sem_ir().names().GetIRBaseName(name_id) + suffix).str());
  43. }
  44. // Names an `IntType` or `FloatType`.
  45. auto AddIntOrFloatTypeName(char type_literal_prefix, InstId bit_width_id,
  46. llvm::StringRef suffix = "") -> void;
  47. // Names an `ImplWitnessTable` instruction.
  48. auto AddWitnessTableName(InstId witness_table_inst_id, std::string name)
  49. -> void;
  50. // Pushes all instructions in a block, by ID.
  51. auto PushBlockId(ScopeId scope_id, InstBlockId block_id) -> void {
  52. inst_namer_->PushBlockId(scope_id, block_id);
  53. }
  54. // Names the instruction as an entity. May push processing of the entity.
  55. template <typename EntityIdT>
  56. auto AddEntityNameAndMaybePush(EntityIdT id, llvm::StringRef suffix = "")
  57. -> void {
  58. AddInstName((inst_namer_->MaybePushEntity(id) + suffix).str());
  59. }
  60. auto sem_ir() -> const SemIR::File& { return *inst_namer_->sem_ir_; }
  61. InstNamer* inst_namer_;
  62. ScopeId scope_id_;
  63. InstId inst_id_;
  64. Inst inst_;
  65. };
  66. InstNamer::InstNamer(const File* sem_ir) : sem_ir_(sem_ir) {
  67. insts_.resize(sem_ir->insts().size(), {ScopeId::None, Namespace::Name()});
  68. labels_.resize(sem_ir->inst_blocks().size());
  69. scopes_.resize(GetScopeIdOffset(ScopeIdTypeEnum::None));
  70. generic_scopes_.resize(sem_ir->generics().size(), ScopeId::None);
  71. // We process the stack between each large block in order to reduce the
  72. // temporary size of the stack.
  73. auto process_stack = [&] {
  74. while (!inst_stack_.empty() || !inst_block_stack_.empty()) {
  75. if (inst_stack_.empty()) {
  76. auto [scope_id, block_id] = inst_block_stack_.pop_back_val();
  77. PushBlockInsts(scope_id, sem_ir_->inst_blocks().Get(block_id));
  78. }
  79. while (!inst_stack_.empty()) {
  80. auto [scope_id, inst_id] = inst_stack_.pop_back_val();
  81. NamingContext context(this, scope_id, inst_id);
  82. context.NameInst();
  83. }
  84. }
  85. };
  86. // Name each of the top-level scopes, in order. We use these as the roots of
  87. // walking the IR.
  88. PushBlockInsts(ScopeId::Constants, sem_ir->constants().array_ref());
  89. process_stack();
  90. PushBlockId(ScopeId::Imports, InstBlockId::Imports);
  91. process_stack();
  92. PushBlockId(ScopeId::File, sem_ir->top_inst_block_id());
  93. process_stack();
  94. // Global init won't have any other references, so we add it directly.
  95. if (sem_ir_->global_ctor_id().has_value()) {
  96. MaybePushEntity(sem_ir_->global_ctor_id());
  97. process_stack();
  98. }
  99. }
  100. auto InstNamer::GetScopeIdOffset(ScopeIdTypeEnum id_enum) const -> int {
  101. int offset = 0;
  102. // For each Id type, add the number of entities *above* its case; for example,
  103. // the offset for functions excludes the functions themselves. The fallthrough
  104. // handles summing to get uniqueness; order isn't special.
  105. switch (id_enum) {
  106. case ScopeIdTypeEnum::None:
  107. // `None` will be getting a full count of scopes.
  108. offset += sem_ir_->associated_constants().size();
  109. [[fallthrough]];
  110. case ScopeIdTypeEnum::For<AssociatedConstantId>:
  111. offset += sem_ir_->classes().size();
  112. [[fallthrough]];
  113. case ScopeIdTypeEnum::For<ClassId>:
  114. offset += sem_ir_->vtables().size();
  115. [[fallthrough]];
  116. case ScopeIdTypeEnum::For<VtableId>:
  117. offset += sem_ir_->functions().size();
  118. [[fallthrough]];
  119. case ScopeIdTypeEnum::For<FunctionId>:
  120. offset += sem_ir_->impls().size();
  121. [[fallthrough]];
  122. case ScopeIdTypeEnum::For<ImplId>:
  123. offset += sem_ir_->interfaces().size();
  124. [[fallthrough]];
  125. case ScopeIdTypeEnum::For<InterfaceId>:
  126. offset += sem_ir_->specific_interfaces().size();
  127. [[fallthrough]];
  128. case ScopeIdTypeEnum::For<SpecificInterfaceId>:
  129. // All type-specific scopes are offset by `FirstEntityScope`.
  130. offset += static_cast<int>(ScopeId::FirstEntityScope);
  131. return offset;
  132. default:
  133. CARBON_FATAL("Unexpected ScopeIdTypeEnum: {0}", id_enum);
  134. }
  135. }
  136. auto InstNamer::GetScopeName(ScopeId scope) const -> std::string {
  137. switch (scope) {
  138. case ScopeId::None:
  139. return "<no scope>";
  140. // These are treated as SemIR keywords.
  141. case ScopeId::File:
  142. return "file";
  143. case ScopeId::Imports:
  144. return "imports";
  145. case ScopeId::Constants:
  146. return "constants";
  147. // For everything else, use an @ prefix.
  148. default:
  149. return ("@" + GetScopeInfo(scope).name.GetFullName()).str();
  150. }
  151. }
  152. auto InstNamer::GetUnscopedNameFor(InstId inst_id) const -> llvm::StringRef {
  153. if (!inst_id.has_value()) {
  154. return "";
  155. }
  156. if (IsSingletonInstId(inst_id)) {
  157. return sem_ir_->insts().Get(inst_id).kind().ir_name();
  158. }
  159. const auto& inst_name = insts_[inst_id.index].second;
  160. return inst_name ? inst_name.GetFullName() : "";
  161. }
  162. auto InstNamer::GetNameFor(ScopeId scope_id, InstId inst_id) const
  163. -> std::string {
  164. if (!inst_id.has_value()) {
  165. return "invalid";
  166. }
  167. // Check for a builtin.
  168. if (IsSingletonInstId(inst_id)) {
  169. return sem_ir_->insts().Get(inst_id).kind().ir_name().str();
  170. }
  171. if (inst_id == SemIR::Namespace::PackageInstId) {
  172. return "package";
  173. }
  174. const auto& [inst_scope, inst_name] = insts_[inst_id.index];
  175. if (!inst_name) {
  176. // This should not happen in valid IR.
  177. RawStringOstream out;
  178. out << "<unexpected>." << inst_id;
  179. auto loc_id = sem_ir_->insts().GetCanonicalLocId(inst_id);
  180. // TODO: Consider handling other kinds.
  181. if (loc_id.kind() == LocId::Kind::NodeId) {
  182. const auto& tree = sem_ir_->parse_tree();
  183. auto token = tree.node_token(loc_id.node_id());
  184. out << ".loc" << tree.tokens().GetLineNumber(token) << "_"
  185. << tree.tokens().GetColumnNumber(token);
  186. }
  187. return out.TakeStr();
  188. }
  189. if (inst_scope == scope_id) {
  190. return ("%" + inst_name.GetFullName()).str();
  191. }
  192. return (GetScopeName(inst_scope) + ".%" + inst_name.GetFullName()).str();
  193. }
  194. auto InstNamer::GetUnscopedLabelFor(InstBlockId block_id) const
  195. -> llvm::StringRef {
  196. if (!block_id.has_value()) {
  197. return "";
  198. }
  199. const auto& label_name = labels_[block_id.index].second;
  200. return label_name ? label_name.GetFullName() : "";
  201. }
  202. // Returns the IR name to use for a label, when referenced from a given scope.
  203. auto InstNamer::GetLabelFor(ScopeId scope_id, InstBlockId block_id) const
  204. -> std::string {
  205. if (!block_id.has_value()) {
  206. return "!invalid";
  207. }
  208. const auto& [label_scope, label_name] = labels_[block_id.index];
  209. if (!label_name) {
  210. // This should not happen in valid IR.
  211. RawStringOstream out;
  212. out << "<unexpected instblockref " << block_id << ">";
  213. return out.TakeStr();
  214. }
  215. if (label_scope == scope_id) {
  216. return ("!" + label_name.GetFullName()).str();
  217. }
  218. return (GetScopeName(label_scope) + ".!" + label_name.GetFullName()).str();
  219. }
  220. auto InstNamer::Namespace::Name::GetFullName() const -> llvm::StringRef {
  221. if (!value_) {
  222. return "<null name>";
  223. }
  224. llvm::StringMapEntry<NameResult>* value = value_;
  225. while (value->second.ambiguous && value->second.fallback) {
  226. value = value->second.fallback.value_;
  227. }
  228. return value->first();
  229. }
  230. auto InstNamer::Namespace::Name::GetBaseName() const -> llvm::StringRef {
  231. if (!value_) {
  232. return "<null name>";
  233. }
  234. return value_->first().take_front(base_name_size_);
  235. }
  236. auto InstNamer::Namespace::AllocateName(
  237. const InstNamer& inst_namer,
  238. std::variant<LocId, uint64_t> loc_id_or_fingerprint, std::string name)
  239. -> Name {
  240. // The best (shortest) name for this instruction so far, and the current
  241. // name for it.
  242. Name best;
  243. Name current;
  244. const size_t base_name_size = name.size();
  245. // Add `name` as a name for this entity.
  246. auto add_name = [&](bool mark_ambiguous = true) {
  247. auto [it, added] = allocated_.insert({name, NameResult()});
  248. Name new_name = Name(it, base_name_size);
  249. if (!added) {
  250. if (mark_ambiguous) {
  251. // This name was allocated for a different instruction. Mark it as
  252. // ambiguous and keep looking for a name for this instruction.
  253. new_name.SetAmbiguous();
  254. }
  255. } else {
  256. if (!best) {
  257. best = new_name;
  258. } else {
  259. CARBON_CHECK(current);
  260. current.SetFallback(new_name);
  261. }
  262. current = new_name;
  263. }
  264. return added;
  265. };
  266. // Use the given name if it's available.
  267. if (!name.empty()) {
  268. add_name();
  269. }
  270. // Append location information to try to disambiguate.
  271. if (auto* loc_id = std::get_if<LocId>(&loc_id_or_fingerprint)) {
  272. *loc_id = inst_namer.sem_ir_->insts().GetCanonicalLocId(*loc_id);
  273. // TODO: Consider handling other kinds.
  274. if (loc_id->kind() == LocId::Kind::NodeId) {
  275. const auto& tree = inst_namer.sem_ir_->parse_tree();
  276. auto token = tree.node_token(loc_id->node_id());
  277. llvm::raw_string_ostream(name)
  278. << ".loc" << tree.tokens().GetLineNumber(token);
  279. add_name();
  280. llvm::raw_string_ostream(name)
  281. << "_" << tree.tokens().GetColumnNumber(token);
  282. add_name();
  283. }
  284. } else {
  285. uint64_t fingerprint = std::get<uint64_t>(loc_id_or_fingerprint);
  286. llvm::raw_string_ostream out(name);
  287. out << ".";
  288. // Include names with 3-6 characters from the fingerprint. Then fall back to
  289. // sequential numbering.
  290. for (int n : llvm::seq(1, 7)) {
  291. out.write_hex((fingerprint >> (64 - 4 * n)) & 0xF);
  292. if (n >= 3) {
  293. add_name();
  294. }
  295. }
  296. }
  297. // Append numbers until we find an available name.
  298. name += ".";
  299. auto name_size_without_counter = name.size();
  300. for (int counter = 1;; ++counter) {
  301. name.resize(name_size_without_counter);
  302. llvm::raw_string_ostream(name) << counter;
  303. if (add_name(/*mark_ambiguous=*/false)) {
  304. return best;
  305. }
  306. }
  307. }
  308. auto InstNamer::AddBlockLabel(
  309. ScopeId scope_id, InstBlockId block_id, std::string name,
  310. std::variant<LocId, uint64_t> loc_id_or_fingerprint) -> void {
  311. if (!block_id.has_value() || labels_[block_id.index].second) {
  312. return;
  313. }
  314. if (auto* loc_id = std::get_if<LocId>(&loc_id_or_fingerprint);
  315. loc_id && !loc_id->has_value()) {
  316. if (const auto& block = sem_ir_->inst_blocks().Get(block_id);
  317. !block.empty()) {
  318. loc_id_or_fingerprint = LocId(block.front());
  319. }
  320. }
  321. labels_[block_id.index] = {
  322. scope_id, GetScopeInfo(scope_id).labels.AllocateName(
  323. *this, loc_id_or_fingerprint, std::move(name))};
  324. }
  325. // Provides names for `AddBlockLabel`.
  326. struct BranchNames {
  327. // Returns names for a branching parse node, or nullopt if not a branch.
  328. static auto For(Parse::NodeKind node_kind) -> std::optional<BranchNames> {
  329. switch (node_kind) {
  330. case Parse::NodeKind::ForHeaderStart:
  331. return {{.prefix = "for", .branch = "next"}};
  332. case Parse::NodeKind::ForHeader:
  333. return {{.prefix = "for", .branch_if = "body", .branch = "done"}};
  334. case Parse::NodeKind::IfExprIf:
  335. return {{.prefix = "if.expr",
  336. .branch_if = "then",
  337. .branch = "else",
  338. .branch_with_arg = "result"}};
  339. case Parse::NodeKind::IfCondition:
  340. return {{.prefix = "if", .branch_if = "then", .branch = "else"}};
  341. case Parse::NodeKind::IfStatement:
  342. return {{.prefix = "if", .branch = "done"}};
  343. case Parse::NodeKind::ShortCircuitOperandAnd:
  344. return {
  345. {.prefix = "and", .branch_if = "rhs", .branch_with_arg = "result"}};
  346. case Parse::NodeKind::ShortCircuitOperandOr:
  347. return {
  348. {.prefix = "or", .branch_if = "rhs", .branch_with_arg = "result"}};
  349. case Parse::NodeKind::WhileConditionStart:
  350. return {{.prefix = "while", .branch = "cond"}};
  351. case Parse::NodeKind::WhileCondition:
  352. return {{.prefix = "while", .branch_if = "body", .branch = "done"}};
  353. default:
  354. return std::nullopt;
  355. }
  356. }
  357. // Returns the provided suffix for the instruction kind, or an empty string.
  358. auto GetSuffix(InstKind inst_kind) -> llvm::StringLiteral {
  359. switch (inst_kind) {
  360. case BranchIf::Kind:
  361. return branch_if;
  362. case Branch::Kind:
  363. return branch;
  364. case BranchWithArg::Kind:
  365. return branch_with_arg;
  366. default:
  367. return "";
  368. }
  369. }
  370. // The kind of branch, based on the node kind.
  371. llvm::StringLiteral prefix;
  372. // For labeling branch instruction kinds. Only expected kinds need a value;
  373. // the empty string is for unexpected kinds.
  374. llvm::StringLiteral branch_if = "";
  375. llvm::StringLiteral branch = "";
  376. llvm::StringLiteral branch_with_arg = "";
  377. };
  378. // Finds and adds a suitable block label for the given SemIR instruction that
  379. // represents some kind of branch.
  380. auto InstNamer::AddBlockLabel(ScopeId scope_id, LocId loc_id, AnyBranch branch)
  381. -> void {
  382. std::string label;
  383. loc_id = sem_ir_->insts().GetCanonicalLocId(loc_id);
  384. if (loc_id.node_id().has_value()) {
  385. if (auto names = BranchNames::For(
  386. sem_ir_->parse_tree().node_kind(loc_id.node_id()))) {
  387. if (auto suffix = names->GetSuffix(branch.kind); !suffix.empty()) {
  388. label = llvm::formatv("{0}.{1}", names->prefix, suffix);
  389. } else {
  390. label =
  391. llvm::formatv("{0}.<unexpected {1}>", names->prefix, branch.kind);
  392. }
  393. }
  394. }
  395. AddBlockLabel(scope_id, branch.target_id, label, loc_id);
  396. }
  397. auto InstNamer::PushBlockId(ScopeId scope_id, InstBlockId block_id) -> void {
  398. if (block_id.has_value()) {
  399. inst_block_stack_.push_back({scope_id, block_id});
  400. }
  401. }
  402. auto InstNamer::PushBlockInsts(ScopeId scope_id,
  403. llvm::ArrayRef<InstId> inst_ids) -> void {
  404. for (auto inst_id : llvm::reverse(inst_ids)) {
  405. if (inst_id.has_value() && !IsSingletonInstId(inst_id)) {
  406. inst_stack_.push_back(std::make_pair(scope_id, inst_id));
  407. }
  408. }
  409. }
  410. auto InstNamer::PushGeneric(ScopeId scope_id, GenericId generic_id) -> void {
  411. if (!generic_id.has_value()) {
  412. return;
  413. }
  414. generic_scopes_[generic_id.index] = scope_id;
  415. const auto& generic = sem_ir_->generics().Get(generic_id);
  416. // Push blocks in reverse order.
  417. PushBlockId(scope_id, generic.definition_block_id);
  418. PushBlockId(scope_id, generic.decl_block_id);
  419. }
  420. auto InstNamer::PushEntity(AssociatedConstantId associated_constant_id,
  421. ScopeId scope_id, Scope& scope) -> void {
  422. const auto& assoc_const =
  423. sem_ir_->associated_constants().Get(associated_constant_id);
  424. scope.name = globals_.AllocateName(
  425. *this, LocId(assoc_const.decl_id),
  426. sem_ir_->names().GetIRBaseName(assoc_const.name_id).str());
  427. // Push blocks in reverse order.
  428. PushGeneric(scope_id, assoc_const.generic_id);
  429. }
  430. auto InstNamer::PushEntity(ClassId class_id, ScopeId scope_id, Scope& scope)
  431. -> void {
  432. const auto& class_info = sem_ir_->classes().Get(class_id);
  433. LocId class_loc(class_info.latest_decl_id());
  434. scope.name = globals_.AllocateName(
  435. *this, class_loc,
  436. sem_ir_->names().GetIRBaseName(class_info.name_id).str());
  437. AddBlockLabel(scope_id, class_info.body_block_id, "class", class_loc);
  438. PushGeneric(scope_id, class_info.generic_id);
  439. // Push blocks in reverse order.
  440. PushBlockId(scope_id, class_info.body_block_id);
  441. PushBlockId(scope_id, class_info.pattern_block_id);
  442. }
  443. auto InstNamer::GetNameForParentNameScope(NameScopeId name_scope_id)
  444. -> llvm::StringRef {
  445. if (!name_scope_id.has_value()) {
  446. return "";
  447. }
  448. auto scope_inst =
  449. sem_ir_->insts().Get(sem_ir_->name_scopes().Get(name_scope_id).inst_id());
  450. CARBON_KIND_SWITCH(scope_inst) {
  451. case CARBON_KIND(ClassDecl class_decl): {
  452. return MaybePushEntity(class_decl.class_id);
  453. }
  454. case CARBON_KIND(ImplDecl impl): {
  455. return MaybePushEntity(impl.impl_id);
  456. }
  457. case CARBON_KIND(InterfaceDecl interface): {
  458. return MaybePushEntity(interface.interface_id);
  459. }
  460. case SemIR::Namespace::Kind: {
  461. // Only prefix type scopes.
  462. return "";
  463. }
  464. default: {
  465. return "<unsupported scope>";
  466. }
  467. }
  468. }
  469. auto InstNamer::PushEntity(FunctionId function_id, ScopeId scope_id,
  470. Scope& scope) -> void {
  471. const auto& fn = sem_ir_->functions().Get(function_id);
  472. LocId fn_loc(fn.latest_decl_id());
  473. auto scope_prefix = GetNameForParentNameScope(fn.parent_scope_id);
  474. scope.name = globals_.AllocateName(
  475. *this, fn_loc,
  476. llvm::formatv("{0}{1}{2}", scope_prefix, scope_prefix.empty() ? "" : ".",
  477. sem_ir_->names().GetIRBaseName(fn.name_id)));
  478. if (!fn.body_block_ids.empty()) {
  479. AddBlockLabel(scope_id, fn.body_block_ids.front(), "entry", fn_loc);
  480. }
  481. // Push blocks in reverse order.
  482. PushGeneric(scope_id, fn.generic_id);
  483. for (auto block_id : llvm::reverse(fn.body_block_ids)) {
  484. PushBlockId(scope_id, block_id);
  485. }
  486. PushBlockId(scope_id, fn.pattern_block_id);
  487. PushBlockId(scope_id, fn.call_params_id);
  488. }
  489. auto InstNamer::PushEntity(ImplId impl_id, ScopeId scope_id, Scope& scope)
  490. -> void {
  491. const auto& impl = sem_ir_->impls().Get(impl_id);
  492. auto impl_fingerprint = fingerprinter_.GetOrCompute(sem_ir_, impl_id);
  493. llvm::StringRef self_name;
  494. auto self_const_id =
  495. sem_ir_->constant_values().GetConstantInstId(impl.self_id);
  496. if (IsSingletonInstId(self_const_id)) {
  497. self_name = sem_ir_->insts().Get(self_const_id).kind().ir_name();
  498. } else if (const auto& inst_name = insts_[self_const_id.index].second) {
  499. self_name = inst_name.GetBaseName();
  500. } else {
  501. self_name = "<unexpected self>";
  502. }
  503. llvm::StringRef interface_name;
  504. if (impl.interface.interface_id.has_value()) {
  505. interface_name = MaybePushEntity(impl.interface.interface_id);
  506. } else {
  507. interface_name = "<error>";
  508. }
  509. scope.name = globals_.AllocateName(
  510. *this, impl_fingerprint,
  511. llvm::formatv("{0}.as.{1}.impl", self_name, interface_name));
  512. AddBlockLabel(scope_id, impl.body_block_id, "impl", impl_fingerprint);
  513. // Push blocks in reverse order.
  514. PushGeneric(scope_id, impl.generic_id);
  515. PushBlockId(scope_id, impl.body_block_id);
  516. PushBlockId(scope_id, impl.pattern_block_id);
  517. }
  518. auto InstNamer::PushEntity(InterfaceId interface_id, ScopeId scope_id,
  519. Scope& scope) -> void {
  520. const auto& interface = sem_ir_->interfaces().Get(interface_id);
  521. LocId interface_loc(interface.latest_decl_id());
  522. scope.name = globals_.AllocateName(
  523. *this, interface_loc,
  524. sem_ir_->names().GetIRBaseName(interface.name_id).str());
  525. AddBlockLabel(scope_id, interface.body_block_id, "interface", interface_loc);
  526. // Push blocks in reverse order.
  527. PushGeneric(scope_id, interface.generic_id);
  528. PushBlockId(scope_id, interface.body_block_id);
  529. PushBlockId(scope_id, interface.pattern_block_id);
  530. }
  531. auto InstNamer::PushEntity(VtableId vtable_id, ScopeId /*scope_id*/,
  532. Scope& scope) -> void {
  533. const auto& vtable = sem_ir_->vtables().Get(vtable_id);
  534. const auto& class_info = sem_ir_->classes().Get(vtable.class_id);
  535. LocId vtable_loc(class_info.latest_decl_id());
  536. scope.name = globals_.AllocateName(
  537. *this, vtable_loc,
  538. sem_ir_->names().GetIRBaseName(class_info.name_id).str() + ".vtable");
  539. // TODO: Add support for generic vtables here and elsewhere.
  540. // PushGeneric(scope_id, vtable_info.generic_id);
  541. }
  542. InstNamer::NamingContext::NamingContext(InstNamer* inst_namer,
  543. InstNamer::ScopeId scope_id,
  544. InstId inst_id)
  545. : inst_namer_(inst_namer),
  546. scope_id_(scope_id),
  547. inst_id_(inst_id),
  548. inst_(sem_ir().insts().Get(inst_id)) {}
  549. auto InstNamer::NamingContext::AddInstName(std::string name) -> void {
  550. ScopeId old_scope_id = inst_namer_->insts_[inst_id_.index].first;
  551. if (old_scope_id == ScopeId::None) {
  552. std::variant<LocId, uint64_t> loc_id_or_fingerprint = LocId::None;
  553. if (scope_id_ == ScopeId::Constants || scope_id_ == ScopeId::Imports) {
  554. loc_id_or_fingerprint =
  555. inst_namer_->fingerprinter_.GetOrCompute(&sem_ir(), inst_id_);
  556. } else {
  557. loc_id_or_fingerprint = LocId(inst_id_);
  558. }
  559. auto scoped_name = inst_namer_->GetScopeInfo(scope_id_).insts.AllocateName(
  560. *inst_namer_, loc_id_or_fingerprint, name);
  561. inst_namer_->insts_[inst_id_.index] = {scope_id_, scoped_name};
  562. } else {
  563. CARBON_CHECK(old_scope_id == scope_id_,
  564. "Attempting to name inst in multiple scopes");
  565. }
  566. }
  567. auto InstNamer::NamingContext::AddIntOrFloatTypeName(char type_literal_prefix,
  568. InstId bit_width_id,
  569. llvm::StringRef suffix)
  570. -> void {
  571. RawStringOstream out;
  572. out << type_literal_prefix;
  573. if (auto bit_width = sem_ir().insts().TryGetAs<IntValue>(bit_width_id)) {
  574. out << sem_ir().ints().Get(bit_width->int_id);
  575. } else {
  576. out << "N";
  577. }
  578. out << suffix;
  579. AddInstName(out.TakeStr());
  580. }
  581. auto InstNamer::NamingContext::AddWitnessTableName(InstId witness_table_inst_id,
  582. std::string name) -> void {
  583. auto witness_table =
  584. sem_ir().insts().GetAs<ImplWitnessTable>(witness_table_inst_id);
  585. if (!witness_table.impl_id.has_value()) {
  586. // TODO: The witness comes from a facet value. Can we get the
  587. // interface names from it? Store the facet value instruction in the
  588. // table?
  589. AddInstName(name);
  590. return;
  591. }
  592. const auto& impl = sem_ir().impls().Get(witness_table.impl_id);
  593. auto name_id = sem_ir().interfaces().Get(impl.interface.interface_id).name_id;
  594. std::string suffix = llvm::formatv(".{}", name);
  595. AddInstNameId(name_id, suffix);
  596. }
  597. auto InstNamer::NamingContext::NameInst() -> void {
  598. CARBON_KIND_SWITCH(inst_) {
  599. case AddrOf::Kind: {
  600. AddInstName("addr");
  601. return;
  602. }
  603. case ArrayType::Kind: {
  604. // TODO: Can we figure out the name of the type this is an array of?
  605. AddInstName("array_type");
  606. return;
  607. }
  608. case CARBON_KIND(AssociatedConstantDecl inst): {
  609. AddEntityNameAndMaybePush(inst.assoc_const_id);
  610. PushBlockId(inst_namer_->GetScopeFor(inst.assoc_const_id),
  611. inst.decl_block_id);
  612. return;
  613. }
  614. case CARBON_KIND(AssociatedEntity inst): {
  615. RawStringOstream out;
  616. out << "assoc" << inst.index.index;
  617. AddInstName(out.TakeStr());
  618. return;
  619. }
  620. case CARBON_KIND(AssociatedEntityType inst): {
  621. AddEntityNameAndMaybePush(inst.interface_id, ".assoc_type");
  622. return;
  623. }
  624. case BindAlias::Kind:
  625. case BindName::Kind:
  626. case BindSymbolicName::Kind:
  627. case ExportDecl::Kind: {
  628. auto inst = inst_.As<AnyBindNameOrExportDecl>();
  629. AddInstNameId(sem_ir().entity_names().Get(inst.entity_name_id).name_id);
  630. return;
  631. }
  632. case BindingPattern::Kind:
  633. case SymbolicBindingPattern::Kind: {
  634. auto inst = inst_.As<AnyBindingPattern>();
  635. auto name_id = NameId::Underscore;
  636. if (inst.entity_name_id.has_value()) {
  637. name_id = sem_ir().entity_names().Get(inst.entity_name_id).name_id;
  638. }
  639. AddInstNameId(name_id, ".patt");
  640. return;
  641. }
  642. case CARBON_KIND(BoolLiteral inst): {
  643. if (inst.value.ToBool()) {
  644. AddInstName("true");
  645. } else {
  646. AddInstName("false");
  647. }
  648. return;
  649. }
  650. case CARBON_KIND(BoundMethod inst): {
  651. auto type_id = sem_ir().insts().Get(inst.function_decl_id).type_id();
  652. if (auto fn_ty = sem_ir().types().TryGetAs<FunctionType>(type_id)) {
  653. AddEntityNameAndMaybePush(fn_ty->function_id, ".bound");
  654. } else {
  655. AddInstName("bound_method");
  656. }
  657. return;
  658. }
  659. case Branch::Kind:
  660. case BranchIf::Kind:
  661. case BranchWithArg::Kind: {
  662. auto branch = inst_.As<AnyBranch>();
  663. inst_namer_->AddBlockLabel(scope_id_, LocId(inst_id_), branch);
  664. return;
  665. }
  666. case CARBON_KIND(Call inst): {
  667. auto callee_function = GetCalleeFunction(sem_ir(), inst.callee_id);
  668. if (!callee_function.function_id.has_value()) {
  669. AddInstName("");
  670. return;
  671. }
  672. AddEntityNameAndMaybePush(callee_function.function_id, ".call");
  673. return;
  674. }
  675. case CARBON_KIND(ClassDecl inst): {
  676. AddEntityNameAndMaybePush(inst.class_id, ".decl");
  677. auto class_scope_id = inst_namer_->GetScopeFor(inst.class_id);
  678. PushBlockId(class_scope_id, inst.decl_block_id);
  679. return;
  680. }
  681. case CARBON_KIND(ClassType inst): {
  682. if (auto literal_info = NumericTypeLiteralInfo::ForType(sem_ir(), inst);
  683. literal_info.is_valid()) {
  684. AddInstName(literal_info.GetLiteralAsString(sem_ir()));
  685. } else {
  686. AddEntityNameAndMaybePush(inst.class_id);
  687. }
  688. return;
  689. }
  690. case CompleteTypeWitness::Kind: {
  691. // TODO: Can we figure out the name of the type this is a witness for?
  692. AddInstName("complete_type");
  693. return;
  694. }
  695. case CARBON_KIND(VtablePtr inst): {
  696. const auto& vtable = sem_ir().vtables().Get(inst.vtable_id);
  697. if (inst_namer_->GetScopeFor(vtable.class_id) == scope_id_) {
  698. inst_namer_->MaybePushEntity(inst.vtable_id);
  699. AddInstName("vtable_ptr");
  700. } else {
  701. AddEntityNameAndMaybePush(inst.vtable_id, "_ptr");
  702. }
  703. return;
  704. }
  705. case ConstType::Kind: {
  706. // TODO: Can we figure out the name of the type argument?
  707. AddInstName("const");
  708. return;
  709. }
  710. case CARBON_KIND(FacetAccessType inst): {
  711. auto name_id = NameId::None;
  712. if (auto name =
  713. sem_ir().insts().TryGetAs<NameRef>(inst.facet_value_inst_id)) {
  714. name_id = name->name_id;
  715. } else if (auto symbolic = sem_ir().insts().TryGetAs<BindSymbolicName>(
  716. inst.facet_value_inst_id)) {
  717. name_id = sem_ir().entity_names().Get(symbolic->entity_name_id).name_id;
  718. }
  719. if (name_id.has_value()) {
  720. AddInstNameId(name_id, ".as_type");
  721. } else {
  722. AddInstName("as_type");
  723. }
  724. return;
  725. }
  726. case CARBON_KIND(FacetType inst): {
  727. const auto& facet_type_info =
  728. sem_ir().facet_types().Get(inst.facet_type_id);
  729. bool has_where = facet_type_info.other_requirements ||
  730. !facet_type_info.self_impls_constraints.empty() ||
  731. !facet_type_info.rewrite_constraints.empty();
  732. if (facet_type_info.extend_constraints.size() == 1) {
  733. AddEntityNameAndMaybePush(
  734. facet_type_info.extend_constraints.front().interface_id,
  735. has_where ? "_where.type" : ".type");
  736. } else if (facet_type_info.extend_constraints.empty()) {
  737. AddInstName(has_where ? "type_where" : "type");
  738. } else {
  739. AddInstName("facet_type");
  740. }
  741. return;
  742. }
  743. case CARBON_KIND(FacetValue inst): {
  744. if (auto facet_type =
  745. sem_ir().types().TryGetAs<FacetType>(inst.type_id)) {
  746. const auto& facet_type_info =
  747. sem_ir().facet_types().Get(facet_type->facet_type_id);
  748. if (auto interface = facet_type_info.TryAsSingleInterface()) {
  749. AddEntityNameAndMaybePush(interface->interface_id, ".facet");
  750. return;
  751. }
  752. }
  753. AddInstName("facet_value");
  754. return;
  755. }
  756. case FloatLiteral::Kind: {
  757. AddInstName("float");
  758. return;
  759. }
  760. case CARBON_KIND(FloatType inst): {
  761. AddIntOrFloatTypeName('f', inst.bit_width_id);
  762. return;
  763. }
  764. case CARBON_KIND(FunctionDecl inst): {
  765. AddEntityNameAndMaybePush(inst.function_id, ".decl");
  766. auto function_scope_id = inst_namer_->GetScopeFor(inst.function_id);
  767. PushBlockId(function_scope_id, inst.decl_block_id);
  768. return;
  769. }
  770. case CARBON_KIND(FunctionType inst): {
  771. AddEntityNameAndMaybePush(inst.function_id, ".type");
  772. return;
  773. }
  774. case CARBON_KIND(GenericClassType inst): {
  775. AddEntityNameAndMaybePush(inst.class_id, ".type");
  776. return;
  777. }
  778. case CARBON_KIND(GenericInterfaceType inst): {
  779. AddEntityNameAndMaybePush(inst.interface_id, ".type");
  780. return;
  781. }
  782. case CARBON_KIND(ImplDecl inst): {
  783. // `impl` declarations aren't named because they aren't added to any
  784. // namespace, and so aren't referenced directly.
  785. inst_namer_->MaybePushEntity(inst.impl_id);
  786. PushBlockId(inst_namer_->GetScopeFor(inst.impl_id), inst.decl_block_id);
  787. return;
  788. }
  789. case CARBON_KIND(LookupImplWitness inst): {
  790. const auto& interface =
  791. sem_ir().specific_interfaces().Get(inst.query_specific_interface_id);
  792. AddEntityNameAndMaybePush(interface.interface_id, ".lookup_impl_witness");
  793. return;
  794. }
  795. case CARBON_KIND(ImplWitness inst): {
  796. AddWitnessTableName(inst.witness_table_id, "impl_witness");
  797. return;
  798. }
  799. case CARBON_KIND(ImplWitnessAccess inst): {
  800. // TODO: Include information about the impl?
  801. RawStringOstream out;
  802. out << "impl.elem" << inst.index.index;
  803. AddInstName(out.TakeStr());
  804. return;
  805. }
  806. case ImplWitnessAssociatedConstant::Kind: {
  807. AddInstName("impl_witness_assoc_constant");
  808. return;
  809. }
  810. case ImplWitnessTable::Kind: {
  811. AddWitnessTableName(inst_id_, "impl_witness_table");
  812. return;
  813. }
  814. case ImportCppDecl::Kind: {
  815. AddInstName("Cpp.import_cpp");
  816. return;
  817. }
  818. case CARBON_KIND(ImportDecl inst): {
  819. if (inst.package_id.has_value()) {
  820. AddInstNameId(inst.package_id, ".import");
  821. } else {
  822. AddInstName("default.import");
  823. }
  824. return;
  825. }
  826. case ImportRefUnloaded::Kind:
  827. case ImportRefLoaded::Kind: {
  828. // Build the base import name: <package>.<entity-name>
  829. RawStringOstream out;
  830. auto inst = inst_.As<AnyImportRef>();
  831. auto import_ir_inst =
  832. sem_ir().import_ir_insts().Get(inst.import_ir_inst_id);
  833. const auto& import_ir =
  834. *sem_ir().import_irs().Get(import_ir_inst.ir_id()).sem_ir;
  835. auto package_id = import_ir.package_id();
  836. if (auto ident_id = package_id.AsIdentifierId(); ident_id.has_value()) {
  837. out << import_ir.identifiers().Get(ident_id);
  838. } else {
  839. out << package_id.AsSpecialName();
  840. }
  841. out << ".";
  842. // Add entity name if available.
  843. if (inst.entity_name_id.has_value()) {
  844. auto name_id = sem_ir().entity_names().Get(inst.entity_name_id).name_id;
  845. out << sem_ir().names().GetIRBaseName(name_id);
  846. } else {
  847. out << "import_ref";
  848. }
  849. AddInstName(out.TakeStr());
  850. // When building import refs, we frequently add instructions without
  851. // a block. Constants that refer to them need to be separately
  852. // named.
  853. auto const_id = sem_ir().constant_values().Get(inst_id_);
  854. if (const_id.has_value() && const_id.is_concrete()) {
  855. auto const_inst_id = sem_ir().constant_values().GetInstId(const_id);
  856. if (!inst_namer_->insts_[const_inst_id.index].second) {
  857. inst_namer_->PushBlockInsts(ScopeId::Imports, const_inst_id);
  858. }
  859. }
  860. return;
  861. }
  862. case CARBON_KIND(InstValue inst): {
  863. inst_namer_->PushBlockInsts(scope_id_, inst.inst_id);
  864. AddInstName(
  865. ("inst." + sem_ir().insts().Get(inst.inst_id).kind().ir_name())
  866. .str());
  867. return;
  868. }
  869. case CARBON_KIND(InterfaceDecl inst): {
  870. AddEntityNameAndMaybePush(inst.interface_id, ".decl");
  871. auto interface_scope_id = inst_namer_->GetScopeFor(inst.interface_id);
  872. PushBlockId(interface_scope_id, inst.decl_block_id);
  873. return;
  874. }
  875. case CARBON_KIND(IntType inst): {
  876. AddIntOrFloatTypeName(inst.int_kind == IntKind::Signed ? 'i' : 'u',
  877. inst.bit_width_id, ".builtin");
  878. return;
  879. }
  880. case CARBON_KIND(IntValue inst): {
  881. RawStringOstream out;
  882. out << "int_" << sem_ir().ints().Get(inst.int_id);
  883. AddInstName(out.TakeStr());
  884. return;
  885. }
  886. case CARBON_KIND(NameBindingDecl inst): {
  887. PushBlockId(scope_id_, inst.pattern_block_id);
  888. return;
  889. }
  890. case CARBON_KIND(NameRef inst): {
  891. AddInstNameId(inst.name_id, ".ref");
  892. return;
  893. }
  894. // The namespace is specified here due to the name conflict.
  895. case CARBON_KIND(SemIR::Namespace inst): {
  896. AddInstNameId(sem_ir().name_scopes().Get(inst.name_scope_id).name_id());
  897. return;
  898. }
  899. case OutParam::Kind:
  900. case RefParam::Kind:
  901. case ValueParam::Kind: {
  902. AddInstNameId(inst_.As<AnyParam>().pretty_name_id, ".param");
  903. return;
  904. }
  905. case OutParamPattern::Kind:
  906. case RefParamPattern::Kind:
  907. case ValueParamPattern::Kind: {
  908. AddInstNameId(GetPrettyNameFromPatternId(sem_ir(), inst_id_),
  909. ".param_patt");
  910. return;
  911. }
  912. case PatternType::Kind: {
  913. AddInstName("pattern_type");
  914. return;
  915. }
  916. case PointerType::Kind: {
  917. AddInstName("ptr");
  918. return;
  919. }
  920. case RequireCompleteType::Kind: {
  921. AddInstName("require_complete");
  922. return;
  923. }
  924. case ReturnSlotPattern::Kind: {
  925. AddInstNameId(NameId::ReturnSlot, ".patt");
  926. return;
  927. }
  928. case CARBON_KIND(SpecificFunction inst): {
  929. auto type_id = sem_ir().insts().Get(inst.callee_id).type_id();
  930. if (auto fn_ty = sem_ir().types().TryGetAs<FunctionType>(type_id)) {
  931. AddEntityNameAndMaybePush(fn_ty->function_id, ".specific_fn");
  932. } else {
  933. AddInstName("specific_fn");
  934. }
  935. return;
  936. }
  937. case CARBON_KIND(SpecificImplFunction inst): {
  938. auto type_id = sem_ir().insts().Get(inst.callee_id).type_id();
  939. if (auto fn_ty = sem_ir().types().TryGetAs<FunctionType>(type_id)) {
  940. AddEntityNameAndMaybePush(fn_ty->function_id, ".specific_impl_fn");
  941. } else {
  942. AddInstName("specific_impl_fn");
  943. }
  944. return;
  945. }
  946. case ReturnSlot::Kind: {
  947. AddInstNameId(NameId::ReturnSlot);
  948. return;
  949. }
  950. case CARBON_KIND(SpliceBlock inst): {
  951. PushBlockId(scope_id_, inst.block_id);
  952. AddInstName("");
  953. return;
  954. }
  955. case StringLiteral::Kind: {
  956. AddInstName("str");
  957. return;
  958. }
  959. case CARBON_KIND(StructValue inst): {
  960. if (auto fn_ty = sem_ir().types().TryGetAs<FunctionType>(inst.type_id)) {
  961. AddEntityNameAndMaybePush(fn_ty->function_id);
  962. } else if (auto class_ty =
  963. sem_ir().types().TryGetAs<ClassType>(inst.type_id)) {
  964. AddEntityNameAndMaybePush(class_ty->class_id, ".val");
  965. } else if (auto generic_class_ty =
  966. sem_ir().types().TryGetAs<GenericClassType>(
  967. inst.type_id)) {
  968. AddEntityNameAndMaybePush(generic_class_ty->class_id, ".generic");
  969. } else if (auto generic_interface_ty =
  970. sem_ir().types().TryGetAs<GenericInterfaceType>(
  971. inst.type_id)) {
  972. AddInstNameId(sem_ir()
  973. .interfaces()
  974. .Get(generic_interface_ty->interface_id)
  975. .name_id,
  976. ".generic");
  977. } else {
  978. if (sem_ir().inst_blocks().Get(inst.elements_id).empty()) {
  979. AddInstName("empty_struct");
  980. } else {
  981. AddInstName("struct");
  982. }
  983. }
  984. return;
  985. }
  986. case CARBON_KIND(StructType inst): {
  987. const auto& fields = sem_ir().struct_type_fields().Get(inst.fields_id);
  988. if (fields.empty()) {
  989. AddInstName("empty_struct_type");
  990. return;
  991. }
  992. std::string name = "struct_type";
  993. for (auto field : fields) {
  994. name += ".";
  995. name += sem_ir().names().GetIRBaseName(field.name_id).str();
  996. }
  997. AddInstName(std::move(name));
  998. return;
  999. }
  1000. case CARBON_KIND(TupleAccess inst): {
  1001. RawStringOstream out;
  1002. out << "tuple.elem" << inst.index.index;
  1003. AddInstName(out.TakeStr());
  1004. return;
  1005. }
  1006. case CARBON_KIND(TupleType inst): {
  1007. if (inst.type_elements_id == InstBlockId::Empty) {
  1008. AddInstName("empty_tuple.type");
  1009. } else {
  1010. AddInstName("tuple.type");
  1011. }
  1012. return;
  1013. }
  1014. case CARBON_KIND(TupleValue inst): {
  1015. if (sem_ir().types().Is<ArrayType>(inst.type_id)) {
  1016. AddInstName("array");
  1017. } else if (inst.elements_id == InstBlockId::Empty) {
  1018. AddInstName("empty_tuple");
  1019. } else {
  1020. AddInstName("tuple");
  1021. }
  1022. return;
  1023. }
  1024. case CARBON_KIND(UnboundElementType inst): {
  1025. if (auto class_ty =
  1026. sem_ir().insts().TryGetAs<ClassType>(inst.class_type_inst_id)) {
  1027. AddEntityNameAndMaybePush(class_ty->class_id, ".elem");
  1028. } else {
  1029. AddInstName("elem_type");
  1030. }
  1031. return;
  1032. }
  1033. case VarPattern::Kind: {
  1034. AddInstNameId(GetPrettyNameFromPatternId(sem_ir(), inst_id_),
  1035. ".var_patt");
  1036. return;
  1037. }
  1038. case CARBON_KIND(VarStorage inst): {
  1039. if (inst.pattern_id.has_value()) {
  1040. AddInstNameId(GetPrettyNameFromPatternId(sem_ir(), inst.pattern_id),
  1041. ".var");
  1042. } else {
  1043. AddInstName("var");
  1044. }
  1045. return;
  1046. }
  1047. default: {
  1048. // Sequentially number all remaining values.
  1049. if (inst_.kind().has_type()) {
  1050. AddInstName("");
  1051. }
  1052. return;
  1053. }
  1054. }
  1055. }
  1056. } // namespace Carbon::SemIR