context.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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_CHECK_CONTEXT_H_
  5. #define CARBON_TOOLCHAIN_CHECK_CONTEXT_H_
  6. #include "llvm/ADT/DenseMap.h"
  7. #include "llvm/ADT/DenseSet.h"
  8. #include "llvm/ADT/FoldingSet.h"
  9. #include "llvm/ADT/SmallVector.h"
  10. #include "toolchain/check/decl_name_stack.h"
  11. #include "toolchain/check/decl_state.h"
  12. #include "toolchain/check/inst_block_stack.h"
  13. #include "toolchain/check/node_stack.h"
  14. #include "toolchain/parse/tree.h"
  15. #include "toolchain/parse/tree_node_location_translator.h"
  16. #include "toolchain/sem_ir/file.h"
  17. #include "toolchain/sem_ir/ids.h"
  18. #include "toolchain/sem_ir/inst.h"
  19. namespace Carbon::Check {
  20. // Context and shared functionality for semantics handlers.
  21. class Context {
  22. public:
  23. using DiagnosticEmitter = Carbon::DiagnosticEmitter<Parse::NodeLocation>;
  24. using DiagnosticBuilder = DiagnosticEmitter::DiagnosticBuilder;
  25. // A scope in which `break` and `continue` can be used.
  26. struct BreakContinueScope {
  27. SemIR::InstBlockId break_target;
  28. SemIR::InstBlockId continue_target;
  29. };
  30. // A scope in which `return` can be used.
  31. struct ReturnScope {
  32. // The declaration from which we can return. Inside a function, this will
  33. // be a `FunctionDecl`.
  34. SemIR::InstId decl_id;
  35. // The value corresponding to the current `returned var`, if any. Will be
  36. // set and unset as `returned var`s are declared and go out of scope.
  37. SemIR::InstId returned_var = SemIR::InstId::Invalid;
  38. };
  39. // Stores references for work.
  40. explicit Context(const Lex::TokenizedBuffer& tokens,
  41. DiagnosticEmitter& emitter, const Parse::Tree& parse_tree,
  42. SemIR::File& sem_ir, llvm::raw_ostream* vlog_stream);
  43. // Marks an implementation TODO. Always returns false.
  44. auto TODO(Parse::NodeId parse_node, std::string label) -> bool;
  45. // Runs verification that the processing cleanly finished.
  46. auto VerifyOnFinish() -> void;
  47. // Adds an instruction to the current block, returning the produced ID.
  48. auto AddInst(SemIR::Inst inst) -> SemIR::InstId;
  49. // Adds an instruction to the constants block, returning the produced ID.
  50. auto AddConstantInst(SemIR::Inst inst) -> SemIR::InstId;
  51. // Pushes a parse tree node onto the stack, storing the SemIR::Inst as the
  52. // result.
  53. auto AddInstAndPush(Parse::NodeId parse_node, SemIR::Inst inst) -> void;
  54. // Adds a package's imports to name lookup, with all libraries together.
  55. // sem_irs will all be non-null; has_load_error must be used for any errors.
  56. auto AddPackageImports(Parse::NodeId import_node, IdentifierId package_id,
  57. llvm::ArrayRef<const SemIR::File*> sem_irs,
  58. bool has_load_error) -> void;
  59. // Adds a name to name lookup. Prints a diagnostic for name conflicts.
  60. auto AddNameToLookup(Parse::NodeId name_node, SemIR::NameId name_id,
  61. SemIR::InstId target_id) -> void;
  62. // Performs name lookup in a specified scope for a name appearing in a
  63. // declaration, returning the referenced instruction. If scope_id is invalid,
  64. // uses the current contextual scope.
  65. auto LookupNameInDecl(Parse::NodeId parse_node, SemIR::NameId name_id,
  66. SemIR::NameScopeId scope_id) -> SemIR::InstId;
  67. // Performs an unqualified name lookup, returning the referenced instruction.
  68. auto LookupUnqualifiedName(Parse::NodeId parse_node, SemIR::NameId name_id)
  69. -> SemIR::InstId;
  70. // Performs a qualified name lookup in a specified scope and in scopes that
  71. // it extends, returning the referenced instruction.
  72. auto LookupQualifiedName(Parse::NodeId parse_node, SemIR::NameId name_id,
  73. SemIR::NameScopeId scope_id, bool required = true)
  74. -> SemIR::InstId;
  75. // Prints a diagnostic for a duplicate name.
  76. auto DiagnoseDuplicateName(Parse::NodeId parse_node,
  77. SemIR::InstId prev_def_id) -> void;
  78. // Prints a diagnostic for a missing name.
  79. auto DiagnoseNameNotFound(Parse::NodeId parse_node, SemIR::NameId name_id)
  80. -> void;
  81. // Adds a note to a diagnostic explaining that a class is incomplete.
  82. auto NoteIncompleteClass(SemIR::ClassId class_id, DiagnosticBuilder& builder)
  83. -> void;
  84. // Pushes a scope onto scope_stack_. NameScopeId::Invalid is used for new
  85. // scopes. name_lookup_has_load_error is used to limit diagnostics when a
  86. // given namespace may contain a mix of both successful and failed name
  87. // imports.
  88. auto PushScope(SemIR::InstId scope_inst_id = SemIR::InstId::Invalid,
  89. SemIR::NameScopeId scope_id = SemIR::NameScopeId::Invalid,
  90. bool name_lookup_has_load_error = false) -> void;
  91. // Pops the top scope from scope_stack_, cleaning up names from name_lookup_.
  92. auto PopScope() -> void;
  93. // Pops scopes until we return to the specified scope index.
  94. auto PopToScope(ScopeIndex index) -> void;
  95. // Returns the scope index associated with the current scope.
  96. auto current_scope_index() const -> ScopeIndex {
  97. return current_scope().index;
  98. }
  99. // Returns the name scope associated with the current lexical scope, if any.
  100. auto current_scope_id() const -> SemIR::NameScopeId {
  101. return current_scope().scope_id;
  102. }
  103. // Returns true if currently at file scope.
  104. auto at_file_scope() const -> bool { return scope_stack_.size() == 1; }
  105. // Returns true if the current scope is of the specified kind.
  106. template <typename InstT>
  107. auto CurrentScopeIs() -> bool {
  108. auto current_scope_inst_id = current_scope().scope_inst_id;
  109. if (!current_scope_inst_id.is_valid()) {
  110. return false;
  111. }
  112. return sem_ir_->insts().Get(current_scope_inst_id).kind() == InstT::Kind;
  113. }
  114. // Returns the current scope, if it is of the specified kind. Otherwise,
  115. // returns nullopt.
  116. template <typename InstT>
  117. auto GetCurrentScopeAs() -> std::optional<InstT> {
  118. auto current_scope_inst_id = current_scope().scope_inst_id;
  119. if (!current_scope_inst_id.is_valid()) {
  120. return std::nullopt;
  121. }
  122. return insts().Get(current_scope_inst_id).TryAs<InstT>();
  123. }
  124. // If there is no `returned var` in scope, sets the given instruction to be
  125. // the current `returned var` and returns an invalid instruction ID. If there
  126. // is already a `returned var`, returns it instead.
  127. auto SetReturnedVarOrGetExisting(SemIR::InstId inst_id) -> SemIR::InstId;
  128. // Follows NameRef instructions to find the value named by a given
  129. // instruction.
  130. auto FollowNameRefs(SemIR::InstId inst_id) -> SemIR::InstId;
  131. // Gets the constant value of the given instruction, if it has one.
  132. auto GetConstantValue(SemIR::InstId inst_id) -> SemIR::InstId;
  133. // Adds a `Branch` instruction branching to a new instruction block, and
  134. // returns the ID of the new block. All paths to the branch target must go
  135. // through the current block, though not necessarily through this branch.
  136. auto AddDominatedBlockAndBranch(Parse::NodeId parse_node)
  137. -> SemIR::InstBlockId;
  138. // Adds a `Branch` instruction branching to a new instruction block with a
  139. // value, and returns the ID of the new block. All paths to the branch target
  140. // must go through the current block.
  141. auto AddDominatedBlockAndBranchWithArg(Parse::NodeId parse_node,
  142. SemIR::InstId arg_id)
  143. -> SemIR::InstBlockId;
  144. // Adds a `BranchIf` instruction branching to a new instruction block, and
  145. // returns the ID of the new block. All paths to the branch target must go
  146. // through the current block.
  147. auto AddDominatedBlockAndBranchIf(Parse::NodeId parse_node,
  148. SemIR::InstId cond_id)
  149. -> SemIR::InstBlockId;
  150. // Handles recovergence of control flow. Adds branches from the top
  151. // `num_blocks` on the instruction block stack to a new block, pops the
  152. // existing blocks, and pushes the new block onto the instruction block stack.
  153. auto AddConvergenceBlockAndPush(Parse::NodeId parse_node, int num_blocks)
  154. -> void;
  155. // Handles recovergence of control flow with a result value. Adds branches
  156. // from the top few blocks on the instruction block stack to a new block, pops
  157. // the existing blocks, and pushes the new block onto the instruction block
  158. // stack. The number of blocks popped is the size of `block_args`, and the
  159. // corresponding result values are the elements of `block_args`. Returns an
  160. // instruction referring to the result value.
  161. auto AddConvergenceBlockWithArgAndPush(
  162. Parse::NodeId parse_node, std::initializer_list<SemIR::InstId> block_args)
  163. -> SemIR::InstId;
  164. // Add the current code block to the enclosing function.
  165. // TODO: The parse_node is taken for expressions, which can occur in
  166. // non-function contexts. This should be refactored to support non-function
  167. // contexts, and parse_node removed.
  168. auto AddCurrentCodeBlockToFunction(
  169. Parse::NodeId parse_node = Parse::NodeId::Invalid) -> void;
  170. // Returns whether the current position in the current block is reachable.
  171. auto is_current_position_reachable() -> bool;
  172. // Canonicalizes a type which is tracked as a single instruction.
  173. auto CanonicalizeType(SemIR::InstId inst_id) -> SemIR::TypeId;
  174. // Handles canonicalization of struct types. This may create a new struct type
  175. // when it has a new structure, or reference an existing struct type when it
  176. // duplicates a prior type.
  177. //
  178. // Individual struct type fields aren't canonicalized because they may have
  179. // name conflicts or other diagnostics during creation, which can use the
  180. // parse node.
  181. auto CanonicalizeStructType(Parse::NodeId parse_node,
  182. SemIR::InstBlockId refs_id) -> SemIR::TypeId;
  183. // Handles canonicalization of tuple types. This may create a new tuple type
  184. // if the `type_ids` doesn't match an existing tuple type.
  185. auto CanonicalizeTupleType(Parse::NodeId parse_node,
  186. llvm::ArrayRef<SemIR::TypeId> type_ids)
  187. -> SemIR::TypeId;
  188. // Attempts to complete the type `type_id`. Returns `true` if the type is
  189. // complete, or `false` if it could not be completed. A complete type has
  190. // known object and value representations.
  191. //
  192. // If the type is not complete, `diagnoser` is invoked to diagnose the issue,
  193. // if a `diagnoser` is provided. The builder it returns will be annotated to
  194. // describe the reason why the type is not complete.
  195. auto TryToCompleteType(
  196. SemIR::TypeId type_id,
  197. std::optional<llvm::function_ref<auto()->DiagnosticBuilder>> diagnoser =
  198. std::nullopt) -> bool;
  199. // Returns the type `type_id` as a complete type, or produces an incomplete
  200. // type error and returns an error type. This is a convenience wrapper around
  201. // TryToCompleteType.
  202. auto AsCompleteType(SemIR::TypeId type_id,
  203. llvm::function_ref<auto()->DiagnosticBuilder> diagnoser)
  204. -> SemIR::TypeId {
  205. return TryToCompleteType(type_id, diagnoser) ? type_id
  206. : SemIR::TypeId::Error;
  207. }
  208. // Gets a builtin type. The returned type will be complete.
  209. auto GetBuiltinType(SemIR::BuiltinKind kind) -> SemIR::TypeId;
  210. // Returns a pointer type whose pointee type is `pointee_type_id`.
  211. auto GetPointerType(Parse::NodeId parse_node, SemIR::TypeId pointee_type_id)
  212. -> SemIR::TypeId;
  213. // Removes any top-level `const` qualifiers from a type.
  214. auto GetUnqualifiedType(SemIR::TypeId type_id) -> SemIR::TypeId;
  215. // Starts handling parameters or arguments.
  216. auto ParamOrArgStart() -> void;
  217. // On a comma, pushes the entry. On return, the top of node_stack_ will be
  218. // start_kind.
  219. auto ParamOrArgComma() -> void;
  220. // Detects whether there's an entry to push from the end of a parameter or
  221. // argument list, and if so, moves it to the current parameter or argument
  222. // list. Does not pop the list. `start_kind` is the node kind at the start
  223. // of the parameter or argument list, and will be at the top of the parse node
  224. // stack when this function returns.
  225. auto ParamOrArgEndNoPop(Parse::NodeKind start_kind) -> void;
  226. // Pops the current parameter or argument list. Should only be called after
  227. // `ParamOrArgEndNoPop`.
  228. auto ParamOrArgPop() -> SemIR::InstBlockId;
  229. // Detects whether there's an entry to push. Pops and returns the argument
  230. // list. This is the same as `ParamOrArgEndNoPop` followed by `ParamOrArgPop`.
  231. auto ParamOrArgEnd(Parse::NodeKind start_kind) -> SemIR::InstBlockId;
  232. // Saves a parameter from the top block in node_stack_ to the top block in
  233. // params_or_args_stack_.
  234. auto ParamOrArgSave(SemIR::InstId inst_id) -> void {
  235. params_or_args_stack_.AddInstId(inst_id);
  236. }
  237. // Prints information for a stack dump.
  238. auto PrintForStackDump(llvm::raw_ostream& output) const -> void;
  239. // Get the Lex::TokenKind of a node for diagnostics.
  240. auto token_kind(Parse::NodeId parse_node) -> Lex::TokenKind {
  241. return tokens().GetKind(parse_tree().node_token(parse_node));
  242. }
  243. auto tokens() -> const Lex::TokenizedBuffer& { return *tokens_; }
  244. auto emitter() -> DiagnosticEmitter& { return *emitter_; }
  245. auto parse_tree() -> const Parse::Tree& { return *parse_tree_; }
  246. auto sem_ir() -> SemIR::File& { return *sem_ir_; }
  247. auto node_stack() -> NodeStack& { return node_stack_; }
  248. auto inst_block_stack() -> InstBlockStack& { return inst_block_stack_; }
  249. auto params_or_args_stack() -> InstBlockStack& {
  250. return params_or_args_stack_;
  251. }
  252. auto args_type_info_stack() -> InstBlockStack& {
  253. return args_type_info_stack_;
  254. }
  255. auto return_scope_stack() -> llvm::SmallVector<ReturnScope>& {
  256. return return_scope_stack_;
  257. }
  258. auto break_continue_stack() -> llvm::SmallVector<BreakContinueScope>& {
  259. return break_continue_stack_;
  260. }
  261. auto decl_name_stack() -> DeclNameStack& { return decl_name_stack_; }
  262. auto decl_state_stack() -> DeclStateStack& { return decl_state_stack_; }
  263. // Directly expose SemIR::File data accessors for brevity in calls.
  264. auto identifiers() -> StringStoreWrapper<IdentifierId>& {
  265. return sem_ir().identifiers();
  266. }
  267. auto ints() -> ValueStore<IntId>& { return sem_ir().ints(); }
  268. auto reals() -> ValueStore<RealId>& { return sem_ir().reals(); }
  269. auto string_literals() -> StringStoreWrapper<StringLiteralId>& {
  270. return sem_ir().string_literals();
  271. }
  272. auto functions() -> ValueStore<SemIR::FunctionId>& {
  273. return sem_ir().functions();
  274. }
  275. auto classes() -> ValueStore<SemIR::ClassId>& { return sem_ir().classes(); }
  276. auto interfaces() -> ValueStore<SemIR::InterfaceId>& {
  277. return sem_ir().interfaces();
  278. }
  279. auto cross_ref_irs() -> ValueStore<SemIR::CrossRefIRId>& {
  280. return sem_ir().cross_ref_irs();
  281. }
  282. auto names() -> SemIR::NameStoreWrapper { return sem_ir().names(); }
  283. auto name_scopes() -> SemIR::NameScopeStore& {
  284. return sem_ir().name_scopes();
  285. }
  286. auto types() -> SemIR::TypeStore& { return sem_ir().types(); }
  287. auto type_blocks() -> SemIR::BlockValueStore<SemIR::TypeBlockId>& {
  288. return sem_ir().type_blocks();
  289. }
  290. auto insts() -> SemIR::InstStore& { return sem_ir().insts(); }
  291. auto inst_blocks() -> SemIR::InstBlockStore& {
  292. return sem_ir().inst_blocks();
  293. }
  294. auto constants() -> SemIR::ConstantStore& { return sem_ir().constants(); }
  295. private:
  296. // A FoldingSet node for a type.
  297. class TypeNode : public llvm::FastFoldingSetNode {
  298. public:
  299. explicit TypeNode(const llvm::FoldingSetNodeID& node_id,
  300. SemIR::TypeId type_id)
  301. : llvm::FastFoldingSetNode(node_id), type_id_(type_id) {}
  302. auto type_id() -> SemIR::TypeId { return type_id_; }
  303. private:
  304. SemIR::TypeId type_id_;
  305. };
  306. // An entry in scope_stack_.
  307. struct ScopeStackEntry {
  308. // The sequential index of this scope entry within the file.
  309. ScopeIndex index;
  310. // The instruction associated with this entry, if any. This can be one of:
  311. //
  312. // - A `ClassDecl`, for a class definition scope.
  313. // - A `FunctionDecl`, for the outermost scope in a function
  314. // definition.
  315. // - Invalid, for any other scope.
  316. SemIR::InstId scope_inst_id;
  317. // The name scope associated with this entry, if any.
  318. SemIR::NameScopeId scope_id;
  319. // The previous state of name_lookup_has_load_error_, restored on pop.
  320. bool prev_name_lookup_has_load_error;
  321. // Names which are registered with name_lookup_, and will need to be
  322. // unregistered when the scope ends.
  323. llvm::DenseSet<SemIR::NameId> names;
  324. // Whether a `returned var` was introduced in this scope, and needs to be
  325. // unregistered when the scope ends.
  326. bool has_returned_var = false;
  327. // TODO: This likely needs to track things which need to be destructed.
  328. };
  329. // A lookup result in the lexical lookup table `name_lookup_`.
  330. struct LexicalLookupResult {
  331. // The instruction that was added to lookup.
  332. SemIR::InstId inst_id;
  333. // The scope in which the instruction was added.
  334. ScopeIndex scope_index;
  335. };
  336. // Forms a canonical type ID for a type. This function is given two
  337. // callbacks:
  338. //
  339. // `profile_type(canonical_id)` is called to build a fingerprint for this
  340. // type. The ID should be distinct for all distinct type values with the same
  341. // `kind`.
  342. //
  343. // `make_inst()` is called to obtain a `SemIR::InstId` that describes the
  344. // type. It is only called if the type does not already exist, so can be used
  345. // to lazily build the `SemIR::Inst`. `make_inst()` is not permitted to
  346. // directly or indirectly canonicalize any types.
  347. auto CanonicalizeTypeImpl(
  348. SemIR::InstKind kind,
  349. llvm::function_ref<bool(llvm::FoldingSetNodeID& canonical_id)>
  350. profile_type,
  351. llvm::function_ref<SemIR::InstId()> make_inst) -> SemIR::TypeId;
  352. // Forms a canonical type ID for a type. If the type is new, adds the
  353. // instruction to the current block.
  354. auto CanonicalizeTypeAndAddInstIfNew(SemIR::Inst inst) -> SemIR::TypeId;
  355. // If the passed in instruction ID is a LazyImportRef, resolves it for use.
  356. // Called when name lookup intends to return an inst_id.
  357. auto ResolveIfLazyImportRef(SemIR::InstId inst_id) -> void;
  358. auto current_scope() -> ScopeStackEntry& { return scope_stack_.back(); }
  359. auto current_scope() const -> const ScopeStackEntry& {
  360. return scope_stack_.back();
  361. }
  362. // Tokens for getting data on literals.
  363. const Lex::TokenizedBuffer* tokens_;
  364. // Handles diagnostics.
  365. DiagnosticEmitter* emitter_;
  366. // The file's parse tree.
  367. const Parse::Tree* parse_tree_;
  368. // The SemIR::File being added to.
  369. SemIR::File* sem_ir_;
  370. // Whether to print verbose output.
  371. llvm::raw_ostream* vlog_stream_;
  372. // The stack during Build. Will contain file-level parse nodes on return.
  373. NodeStack node_stack_;
  374. // The stack of instruction blocks being used for general IR generation.
  375. InstBlockStack inst_block_stack_;
  376. // The stack of instruction blocks being used for per-element tracking of
  377. // instructions in parameter and argument instruction blocks. Versus
  378. // inst_block_stack_, an element will have 1 or more instructions in blocks in
  379. // inst_block_stack_, but only ever 1 instruction in blocks here.
  380. InstBlockStack params_or_args_stack_;
  381. // The stack of instruction blocks being used for type information while
  382. // processing arguments. This is used in parallel with params_or_args_stack_.
  383. // It's currently only used for struct literals, where we need to track names
  384. // for a type separate from the literal arguments.
  385. InstBlockStack args_type_info_stack_;
  386. // A stack of scopes from which we can `return`.
  387. llvm::SmallVector<ReturnScope> return_scope_stack_;
  388. // A stack of `break` and `continue` targets.
  389. llvm::SmallVector<BreakContinueScope> break_continue_stack_;
  390. // A stack for scope context.
  391. llvm::SmallVector<ScopeStackEntry> scope_stack_;
  392. // Information about non-lexical scopes. This is a subset of the entries and
  393. // the information in scope_stack_.
  394. llvm::SmallVector<std::pair<ScopeIndex, SemIR::NameScopeId>>
  395. non_lexical_scope_stack_;
  396. // The index of the next scope that will be pushed onto scope_stack_.
  397. ScopeIndex next_scope_index_ = ScopeIndex(0);
  398. // The stack used for qualified declaration name construction.
  399. DeclNameStack decl_name_stack_;
  400. // The stack of declarations that could have modifiers.
  401. DeclStateStack decl_state_stack_;
  402. // Maps identifiers to name lookup results. Values are a stack of name lookup
  403. // results in the ancestor scopes. This offers constant-time lookup of names,
  404. // regardless of how many scopes exist between the name declaration and
  405. // reference. The corresponding scope for each lookup result is tracked, so
  406. // that lexical lookup results can be interleaved with lookup results from
  407. // non-lexical scopes such as classes.
  408. //
  409. // Names which no longer have lookup results are erased.
  410. llvm::DenseMap<SemIR::NameId, llvm::SmallVector<LexicalLookupResult>>
  411. name_lookup_;
  412. // Whether name_lookup_ has load errors, updated whenever scope_stack_ is
  413. // pushed or popped.
  414. bool name_lookup_has_load_error_ = false;
  415. // Cache of the mapping from instructions to types, to avoid recomputing the
  416. // folding set ID.
  417. llvm::DenseMap<SemIR::InstId, SemIR::TypeId> canonical_types_;
  418. // Tracks the canonical representation of types that have been defined.
  419. llvm::FoldingSet<TypeNode> canonical_type_nodes_;
  420. // Storage for the nodes in canonical_type_nodes_. This stores in pointers so
  421. // that FoldingSet can have stable pointers.
  422. llvm::SmallVector<std::unique_ptr<TypeNode>> type_node_storage_;
  423. };
  424. // Parse node handlers. Returns false for unrecoverable errors.
  425. #define CARBON_PARSE_NODE_KIND(Name) \
  426. auto Handle##Name(Context& context, Parse::NodeId parse_node) -> bool;
  427. #include "toolchain/parse/node_kind.def"
  428. } // namespace Carbon::Check
  429. #endif // CARBON_TOOLCHAIN_CHECK_CONTEXT_H_