handle_function.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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/base/kind_switch.h"
  5. #include "toolchain/check/context.h"
  6. #include "toolchain/check/convert.h"
  7. #include "toolchain/check/decl_introducer_state.h"
  8. #include "toolchain/check/decl_name_stack.h"
  9. #include "toolchain/check/function.h"
  10. #include "toolchain/check/generic.h"
  11. #include "toolchain/check/handle.h"
  12. #include "toolchain/check/import_ref.h"
  13. #include "toolchain/check/interface.h"
  14. #include "toolchain/check/merge.h"
  15. #include "toolchain/check/modifiers.h"
  16. #include "toolchain/check/name_component.h"
  17. #include "toolchain/sem_ir/builtin_function_kind.h"
  18. #include "toolchain/sem_ir/entry_point.h"
  19. #include "toolchain/sem_ir/function.h"
  20. #include "toolchain/sem_ir/ids.h"
  21. #include "toolchain/sem_ir/typed_insts.h"
  22. namespace Carbon::Check {
  23. auto HandleParseNode(Context& context, Parse::FunctionIntroducerId node_id)
  24. -> bool {
  25. // Create an instruction block to hold the instructions created as part of the
  26. // function signature, such as parameter and return types.
  27. context.inst_block_stack().Push();
  28. // Push the bracketing node.
  29. context.node_stack().Push(node_id);
  30. // Optional modifiers and the name follow.
  31. context.decl_introducer_state_stack().Push<Lex::TokenKind::Fn>();
  32. context.decl_name_stack().PushScopeAndStartName();
  33. // The function is potentially generic.
  34. StartGenericDecl(context);
  35. // Start a new pattern block for the signature.
  36. context.pattern_block_stack().Push();
  37. return true;
  38. }
  39. auto HandleParseNode(Context& context, Parse::ReturnTypeId node_id) -> bool {
  40. // Propagate the type expression.
  41. auto [type_node_id, type_inst_id] = context.node_stack().PopExprWithNodeId();
  42. auto type_id = ExprAsType(context, type_node_id, type_inst_id).type_id;
  43. auto return_slot_id = context.AddPatternInst<SemIR::ReturnSlotPattern>(
  44. node_id, {.type_id = type_id, .type_inst_id = type_inst_id});
  45. auto param_pattern_id = context.AddPatternInst<SemIR::OutParamPattern>(
  46. node_id, {.type_id = type_id,
  47. .subpattern_id = return_slot_id,
  48. .runtime_index = SemIR::RuntimeParamIndex::Unknown});
  49. context.node_stack().Push(node_id, param_pattern_id);
  50. return true;
  51. }
  52. static auto DiagnoseModifiers(Context& context, DeclIntroducerState& introducer,
  53. bool is_definition,
  54. SemIR::InstId parent_scope_inst_id,
  55. std::optional<SemIR::Inst> parent_scope_inst)
  56. -> void {
  57. CheckAccessModifiersOnDecl(context, introducer, parent_scope_inst);
  58. LimitModifiersOnDecl(context, introducer,
  59. KeywordModifierSet::Access | KeywordModifierSet::Extern |
  60. KeywordModifierSet::Method |
  61. KeywordModifierSet::Interface);
  62. RestrictExternModifierOnDecl(context, introducer, parent_scope_inst,
  63. is_definition);
  64. CheckMethodModifiersOnFunction(context, introducer, parent_scope_inst_id,
  65. parent_scope_inst);
  66. RequireDefaultFinalOnlyInInterfaces(context, introducer, parent_scope_inst);
  67. }
  68. // Tries to merge new_function into prev_function_id. Since new_function won't
  69. // have a definition even if one is upcoming, set is_definition to indicate the
  70. // planned result.
  71. //
  72. // If merging is successful, returns true and may update the previous function.
  73. // Otherwise, returns false. Prints a diagnostic when appropriate.
  74. static auto MergeFunctionRedecl(Context& context, SemIRLoc new_loc,
  75. SemIR::Function& new_function,
  76. bool new_is_import, bool new_is_definition,
  77. SemIR::FunctionId prev_function_id,
  78. SemIR::ImportIRId prev_import_ir_id) -> bool {
  79. auto& prev_function = context.functions().Get(prev_function_id);
  80. if (!CheckFunctionTypeMatches(context, new_function, prev_function)) {
  81. return false;
  82. }
  83. CheckIsAllowedRedecl(context, Lex::TokenKind::Fn, prev_function.name_id,
  84. RedeclInfo(new_function, new_loc, new_is_definition),
  85. RedeclInfo(prev_function, prev_function.latest_decl_id(),
  86. prev_function.definition_id.is_valid()),
  87. prev_import_ir_id);
  88. if (!prev_function.first_owning_decl_id.is_valid()) {
  89. prev_function.first_owning_decl_id = new_function.first_owning_decl_id;
  90. }
  91. if (new_is_definition) {
  92. // Track the signature from the definition, so that IDs in the body
  93. // match IDs in the signature.
  94. prev_function.MergeDefinition(new_function);
  95. prev_function.return_slot_id = new_function.return_slot_id;
  96. }
  97. if ((prev_import_ir_id.is_valid() && !new_is_import)) {
  98. ReplacePrevInstForMerge(context, new_function.parent_scope_id,
  99. prev_function.name_id,
  100. new_function.first_owning_decl_id);
  101. }
  102. return true;
  103. }
  104. // Check whether this is a redeclaration, merging if needed.
  105. static auto TryMergeRedecl(Context& context, Parse::AnyFunctionDeclId node_id,
  106. SemIR::InstId prev_id,
  107. SemIR::FunctionDecl& function_decl,
  108. SemIR::Function& function_info, bool is_definition)
  109. -> void {
  110. if (!prev_id.is_valid()) {
  111. return;
  112. }
  113. auto prev_function_id = SemIR::FunctionId::Invalid;
  114. auto prev_import_ir_id = SemIR::ImportIRId::Invalid;
  115. CARBON_KIND_SWITCH(context.insts().Get(prev_id)) {
  116. case CARBON_KIND(SemIR::FunctionDecl function_decl): {
  117. prev_function_id = function_decl.function_id;
  118. break;
  119. }
  120. case SemIR::ImportRefLoaded::Kind: {
  121. auto import_ir_inst =
  122. GetCanonicalImportIRInst(context, &context.sem_ir(), prev_id);
  123. // Verify the decl so that things like aliases are name conflicts.
  124. const auto* import_ir =
  125. context.import_irs().Get(import_ir_inst.ir_id).sem_ir;
  126. if (!import_ir->insts().Is<SemIR::FunctionDecl>(import_ir_inst.inst_id)) {
  127. break;
  128. }
  129. // Use the type to get the ID.
  130. if (auto struct_value = context.insts().TryGetAs<SemIR::StructValue>(
  131. context.constant_values().GetConstantInstId(prev_id))) {
  132. if (auto function_type = context.types().TryGetAs<SemIR::FunctionType>(
  133. struct_value->type_id)) {
  134. prev_function_id = function_type->function_id;
  135. prev_import_ir_id = import_ir_inst.ir_id;
  136. }
  137. }
  138. break;
  139. }
  140. default:
  141. break;
  142. }
  143. if (!prev_function_id.is_valid()) {
  144. context.DiagnoseDuplicateName(function_info.latest_decl_id(), prev_id);
  145. return;
  146. }
  147. if (MergeFunctionRedecl(context, node_id, function_info,
  148. /*new_is_import=*/false, is_definition,
  149. prev_function_id, prev_import_ir_id)) {
  150. // When merging, use the existing function rather than adding a new one.
  151. function_decl.function_id = prev_function_id;
  152. }
  153. }
  154. // Build a FunctionDecl describing the signature of a function. This
  155. // handles the common logic shared by function declaration syntax and function
  156. // definition syntax.
  157. static auto BuildFunctionDecl(Context& context,
  158. Parse::AnyFunctionDeclId node_id,
  159. bool is_definition)
  160. -> std::pair<SemIR::FunctionId, SemIR::InstId> {
  161. auto return_slot_pattern_id = SemIR::InstId::Invalid;
  162. if (auto [return_node, maybe_return_slot_pattern_id] =
  163. context.node_stack().PopWithNodeIdIf<Parse::NodeKind::ReturnType>();
  164. maybe_return_slot_pattern_id) {
  165. return_slot_pattern_id = *maybe_return_slot_pattern_id;
  166. }
  167. auto name = PopNameComponent(context, return_slot_pattern_id);
  168. if (!name.param_patterns_id.is_valid()) {
  169. context.TODO(node_id, "function with positional parameters");
  170. name.param_patterns_id = SemIR::InstBlockId::Empty;
  171. }
  172. auto name_context = context.decl_name_stack().FinishName(name);
  173. context.node_stack()
  174. .PopAndDiscardSoloNodeId<Parse::NodeKind::FunctionIntroducer>();
  175. // Process modifiers.
  176. auto [parent_scope_inst_id, parent_scope_inst] =
  177. context.name_scopes().GetInstIfValid(name_context.parent_scope_id);
  178. auto introducer =
  179. context.decl_introducer_state_stack().Pop<Lex::TokenKind::Fn>();
  180. DiagnoseModifiers(context, introducer, is_definition, parent_scope_inst_id,
  181. parent_scope_inst);
  182. bool is_extern = introducer.modifier_set.HasAnyOf(KeywordModifierSet::Extern);
  183. auto virtual_modifier =
  184. introducer.modifier_set.ToEnum<SemIR::Function::VirtualModifier>()
  185. .Case(KeywordModifierSet::Virtual,
  186. SemIR::Function::VirtualModifier::Virtual)
  187. .Case(KeywordModifierSet::Abstract,
  188. SemIR::Function::VirtualModifier::Abstract)
  189. .Case(KeywordModifierSet::Impl,
  190. SemIR::Function::VirtualModifier::Impl)
  191. .Default(SemIR::Function::VirtualModifier::None);
  192. if (virtual_modifier != SemIR::Function::VirtualModifier::None &&
  193. parent_scope_inst) {
  194. if (auto class_decl = parent_scope_inst->TryAs<SemIR::ClassDecl>()) {
  195. auto& class_info = context.classes().Get(class_decl->class_id);
  196. if (virtual_modifier == SemIR::Function::VirtualModifier::Impl &&
  197. !class_info.base_id.is_valid()) {
  198. CARBON_DIAGNOSTIC(ImplWithoutBase, Error, "impl without base class");
  199. context.emitter().Build(node_id, ImplWithoutBase).Emit();
  200. }
  201. // TODO: If this is an `impl` function, check there's a matching base
  202. // function that's impl or virtual.
  203. class_info.is_dynamic = true;
  204. }
  205. }
  206. if (introducer.modifier_set.HasAnyOf(KeywordModifierSet::Interface)) {
  207. // TODO: Once we are saving the modifiers for a function, add check that
  208. // the function may only be defined if it is marked `default` or `final`.
  209. context.TODO(introducer.modifier_node_id(ModifierOrder::Decl),
  210. "interface modifier");
  211. }
  212. // Add the function declaration.
  213. auto decl_block_id = context.inst_block_stack().Pop();
  214. auto function_decl = SemIR::FunctionDecl{
  215. SemIR::TypeId::Invalid, SemIR::FunctionId::Invalid, decl_block_id};
  216. auto decl_id =
  217. context.AddPlaceholderInst(SemIR::LocIdAndInst(node_id, function_decl));
  218. // Build the function entity. This will be merged into an existing function if
  219. // there is one, or otherwise added to the function store.
  220. auto function_info =
  221. SemIR::Function{{name_context.MakeEntityWithParamsBase(
  222. name, decl_id, is_extern, introducer.extern_library)},
  223. {.return_slot_pattern_id = name.return_slot_pattern_id,
  224. .return_slot_id = name.return_slot_id,
  225. .virtual_modifier = virtual_modifier}};
  226. if (is_definition) {
  227. function_info.definition_id = decl_id;
  228. }
  229. TryMergeRedecl(context, node_id, name_context.prev_inst_id(), function_decl,
  230. function_info, is_definition);
  231. // Create a new function if this isn't a valid redeclaration.
  232. if (!function_decl.function_id.is_valid()) {
  233. if (function_info.is_extern && context.IsImplFile()) {
  234. DiagnoseExternRequiresDeclInApiFile(context, node_id);
  235. }
  236. function_info.generic_id = FinishGenericDecl(context, decl_id);
  237. function_decl.function_id = context.functions().Add(function_info);
  238. } else {
  239. FinishGenericRedecl(context, decl_id, function_info.generic_id);
  240. // TODO: Validate that the redeclaration doesn't set an access modifier.
  241. }
  242. function_decl.type_id = context.GetFunctionType(
  243. function_decl.function_id, context.scope_stack().PeekSpecificId());
  244. // Write the function ID into the FunctionDecl.
  245. context.ReplaceInstBeforeConstantUse(decl_id, function_decl);
  246. // Diagnose 'definition of `abstract` function' using the canonical Function's
  247. // modifiers.
  248. if (is_definition &&
  249. context.functions().Get(function_decl.function_id).virtual_modifier ==
  250. SemIR::Function::VirtualModifier::Abstract) {
  251. CARBON_DIAGNOSTIC(DefinedAbstractFunction, Error,
  252. "definition of `abstract` function");
  253. context.emitter().Emit(TokenOnly(node_id), DefinedAbstractFunction);
  254. }
  255. // Check if we need to add this to name lookup, now that the function decl is
  256. // done.
  257. if (!name_context.prev_inst_id().is_valid()) {
  258. // At interface scope, a function declaration introduces an associated
  259. // function.
  260. auto lookup_result_id = decl_id;
  261. if (parent_scope_inst && !name_context.has_qualifiers) {
  262. if (auto interface_scope =
  263. parent_scope_inst->TryAs<SemIR::InterfaceDecl>()) {
  264. lookup_result_id = BuildAssociatedEntity(
  265. context, interface_scope->interface_id, decl_id);
  266. }
  267. }
  268. context.decl_name_stack().AddName(name_context, lookup_result_id,
  269. introducer.modifier_set.GetAccessKind());
  270. }
  271. if (SemIR::IsEntryPoint(context.sem_ir(), function_decl.function_id)) {
  272. auto return_type_id = function_info.GetDeclaredReturnType(context.sem_ir());
  273. // TODO: Update this once valid signatures for the entry point are decided.
  274. if (function_info.implicit_param_patterns_id.is_valid() ||
  275. !function_info.param_patterns_id.is_valid() ||
  276. !context.inst_blocks().Get(function_info.param_patterns_id).empty() ||
  277. (return_type_id.is_valid() &&
  278. return_type_id != context.GetInt32Type() &&
  279. return_type_id != context.GetTupleType({}))) {
  280. CARBON_DIAGNOSTIC(InvalidMainRunSignature, Error,
  281. "invalid signature for `Main.Run` function; expected "
  282. "`fn ()` or `fn () -> i32`");
  283. context.emitter().Emit(node_id, InvalidMainRunSignature);
  284. }
  285. }
  286. if (!is_definition && context.IsImplFile() && !is_extern) {
  287. context.definitions_required().push_back(decl_id);
  288. }
  289. return {function_decl.function_id, decl_id};
  290. }
  291. auto HandleParseNode(Context& context, Parse::FunctionDeclId node_id) -> bool {
  292. BuildFunctionDecl(context, node_id, /*is_definition=*/false);
  293. context.decl_name_stack().PopScope();
  294. return true;
  295. }
  296. // Processes a function definition after a signature for which we have already
  297. // built a function ID. This logic is shared between processing regular function
  298. // definitions and delayed parsing of inline method definitions.
  299. static auto HandleFunctionDefinitionAfterSignature(
  300. Context& context, Parse::FunctionDefinitionStartId node_id,
  301. SemIR::FunctionId function_id, SemIR::InstId decl_id) -> void {
  302. auto& function = context.functions().Get(function_id);
  303. // Create the function scope and the entry block.
  304. context.return_scope_stack().push_back({.decl_id = decl_id});
  305. context.inst_block_stack().Push();
  306. context.scope_stack().Push(decl_id);
  307. StartGenericDefinition(context);
  308. context.AddCurrentCodeBlockToFunction();
  309. // Check the return type is complete.
  310. CheckFunctionReturnType(context, function.return_slot_id, function,
  311. SemIR::SpecificId::Invalid);
  312. auto params_to_complete =
  313. context.inst_blocks().GetOrEmpty(function.call_params_id);
  314. if (function.return_slot_id.is_valid()) {
  315. // Exclude the return slot because it's diagnosed above.
  316. params_to_complete = params_to_complete.drop_back();
  317. }
  318. // Check the parameter types are complete.
  319. for (auto param_ref_id : params_to_complete) {
  320. if (param_ref_id == SemIR::InstId::BuiltinErrorInst) {
  321. continue;
  322. }
  323. // The parameter types need to be complete.
  324. context.TryToCompleteType(
  325. context.insts().GetAs<SemIR::AnyParam>(param_ref_id).type_id, [&] {
  326. CARBON_DIAGNOSTIC(
  327. IncompleteTypeInFunctionParam, Error,
  328. "parameter has incomplete type {0} in function definition",
  329. TypeOfInstId);
  330. return context.emitter().Build(
  331. param_ref_id, IncompleteTypeInFunctionParam, param_ref_id);
  332. });
  333. }
  334. context.node_stack().Push(node_id, function_id);
  335. }
  336. auto HandleFunctionDefinitionSuspend(Context& context,
  337. Parse::FunctionDefinitionStartId node_id)
  338. -> SuspendedFunction {
  339. // Process the declaration portion of the function.
  340. auto [function_id, decl_id] =
  341. BuildFunctionDecl(context, node_id, /*is_definition=*/true);
  342. return {.function_id = function_id,
  343. .decl_id = decl_id,
  344. .saved_name_state = context.decl_name_stack().Suspend()};
  345. }
  346. auto HandleFunctionDefinitionResume(Context& context,
  347. Parse::FunctionDefinitionStartId node_id,
  348. SuspendedFunction suspended_fn) -> void {
  349. context.decl_name_stack().Restore(suspended_fn.saved_name_state);
  350. HandleFunctionDefinitionAfterSignature(
  351. context, node_id, suspended_fn.function_id, suspended_fn.decl_id);
  352. }
  353. auto HandleParseNode(Context& context, Parse::FunctionDefinitionStartId node_id)
  354. -> bool {
  355. // Process the declaration portion of the function.
  356. auto [function_id, decl_id] =
  357. BuildFunctionDecl(context, node_id, /*is_definition=*/true);
  358. HandleFunctionDefinitionAfterSignature(context, node_id, function_id,
  359. decl_id);
  360. return true;
  361. }
  362. auto HandleParseNode(Context& context, Parse::FunctionDefinitionId node_id)
  363. -> bool {
  364. SemIR::FunctionId function_id =
  365. context.node_stack().Pop<Parse::NodeKind::FunctionDefinitionStart>();
  366. // If the `}` of the function is reachable, reject if we need a return value
  367. // and otherwise add an implicit `return;`.
  368. if (context.is_current_position_reachable()) {
  369. if (context.functions().Get(function_id).return_slot_id.is_valid()) {
  370. CARBON_DIAGNOSTIC(
  371. MissingReturnStatement, Error,
  372. "missing `return` at end of function with declared return type");
  373. context.emitter().Emit(TokenOnly(node_id), MissingReturnStatement);
  374. } else {
  375. context.AddInst<SemIR::Return>(node_id, {});
  376. }
  377. }
  378. context.scope_stack().Pop();
  379. context.inst_block_stack().Pop();
  380. context.return_scope_stack().pop_back();
  381. context.decl_name_stack().PopScope();
  382. // If this is a generic function, collect information about the definition.
  383. auto& function = context.functions().Get(function_id);
  384. FinishGenericDefinition(context, function.generic_id);
  385. return true;
  386. }
  387. auto HandleParseNode(Context& context,
  388. Parse::BuiltinFunctionDefinitionStartId node_id) -> bool {
  389. // Process the declaration portion of the function.
  390. auto [function_id, _] =
  391. BuildFunctionDecl(context, node_id, /*is_definition=*/true);
  392. context.node_stack().Push(node_id, function_id);
  393. return true;
  394. }
  395. auto HandleParseNode(Context& context, Parse::BuiltinNameId node_id) -> bool {
  396. context.node_stack().Push(node_id);
  397. return true;
  398. }
  399. // Looks up a builtin function kind given its name as a string.
  400. // TODO: Move this out to another file.
  401. static auto LookupBuiltinFunctionKind(Context& context,
  402. Parse::BuiltinNameId name_id)
  403. -> SemIR::BuiltinFunctionKind {
  404. auto builtin_name = context.string_literal_values().Get(
  405. context.tokens().GetStringLiteralValue(
  406. context.parse_tree().node_token(name_id)));
  407. auto kind = SemIR::BuiltinFunctionKind::ForBuiltinName(builtin_name);
  408. if (kind == SemIR::BuiltinFunctionKind::None) {
  409. CARBON_DIAGNOSTIC(UnknownBuiltinFunctionName, Error,
  410. "unknown builtin function name \"{0}\"", std::string);
  411. context.emitter().Emit(name_id, UnknownBuiltinFunctionName,
  412. builtin_name.str());
  413. }
  414. return kind;
  415. }
  416. // Returns whether `function` is a valid declaration of the builtin
  417. // `builtin_inst_kind`.
  418. static auto IsValidBuiltinDeclaration(Context& context,
  419. const SemIR::Function& function,
  420. SemIR::BuiltinFunctionKind builtin_kind)
  421. -> bool {
  422. // Form the list of parameter types for the declaration.
  423. llvm::SmallVector<SemIR::TypeId> param_type_ids;
  424. auto implicit_param_patterns =
  425. context.inst_blocks().GetOrEmpty(function.implicit_param_patterns_id);
  426. auto param_patterns =
  427. context.inst_blocks().GetOrEmpty(function.param_patterns_id);
  428. param_type_ids.reserve(implicit_param_patterns.size() +
  429. param_patterns.size());
  430. for (auto param_id : llvm::concat<const SemIR::InstId>(
  431. implicit_param_patterns, param_patterns)) {
  432. // TODO: We also need to track whether the parameter is declared with
  433. // `var`.
  434. param_type_ids.push_back(context.insts().Get(param_id).type_id());
  435. }
  436. // Get the return type. This is `()` if none was specified.
  437. auto return_type_id = function.GetDeclaredReturnType(context.sem_ir());
  438. if (!return_type_id.is_valid()) {
  439. return_type_id = context.GetTupleType({});
  440. }
  441. return builtin_kind.IsValidType(context.sem_ir(), param_type_ids,
  442. return_type_id);
  443. }
  444. auto HandleParseNode(Context& context,
  445. Parse::BuiltinFunctionDefinitionId /*node_id*/) -> bool {
  446. auto name_id =
  447. context.node_stack().PopForSoloNodeId<Parse::NodeKind::BuiltinName>();
  448. auto [fn_node_id, function_id] =
  449. context.node_stack()
  450. .PopWithNodeId<Parse::NodeKind::BuiltinFunctionDefinitionStart>();
  451. auto builtin_kind = LookupBuiltinFunctionKind(context, name_id);
  452. if (builtin_kind != SemIR::BuiltinFunctionKind::None) {
  453. auto& function = context.functions().Get(function_id);
  454. if (IsValidBuiltinDeclaration(context, function, builtin_kind)) {
  455. function.builtin_function_kind = builtin_kind;
  456. // Build an empty generic definition if this is a generic builtin.
  457. StartGenericDefinition(context);
  458. FinishGenericDefinition(context, function.generic_id);
  459. } else {
  460. CARBON_DIAGNOSTIC(InvalidBuiltinSignature, Error,
  461. "invalid signature for builtin function \"{0}\"",
  462. std::string);
  463. context.emitter().Emit(fn_node_id, InvalidBuiltinSignature,
  464. builtin_kind.name().str());
  465. }
  466. }
  467. context.decl_name_stack().PopScope();
  468. return true;
  469. }
  470. } // namespace Carbon::Check