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

Require a definition in the same file as an impl declaration #4719

Merged
merged 4 commits into from
Dec 20, 2024

Conversation

josh11b
Copy link
Contributor

@josh11b josh11b commented Dec 19, 2024

This PR detects the failures that #4709 fixes.

Copy link
Contributor

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

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

LG, assuming the errors go away as expected when the other PR is merged.

auto& impl = context_.impls().Get(impl_decl.impl_id);
if (!impl.is_defined()) {
CARBON_DIAGNOSTIC(MissingImplDefinition, Error,
"no definition found for declaration of impl");
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe "impl declared but not defined"? I think we have previously said that we prefer diagnostics that state facts about the program rather than actions of the toolchain (eg, say the thing doesn't exist, not that we couldn't find it).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

}
auto facet_type = context.types().TryGetAs<SemIR::FacetType>(facet_type_id);
if (!facet_type) {
CARBON_DIAGNOSTIC(ImplAsNonFacetType, Error, "impl as non-facet-type");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
CARBON_DIAGNOSTIC(ImplAsNonFacetType, Error, "impl as non-facet-type");
CARBON_DIAGNOSTIC(ImplAsNonFacetType, Error, "impl as non-facet type");

Do you think it'd be useful to include the type facet_type_id in this diagnostic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used impl.constraint_id instead of facet_type_id so we can eventually use the source's spelling of that type.

@josh11b
Copy link
Contributor Author

josh11b commented Dec 20, 2024

I've synced and the four failing tests have been updated:

  • check/testdata/impl/declaration.carbon,
  • check/testdata/impl/redeclaration.carbon,
  • check/testdata/impl/no_prelude/import_generic.carbon,
  • check/testdata/impl/no_prelude/generic_redeclaration.carbon

I'll look at your suggestions tomorrow.

@josh11b josh11b added this pull request to the merge queue Dec 20, 2024
Merged via the queue into carbon-language:trunk with commit 5169a18 Dec 20, 2024
8 checks passed
@josh11b josh11b deleted the decl branch December 20, 2024 17:17
valid_redeclaration = IsValidImplRedecl(context, impl_info, prev_impl_id);
if (valid_redeclaration) {
impl_decl.impl_id = prev_impl_id;
}
break;
}
}

// Create a new impl if this isn't a valid redeclaration.
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW I am finding it hard to follow the logic in this change. Specifically:

  • There's now valid_redeclaration as a bool.
  • The comment here shows we check if we set the impl_decl.impl_id to something valid to see if it's a valid redeclaration.
  • The bool can be true without ever going into the point where we set impl_decl.impl_id. So the bool means something similar, but different.
  • Then later we check the bool instead of impl_decl.impl_id to see if it's a "valid redeclaration".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, this was the result of iterating until it behaved the way I wanted. The purpose of this bool was to plumb the information about whether we've already issued a particular error to the point where we can avoid producing another error. I think it would make sense to rename this !invalid_redeclaration, but I don't know if that goes far enough. Does #4738 help?

Copy link
Contributor

@danakj danakj Dec 23, 2024

Choose a reason for hiding this comment

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

yes it helps a lot with the intent of the bool.

I do think there's still a bit of collision with "valid redeclaration" meaning that impl_decl.impl_id.is_valid(). Maybe invalid_redeclaration would be better using a different name than "valid" and IsValidImplRedecl() could be renamed to match. I am not sure but maybe "legal" or something for that, since it's checking rules, whereas "valid" is used to refer to the id value.

Edit: clarifying grammar

github-merge-queue bot pushed a commit that referenced this pull request Dec 23, 2024
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