Implement syntactic merge checks for parameters. (#4149)

Note this isn't implementing checking through imports. The parse node
there is harder to access through the context, so would require
examining the entity in order to get the import declaration, to get at
the ImportIR. We also don't have a parse tree attached in that case, and
would need to add one to SemIR::File. But I believe we do want to add
that, so it's explicitly a TODO.

Note GetTokenText re-lexes literal values, so there's a bit of potential
overhead there. Not sure if we want a more efficient manner for
comparing in cases like this.
This commit is contained in:
Jon Ross-Perkins
2024-07-23 20:32:24 +00:00
committed by GitHub
parent 07c286e3cb
commit db022658c6
26 changed files with 2738 additions and 26 deletions
+6 -1
View File
@@ -99,7 +99,8 @@ static auto MergeFunctionRedecl(Context& context, SemIRLoc new_loc,
SemIR::ImportIRId prev_import_ir_id) -> bool {
auto& prev_function = context.functions().Get(prev_function_id);
if (!CheckFunctionTypeMatches(context, new_function, prev_function, {})) {
if (!CheckFunctionTypeMatches(context, new_function, prev_function, {},
/*check_syntax=*/true)) {
return false;
}
@@ -118,6 +119,8 @@ static auto MergeFunctionRedecl(Context& context, SemIRLoc new_loc,
// Track the signature from the definition, so that IDs in the body
// match IDs in the signature.
prev_function.definition_id = new_function.definition_id;
prev_function.first_param_node_id = new_function.first_param_node_id;
prev_function.last_param_node_id = new_function.last_param_node_id;
prev_function.implicit_param_refs_id = new_function.implicit_param_refs_id;
prev_function.param_refs_id = new_function.param_refs_id;
prev_function.return_storage_id = new_function.return_storage_id;
@@ -252,6 +255,8 @@ static auto BuildFunctionDecl(Context& context,
.parent_scope_id = name_context.parent_scope_id_for_new_inst(),
.decl_id = decl_id,
.generic_id = SemIR::GenericId::Invalid,
.first_param_node_id = name.first_param_node_id,
.last_param_node_id = name.last_param_node_id,
.implicit_param_refs_id = name.implicit_params_id,
.param_refs_id = name.params_id,
.return_storage_id = return_storage_id,