Refactor CheckIsAllowedRedecl and stop function definition merging (#4800)

Rename `CheckIsAllowedRedecl` to `DiagnoseIfInvalidRedecl` to try to
better document behavior, and clean up comments.

This extends the no-merge-if-defined behavior to functions. It was
already the case for class/interface, and just added for impl, so if
anything functions were now inconsistent. I was kind of tempted to make
a helper for it, but I didn't think of a great structure/name to get
there: `DiagnoseRedef` isn't always called when it's a redefinition, for
example due to `extern` diagnostics, it's hard to combine.

Cleans up `is_defined` calls to rely more on `has_definition_started`,
removing some code paths that are unused since definitions aren't
merged.
This commit is contained in:
Jon Ross-Perkins
2025-01-14 21:13:21 +00:00
committed by GitHub
parent 5b70a3ea91
commit d958caaff3
15 changed files with 194 additions and 141 deletions
+4 -9
View File
@@ -453,10 +453,7 @@ auto HandleParseNode(Context& context, Parse::ImplDefinitionStartId node_id)
impl_decl_id, impl_info.scope_id,
context.generics().GetSelfSpecific(impl_info.generic_id));
StartGenericDefinition(context);
if (!impl_info.is_defined()) {
ImplWitnessStartDefinition(context, impl_info);
}
ImplWitnessStartDefinition(context, impl_info);
context.inst_block_stack().Push();
context.node_stack().Push(node_id, impl_id);
@@ -479,11 +476,9 @@ auto HandleParseNode(Context& context, Parse::ImplDefinitionId /*node_id*/)
context.node_stack().Pop<Parse::NodeKind::ImplDefinitionStart>();
auto& impl_info = context.impls().Get(impl_id);
if (!impl_info.is_defined()) {
FinishImplWitness(context, impl_info);
impl_info.defined = true;
}
CARBON_CHECK(!impl_info.is_defined());
FinishImplWitness(context, impl_info);
impl_info.defined = true;
FinishGenericDefinition(context, impl_info.generic_id);
context.inst_block_stack().Pop();