From 9e3c4a3ef1b9641132e653d404e98fcccda21a5f Mon Sep 17 00:00:00 2001 From: Jon Ross-Perkins Date: Thu, 18 Jan 2024 19:01:24 -0800 Subject: [PATCH] Reduce a few cases of retrieving the parse node for conditional diagnostics. (#3620) --- toolchain/check/convert.cpp | 14 ++++++-------- toolchain/check/convert.h | 3 +-- toolchain/check/handle_call_expr.cpp | 3 +-- toolchain/check/handle_function.cpp | 2 +- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/toolchain/check/convert.cpp b/toolchain/check/convert.cpp index 95ec14b06b5d..6109e1acbf12 100644 --- a/toolchain/check/convert.cpp +++ b/toolchain/check/convert.cpp @@ -1077,7 +1077,7 @@ CARBON_DIAGNOSTIC(InCallToFunction, Note, "Calling function declared here."); // Convert the object argument in a method call to match the `self` parameter. static auto ConvertSelf(Context& context, Parse::NodeId call_parse_node, - Parse::NodeId callee_parse_node, + SemIR::InstId callee_id, std::optional addr_pattern, SemIR::InstId self_param_id, SemIR::Param self_param, SemIR::InstId self_id) -> SemIR::InstId { @@ -1086,7 +1086,7 @@ static auto ConvertSelf(Context& context, Parse::NodeId call_parse_node, "Missing object argument in method call."); context.emitter() .Build(call_parse_node, MissingObjectInMethodCall) - .Note(callee_parse_node, InCallToFunction) + .Note(callee_id, InCallToFunction) .Emit(); return SemIR::InstId::BuiltinError; } @@ -1131,8 +1131,7 @@ static auto ConvertSelf(Context& context, Parse::NodeId call_parse_node, auto ConvertCallArgs(Context& context, Parse::NodeId call_parse_node, SemIR::InstId self_id, llvm::ArrayRef arg_refs, - SemIR::InstId return_storage_id, - Parse::NodeId callee_parse_node, + SemIR::InstId return_storage_id, SemIR::InstId callee_id, SemIR::InstBlockId implicit_param_refs_id, SemIR::InstBlockId param_refs_id) -> SemIR::InstBlockId { auto implicit_param_refs = @@ -1148,7 +1147,7 @@ auto ConvertCallArgs(Context& context, Parse::NodeId call_parse_node, context.emitter() .Build(call_parse_node, CallArgCountMismatch, arg_refs.size(), param_refs.size()) - .Note(callee_parse_node, InCallToFunction) + .Note(callee_id, InCallToFunction) .Emit(); return SemIR::InstBlockId::Invalid; } @@ -1166,7 +1165,7 @@ auto ConvertCallArgs(Context& context, Parse::NodeId call_parse_node, context.sem_ir(), implicit_param_id); if (param.name_id == SemIR::NameId::SelfValue) { auto converted_self_id = - ConvertSelf(context, call_parse_node, callee_parse_node, addr_pattern, + ConvertSelf(context, call_parse_node, callee_id, addr_pattern, param_id, param, self_id); if (converted_self_id == SemIR::InstId::BuiltinError) { return SemIR::InstBlockId::Invalid; @@ -1185,8 +1184,7 @@ auto ConvertCallArgs(Context& context, Parse::NodeId call_parse_node, CARBON_DIAGNOSTIC( InCallToFunctionParam, Note, "Initializing parameter {0} of function declared here.", int); - builder.Note(callee_parse_node, InCallToFunctionParam, - diag_param_index + 1); + builder.Note(callee_id, InCallToFunctionParam, diag_param_index + 1); }); // Check type conversions per-element. diff --git a/toolchain/check/convert.h b/toolchain/check/convert.h index bda956b50ff9..def08daae988 100644 --- a/toolchain/check/convert.h +++ b/toolchain/check/convert.h @@ -96,8 +96,7 @@ auto ConvertForExplicitAs(Context& context, Parse::NodeId as_node, auto ConvertCallArgs(Context& context, Parse::NodeId call_parse_node, SemIR::InstId self_id, llvm::ArrayRef arg_refs, - SemIR::InstId return_storage_id, - Parse::NodeId callee_parse_node, + SemIR::InstId return_storage_id, SemIR::InstId callee_id, SemIR::InstBlockId implicit_param_refs_id, SemIR::InstBlockId param_refs_id) -> SemIR::InstBlockId; diff --git a/toolchain/check/handle_call_expr.cpp b/toolchain/check/handle_call_expr.cpp index 37101007595b..c7c7dc826572 100644 --- a/toolchain/check/handle_call_expr.cpp +++ b/toolchain/check/handle_call_expr.cpp @@ -90,8 +90,7 @@ auto HandleCallExpr(Context& context, Parse::CallExprId parse_node) -> bool { auto converted_args_id = ConvertCallArgs(context, call_expr_parse_node, self_id, context.params_or_args_stack().PeekCurrentBlockContents(), - return_storage_id, - context.insts().GetParseNode(function_decl_id.inst_id()), + return_storage_id, function_decl_id.inst_id(), callable.implicit_param_refs_id, callable.param_refs_id); auto call_inst_id = context.AddInst({call_expr_parse_node, diff --git a/toolchain/check/handle_function.cpp b/toolchain/check/handle_function.cpp index e9570ecb1700..2f2410cc8a9d 100644 --- a/toolchain/check/handle_function.cpp +++ b/toolchain/check/handle_function.cpp @@ -258,7 +258,7 @@ auto HandleFunctionDefinitionStart(Context& context, "Parameter has incomplete type `{0}` in function definition.", std::string); return context.emitter().Build( - context.insts().GetParseNode(param_id), IncompleteTypeInFunctionParam, + param_id, IncompleteTypeInFunctionParam, context.sem_ir().StringifyType(param.type_id())); });