ids.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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. #ifndef CARBON_TOOLCHAIN_SEM_IR_IDS_H_
  5. #define CARBON_TOOLCHAIN_SEM_IR_IDS_H_
  6. #include "common/check.h"
  7. #include "common/ostream.h"
  8. #include "toolchain/base/index_base.h"
  9. #include "toolchain/base/value_store.h"
  10. #include "toolchain/diagnostics/diagnostic_emitter.h"
  11. #include "toolchain/parse/node_ids.h"
  12. #include "toolchain/sem_ir/builtin_kind.h"
  13. namespace Carbon::SemIR {
  14. // Forward declare indexed types, for integration with ValueStore.
  15. class File;
  16. class Inst;
  17. struct BindNameInfo;
  18. struct Class;
  19. struct Function;
  20. struct ImportIR;
  21. struct ImportIRInst;
  22. struct Interface;
  23. struct Impl;
  24. struct NameScope;
  25. struct TypeInfo;
  26. // The ID of an instruction.
  27. struct InstId : public IdBase, public Printable<InstId> {
  28. using ValueType = Inst;
  29. // An explicitly invalid ID.
  30. static const InstId Invalid;
  31. // Builtin instruction IDs.
  32. #define CARBON_SEM_IR_BUILTIN_KIND_NAME(Name) static const InstId Builtin##Name;
  33. #include "toolchain/sem_ir/builtin_kind.def"
  34. // The namespace for a `package` expression.
  35. static const InstId PackageNamespace;
  36. // Returns the instruction ID for a builtin. This relies on File guarantees
  37. // for builtin placement.
  38. static constexpr auto ForBuiltin(BuiltinKind kind) -> InstId {
  39. return InstId(kind.AsInt());
  40. }
  41. using IdBase::IdBase;
  42. // Returns true if the instruction is a builtin. Requires is_valid.
  43. auto is_builtin() const -> bool {
  44. CARBON_CHECK(is_valid());
  45. return index < BuiltinKind::ValidCount;
  46. }
  47. // Returns the BuiltinKind. Requires is_builtin.
  48. auto builtin_kind() const -> BuiltinKind {
  49. CARBON_CHECK(is_builtin());
  50. return BuiltinKind::FromInt(index);
  51. }
  52. auto Print(llvm::raw_ostream& out) const -> void {
  53. out << "inst";
  54. if (!is_valid()) {
  55. IdBase::Print(out);
  56. } else if (is_builtin()) {
  57. out << builtin_kind();
  58. } else {
  59. // Use the `+` as a small reminder that this is a delta, rather than an
  60. // absolute index.
  61. out << "+" << index - BuiltinKind::ValidCount;
  62. }
  63. }
  64. };
  65. constexpr InstId InstId::Invalid = InstId(InvalidIndex);
  66. #define CARBON_SEM_IR_BUILTIN_KIND_NAME(Name) \
  67. constexpr InstId InstId::Builtin##Name = \
  68. InstId::ForBuiltin(BuiltinKind::Name);
  69. #include "toolchain/sem_ir/builtin_kind.def"
  70. // The package namespace will be the instruction after builtins.
  71. constexpr InstId InstId::PackageNamespace = InstId(BuiltinKind::ValidCount);
  72. // The ID of a constant value of an expression. An expression is either:
  73. //
  74. // - a template constant, with an immediate value, such as `42` or `i32*` or
  75. // `("hello", "world")`, or
  76. // - a symbolic constant, whose value includes a symbolic parameter, such as
  77. // `Vector(T*)`, or
  78. // - a runtime expression, such as `Print("hello")`.
  79. struct ConstantId : public IdBase, public Printable<ConstantId> {
  80. // An ID for an expression that is not constant.
  81. static const ConstantId NotConstant;
  82. // An ID for an expression whose phase cannot be determined because it
  83. // contains an error. This is always modeled as a template constant.
  84. static const ConstantId Error;
  85. // An explicitly invalid ID.
  86. static const ConstantId Invalid;
  87. // Returns the constant ID corresponding to a template constant, which should
  88. // either be in the `constants` block in the file or should be known to be
  89. // unique.
  90. static constexpr auto ForTemplateConstant(InstId const_id) -> ConstantId {
  91. return ConstantId(const_id.index + IndexOffset);
  92. }
  93. // Returns the constant ID corresponding to a symbolic constant, which should
  94. // either be in the `constants` block in the file or should be known to be
  95. // unique.
  96. static constexpr auto ForSymbolicConstant(InstId const_id) -> ConstantId {
  97. return ConstantId(-const_id.index - IndexOffset);
  98. }
  99. using IdBase::IdBase;
  100. // Returns whether this represents a constant. Requires is_valid.
  101. auto is_constant() const -> bool {
  102. CARBON_CHECK(is_valid());
  103. return *this != ConstantId::NotConstant;
  104. }
  105. // Returns whether this represents a symbolic constant. Requires is_valid.
  106. auto is_symbolic() const -> bool {
  107. CARBON_CHECK(is_valid());
  108. return index <= -IndexOffset;
  109. }
  110. // Returns whether this represents a template constant. Requires is_valid.
  111. auto is_template() const -> bool {
  112. CARBON_CHECK(is_valid());
  113. return index >= IndexOffset;
  114. }
  115. // Returns the instruction that describes this constant value, or
  116. // InstId::Invalid for a runtime value. Requires is_valid.
  117. constexpr auto inst_id() const -> InstId {
  118. CARBON_CHECK(is_valid());
  119. return InstId(Abs(index) - IndexOffset);
  120. }
  121. auto Print(llvm::raw_ostream& out) const -> void {
  122. if (!is_valid()) {
  123. IdBase::Print(out);
  124. } else if (is_template()) {
  125. out << "template " << inst_id();
  126. } else if (is_symbolic()) {
  127. out << "symbolic " << inst_id();
  128. } else {
  129. out << "runtime";
  130. }
  131. }
  132. private:
  133. // TODO: C++23 makes std::abs constexpr, but until then we mirror std::abs
  134. // logic here. LLVM should still optimize this.
  135. static constexpr auto Abs(int32_t i) -> int32_t { return i > 0 ? i : -i; }
  136. static constexpr int32_t NotConstantIndex = InvalidIndex - 1;
  137. // The offset of InstId indices to ConstantId indices.
  138. static constexpr int32_t IndexOffset = -NotConstantIndex + 1;
  139. };
  140. constexpr ConstantId ConstantId::NotConstant = ConstantId(NotConstantIndex);
  141. static_assert(ConstantId::NotConstant.inst_id() == InstId::Invalid);
  142. constexpr ConstantId ConstantId::Error =
  143. ConstantId::ForTemplateConstant(InstId::BuiltinError);
  144. constexpr ConstantId ConstantId::Invalid = ConstantId(InvalidIndex);
  145. // The ID of a bind name.
  146. struct BindNameId : public IdBase, public Printable<BindNameId> {
  147. using ValueType = BindNameInfo;
  148. // An explicitly invalid ID.
  149. static const BindNameId Invalid;
  150. using IdBase::IdBase;
  151. auto Print(llvm::raw_ostream& out) const -> void {
  152. out << "bindName";
  153. IdBase::Print(out);
  154. }
  155. };
  156. constexpr BindNameId BindNameId::Invalid = BindNameId(InvalidIndex);
  157. // The index of a compile-time binding. This is the de Bruijn level for the
  158. // binding -- that is, this is the number of other compile time bindings whose
  159. // scope encloses this binding.
  160. struct CompileTimeBindIndex : public IndexBase,
  161. public Printable<CompileTimeBindIndex> {
  162. // An explicitly invalid index.
  163. static const CompileTimeBindIndex Invalid;
  164. using IndexBase::IndexBase;
  165. auto Print(llvm::raw_ostream& out) const -> void {
  166. out << "compTimeBind";
  167. IndexBase::Print(out);
  168. }
  169. };
  170. constexpr CompileTimeBindIndex CompileTimeBindIndex::Invalid =
  171. CompileTimeBindIndex(InvalidIndex);
  172. // The ID of a function.
  173. struct FunctionId : public IdBase, public Printable<FunctionId> {
  174. using ValueType = Function;
  175. // An explicitly invalid ID.
  176. static const FunctionId Invalid;
  177. using IdBase::IdBase;
  178. auto Print(llvm::raw_ostream& out) const -> void {
  179. out << "function";
  180. IdBase::Print(out);
  181. }
  182. };
  183. constexpr FunctionId FunctionId::Invalid = FunctionId(InvalidIndex);
  184. // The ID of an IR within the set of all IRs being evaluated in the current
  185. // check execution.
  186. struct CheckIRId : public IdBase, public Printable<CheckIRId> {
  187. using IdBase::IdBase;
  188. auto Print(llvm::raw_ostream& out) const -> void {
  189. out << "check_ir";
  190. IdBase::Print(out);
  191. }
  192. };
  193. // The ID of a class.
  194. struct ClassId : public IdBase, public Printable<ClassId> {
  195. using ValueType = Class;
  196. // An explicitly invalid ID.
  197. static const ClassId Invalid;
  198. using IdBase::IdBase;
  199. auto Print(llvm::raw_ostream& out) const -> void {
  200. out << "class";
  201. IdBase::Print(out);
  202. }
  203. };
  204. constexpr ClassId ClassId::Invalid = ClassId(InvalidIndex);
  205. // The ID of an interface.
  206. struct InterfaceId : public IdBase, public Printable<InterfaceId> {
  207. using ValueType = Interface;
  208. // An explicitly invalid ID.
  209. static const InterfaceId Invalid;
  210. using IdBase::IdBase;
  211. auto Print(llvm::raw_ostream& out) const -> void {
  212. out << "interface";
  213. IdBase::Print(out);
  214. }
  215. };
  216. constexpr InterfaceId InterfaceId::Invalid = InterfaceId(InvalidIndex);
  217. // The ID of an impl.
  218. struct ImplId : public IdBase, public Printable<ImplId> {
  219. using ValueType = Impl;
  220. // An explicitly invalid ID.
  221. static const ImplId Invalid;
  222. using IdBase::IdBase;
  223. auto Print(llvm::raw_ostream& out) const -> void {
  224. out << "impl";
  225. IdBase::Print(out);
  226. }
  227. };
  228. constexpr ImplId ImplId::Invalid = ImplId(InvalidIndex);
  229. // The ID of an IR within the set of imported IRs, both direct and indirect.
  230. struct ImportIRId : public IdBase, public Printable<ImportIRId> {
  231. using ValueType = ImportIR;
  232. // An explicitly invalid ID.
  233. static const ImportIRId Invalid;
  234. // The implicit `api` import, for an `impl` file. A null entry is added if
  235. // there is none, as in an `api`, in which case this ID should not show up in
  236. // instructions.
  237. static const ImportIRId ApiForImpl;
  238. using IdBase::IdBase;
  239. auto Print(llvm::raw_ostream& out) const -> void {
  240. out << "ir";
  241. IdBase::Print(out);
  242. }
  243. };
  244. constexpr ImportIRId ImportIRId::Invalid = ImportIRId(InvalidIndex);
  245. constexpr ImportIRId ImportIRId::ApiForImpl = ImportIRId(0);
  246. // A boolean value.
  247. struct BoolValue : public IdBase, public Printable<BoolValue> {
  248. static const BoolValue False;
  249. static const BoolValue True;
  250. // Returns the `BoolValue` corresponding to `b`.
  251. static constexpr auto From(bool b) -> BoolValue { return b ? True : False; }
  252. // Returns the `bool` corresponding to this `BoolValue`.
  253. constexpr auto ToBool() -> bool {
  254. CARBON_CHECK(*this == False || *this == True)
  255. << "Invalid bool value " << index;
  256. return *this != False;
  257. }
  258. using IdBase::IdBase;
  259. auto Print(llvm::raw_ostream& out) const -> void {
  260. if (*this == False) {
  261. out << "false";
  262. } else if (*this == True) {
  263. out << "true";
  264. } else {
  265. CARBON_FATAL() << "Invalid bool value " << index;
  266. }
  267. }
  268. };
  269. constexpr BoolValue BoolValue::False = BoolValue(0);
  270. constexpr BoolValue BoolValue::True = BoolValue(1);
  271. // An integer kind value -- either "signed" or "unsigned".
  272. //
  273. // This might eventually capture any other properties of an integer type that
  274. // affect its semantics, such as overflow behavior.
  275. struct IntKind : public IdBase, public Printable<IntKind> {
  276. static const IntKind Unsigned;
  277. static const IntKind Signed;
  278. using IdBase::IdBase;
  279. // Returns whether this type is signed.
  280. constexpr auto is_signed() -> bool { return *this == Signed; }
  281. auto Print(llvm::raw_ostream& out) const -> void {
  282. if (*this == Unsigned) {
  283. out << "unsigned";
  284. } else if (*this == Signed) {
  285. out << "signed";
  286. } else {
  287. CARBON_FATAL() << "Invalid int kind value " << index;
  288. }
  289. }
  290. };
  291. constexpr IntKind IntKind::Unsigned = IntKind(0);
  292. constexpr IntKind IntKind::Signed = IntKind(1);
  293. // A float kind value
  294. struct FloatKind : public IdBase, public Printable<FloatKind> {
  295. using IdBase::IdBase;
  296. auto Print(llvm::raw_ostream& out) const -> void { out << "float"; }
  297. };
  298. // The ID of a name. A name is either a string or a special name such as
  299. // `self`, `Self`, or `base`.
  300. struct NameId : public IdBase, public Printable<NameId> {
  301. // names().GetFormatted() is used for diagnostics.
  302. using DiagnosticType = DiagnosticTypeInfo<std::string>;
  303. // An explicitly invalid ID.
  304. static const NameId Invalid;
  305. // The name of `self`.
  306. static const NameId SelfValue;
  307. // The name of `Self`.
  308. static const NameId SelfType;
  309. // The name of the return slot in a function.
  310. static const NameId ReturnSlot;
  311. // The name of `package`.
  312. static const NameId PackageNamespace;
  313. // The name of `base`.
  314. static const NameId Base;
  315. // The number of non-index (<0) that exist, and will need storage in name
  316. // lookup.
  317. static const int NonIndexValueCount;
  318. // Returns the NameId corresponding to a particular IdentifierId.
  319. static auto ForIdentifier(IdentifierId id) -> NameId {
  320. if (id.index >= 0) {
  321. return NameId(id.index);
  322. } else if (!id.is_valid()) {
  323. return NameId::Invalid;
  324. } else {
  325. CARBON_FATAL() << "Unexpected identifier ID " << id;
  326. }
  327. }
  328. using IdBase::IdBase;
  329. // Returns the IdentifierId corresponding to this NameId, or an invalid
  330. // IdentifierId if this is a special name.
  331. auto AsIdentifierId() const -> IdentifierId {
  332. return index >= 0 ? IdentifierId(index) : IdentifierId::Invalid;
  333. }
  334. auto Print(llvm::raw_ostream& out) const -> void {
  335. out << "name";
  336. if (*this == SelfValue) {
  337. out << "SelfValue";
  338. } else if (*this == SelfType) {
  339. out << "SelfType";
  340. } else if (*this == ReturnSlot) {
  341. out << "ReturnSlot";
  342. } else if (*this == PackageNamespace) {
  343. out << "PackageNamespace";
  344. } else if (*this == Base) {
  345. out << "Base";
  346. } else {
  347. CARBON_CHECK(!is_valid() || index >= 0) << "Unknown index " << index;
  348. IdBase::Print(out);
  349. }
  350. }
  351. };
  352. constexpr NameId NameId::Invalid = NameId(InvalidIndex);
  353. constexpr NameId NameId::SelfValue = NameId(InvalidIndex - 1);
  354. constexpr NameId NameId::SelfType = NameId(InvalidIndex - 2);
  355. constexpr NameId NameId::ReturnSlot = NameId(InvalidIndex - 3);
  356. constexpr NameId NameId::PackageNamespace = NameId(InvalidIndex - 4);
  357. constexpr NameId NameId::Base = NameId(InvalidIndex - 5);
  358. constexpr int NameId::NonIndexValueCount = 6;
  359. // Enforce the link between SpecialValueCount and the last special value.
  360. static_assert(NameId::NonIndexValueCount == -NameId::Base.index);
  361. // The ID of a name scope.
  362. struct NameScopeId : public IdBase, public Printable<NameScopeId> {
  363. using ValueType = NameScope;
  364. // An explicitly invalid ID.
  365. static const NameScopeId Invalid;
  366. // The package (or file) name scope, guaranteed to be the first added.
  367. static const NameScopeId Package;
  368. using IdBase::IdBase;
  369. auto Print(llvm::raw_ostream& out) const -> void {
  370. out << "name_scope";
  371. IdBase::Print(out);
  372. }
  373. };
  374. constexpr NameScopeId NameScopeId::Invalid = NameScopeId(InvalidIndex);
  375. constexpr NameScopeId NameScopeId::Package = NameScopeId(0);
  376. // The ID of an instruction block.
  377. struct InstBlockId : public IdBase, public Printable<InstBlockId> {
  378. using ElementType = InstId;
  379. using ValueType = llvm::MutableArrayRef<ElementType>;
  380. // An empty block, reused to avoid allocating empty vectors. Always the
  381. // 0-index block.
  382. static const InstBlockId Empty;
  383. // Exported instructions. Always the 1-index block. Empty until the File is
  384. // fully checked; intermediate state is in the Check::Context.
  385. static const InstBlockId Exports;
  386. // Global declaration initialization instructions. Empty if none are present.
  387. // Otherwise, __global_init function will be generated and this block will
  388. // be inserted into it.
  389. static const InstBlockId GlobalInit;
  390. // An explicitly invalid ID.
  391. static const InstBlockId Invalid;
  392. // An ID for unreachable code.
  393. static const InstBlockId Unreachable;
  394. using IdBase::IdBase;
  395. auto Print(llvm::raw_ostream& out) const -> void {
  396. if (*this == Unreachable) {
  397. out << "unreachable";
  398. } else if (*this == Empty) {
  399. out << "empty";
  400. } else if (*this == Exports) {
  401. out << "exports";
  402. } else if (*this == GlobalInit) {
  403. out << "global_init";
  404. } else {
  405. out << "block";
  406. IdBase::Print(out);
  407. }
  408. }
  409. };
  410. constexpr InstBlockId InstBlockId::Empty = InstBlockId(0);
  411. constexpr InstBlockId InstBlockId::Exports = InstBlockId(1);
  412. constexpr InstBlockId InstBlockId::Invalid = InstBlockId(InvalidIndex);
  413. constexpr InstBlockId InstBlockId::Unreachable = InstBlockId(InvalidIndex - 1);
  414. constexpr InstBlockId InstBlockId::GlobalInit = InstBlockId(2);
  415. // The ID of a type.
  416. struct TypeId : public IdBase, public Printable<TypeId> {
  417. using ValueType = TypeInfo;
  418. // StringifyType() is used for diagnostics.
  419. using DiagnosticType = DiagnosticTypeInfo<std::string>;
  420. // The builtin TypeType.
  421. static const TypeId TypeType;
  422. // The builtin Error.
  423. static const TypeId Error;
  424. // An explicitly invalid ID.
  425. static const TypeId Invalid;
  426. using IdBase::IdBase;
  427. auto Print(llvm::raw_ostream& out) const -> void {
  428. out << "type";
  429. if (*this == TypeType) {
  430. out << "TypeType";
  431. } else if (*this == Error) {
  432. out << "Error";
  433. } else {
  434. IdBase::Print(out);
  435. }
  436. }
  437. };
  438. constexpr TypeId TypeId::TypeType = TypeId(InvalidIndex - 2);
  439. constexpr TypeId TypeId::Error = TypeId(InvalidIndex - 1);
  440. constexpr TypeId TypeId::Invalid = TypeId(InvalidIndex);
  441. // The ID of a type block.
  442. struct TypeBlockId : public IdBase, public Printable<TypeBlockId> {
  443. using ElementType = TypeId;
  444. using ValueType = llvm::MutableArrayRef<ElementType>;
  445. using IdBase::IdBase;
  446. auto Print(llvm::raw_ostream& out) const -> void {
  447. out << "typeBlock";
  448. IdBase::Print(out);
  449. }
  450. };
  451. // An index for element access, for structs, tuples, and classes.
  452. struct ElementIndex : public IndexBase, public Printable<ElementIndex> {
  453. using IndexBase::IndexBase;
  454. auto Print(llvm::raw_ostream& out) const -> void {
  455. out << "element";
  456. IndexBase::Print(out);
  457. }
  458. };
  459. // The ID of an ImportIRInst.
  460. struct ImportIRInstId : public IdBase, public Printable<InstId> {
  461. using ValueType = ImportIRInst;
  462. // An explicitly invalid ID.
  463. static const ImportIRInstId Invalid;
  464. using IdBase::IdBase;
  465. };
  466. constexpr ImportIRInstId ImportIRInstId::Invalid = ImportIRInstId(InvalidIndex);
  467. // A SemIR location used exclusively for diagnostic locations.
  468. //
  469. // Contents:
  470. // - index > Invalid: A Parse::NodeId in the current IR.
  471. // - index < Invalid: An ImportIRInstId.
  472. // - index == Invalid: Can be used for either.
  473. struct LocId : public IdBase, public Printable<LocId> {
  474. // An explicitly invalid ID.
  475. static const LocId Invalid;
  476. using IdBase::IdBase;
  477. // NOLINTNEXTLINE(google-explicit-constructor)
  478. constexpr LocId(Parse::InvalidNodeId /*invalid*/) : IdBase(InvalidIndex) {}
  479. // NOLINTNEXTLINE(google-explicit-constructor)
  480. constexpr LocId(Parse::NodeId node_id) : IdBase(node_id.index) {
  481. CARBON_CHECK(node_id.is_valid() == is_valid());
  482. }
  483. // NOLINTNEXTLINE(google-explicit-constructor)
  484. constexpr LocId(ImportIRInstId inst_id)
  485. : IdBase(InvalidIndex + ImportIRInstId::InvalidIndex - inst_id.index) {
  486. CARBON_CHECK(inst_id.is_valid() == is_valid());
  487. }
  488. auto is_node_id() const -> bool { return index > InvalidIndex; }
  489. auto is_import_ir_inst_id() const -> bool { return index < InvalidIndex; }
  490. // This is allowed to return an invalid NodeId, but should never be used for a
  491. // valid InstId.
  492. auto node_id() const -> Parse::NodeId {
  493. CARBON_CHECK(is_node_id() || !is_valid());
  494. return Parse::NodeId(index);
  495. }
  496. // This is allowed to return an invalid InstId, but should never be used for a
  497. // valid NodeId.
  498. auto import_ir_inst_id() const -> ImportIRInstId {
  499. CARBON_CHECK(is_import_ir_inst_id() || !is_valid());
  500. return ImportIRInstId(InvalidIndex + ImportIRInstId::InvalidIndex - index);
  501. }
  502. auto Print(llvm::raw_ostream& out) const -> void {
  503. out << "loc_";
  504. if (is_node_id() || !is_valid()) {
  505. out << node_id();
  506. } else {
  507. out << import_ir_inst_id();
  508. }
  509. }
  510. };
  511. constexpr LocId LocId::Invalid = LocId(Parse::NodeId::Invalid);
  512. } // namespace Carbon::SemIR
  513. // Support use of Id types as DenseMap/DenseSet keys.
  514. template <>
  515. struct llvm::DenseMapInfo<Carbon::SemIR::ConstantId>
  516. : public Carbon::IndexMapInfo<Carbon::SemIR::ConstantId> {};
  517. template <>
  518. struct llvm::DenseMapInfo<Carbon::SemIR::InstBlockId>
  519. : public Carbon::IndexMapInfo<Carbon::SemIR::InstBlockId> {};
  520. template <>
  521. struct llvm::DenseMapInfo<Carbon::SemIR::InstId>
  522. : public Carbon::IndexMapInfo<Carbon::SemIR::InstId> {};
  523. template <>
  524. struct llvm::DenseMapInfo<Carbon::SemIR::NameId>
  525. : public Carbon::IndexMapInfo<Carbon::SemIR::NameId> {};
  526. template <>
  527. struct llvm::DenseMapInfo<Carbon::SemIR::NameScopeId>
  528. : public Carbon::IndexMapInfo<Carbon::SemIR::NameScopeId> {};
  529. template <>
  530. struct llvm::DenseMapInfo<Carbon::SemIR::TypeId>
  531. : public Carbon::IndexMapInfo<Carbon::SemIR::TypeId> {};
  532. #endif // CARBON_TOOLCHAIN_SEM_IR_IDS_H_