-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Conversation
toolchain/check/handle_interface.cpp
Outdated
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()) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@@ -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()) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Rename
CheckIsAllowedRedecl
toDiagnoseIfInvalidRedecl
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 toextern
diagnostics, it's hard to combine.Cleans up
is_defined
calls to rely more onhas_definition_started
, removing some code paths that are unused since definitions aren't merged.