Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor CheckIsAllowedRedecl and stop function definition merging #4800

Merged
merged 2 commits into from
Jan 14, 2025

Conversation

jonmeow
Copy link
Contributor

@jonmeow jonmeow commented Jan 14, 2025

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.

context, Lex::TokenKind::Interface, existing_interface.name_id,
RedeclInfo(interface_info, node_id, is_definition),
RedeclInfo(existing_interface, existing_interface.latest_decl_id(),
existing_interface.is_defined()),
/*prev_import_ir_id=*/SemIR::ImportIRId::Invalid);

// Can't merge interface definitions due to the generic requirements.
// TODO: Should this also be mirrored to classes/functions for generics?
if (!is_definition || !existing_interface.is_defined()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be using has_definition_started for consistency here (and a few lines above) too? I don't think it's possible to define an interface inside its own definition, but maybe that could happen during error recovery somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes much difference, but changed -- also, cleaned up some code paths that looked obsolete.

@zygoloid zygoloid enabled auto-merge January 14, 2025 20:30
@zygoloid zygoloid added this pull request to the merge queue Jan 14, 2025
Merged via the queue into carbon-language:trunk with commit d958caa Jan 14, 2025
8 checks passed
@@ -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()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have tests with two impl, class, function, interface definitions with the same signature?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See tests which mention "error: redefinition of"

But also, see the CHECK on line 446 here

@jonmeow jonmeow deleted the merge-redecl branch January 14, 2025 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants