Skip to content

Conversation

@danakj
Copy link
Contributor

@danakj danakj commented Nov 21, 2025

We were requiring the facet type to be complete in two different places, but this was not necessary. Now we only require it to be complete in a single place when checking the definition. If it was required earlier for a rewrite constraint, it would have been already checked and diagnosed in member lookup for the rewrite.

In the process reorganize and rename code to help clarify the relationships and behaviour between handle_impl.cpp and impl.cpp.

Move the diagnosing of extend impl T as to the handler of the T, similar to where it's diagnosed for require decls. This helps simplify the code, avoiding a bunch of looking through parse nodes for specific types. Make them both handle errors in the self type in a similar manner, avoiding a second diagnostic.

@danakj danakj requested a review from a team as a code owner November 21, 2025 18:32
@danakj danakj requested review from josh11b and removed request for a team November 21, 2025 18:32
@danakj
Copy link
Contributor Author

danakj commented Nov 21, 2025

This is based on #6385, the first commit is less-completing-impl-as.

@danakj
Copy link
Contributor Author

danakj commented Nov 24, 2025

This is based on #6385, the first commit is less-completing-impl-as.

Rebased to trunk.

@danakj danakj force-pushed the less-completing-impl-as branch from c713931 to 181c03c Compare November 24, 2025 15:23
@danakj danakj requested a review from zygoloid November 26, 2025 16:30
Copy link
Contributor

@josh11b josh11b left a comment

Choose a reason for hiding this comment

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

Sorry for the delay in reviewing.

This PR seems a bit large, it ended up being pretty difficult to sort through all the changes. It would have helped a lot to break this into smaller changes.

Copy link
Contributor Author

@danakj danakj left a comment

Choose a reason for hiding this comment

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

Thanks, PTAL

@danakj danakj requested a review from josh11b November 26, 2025 23:08
Comment on lines +87 to +89
// If the explicit self type is the default, suggest removing it with a
// diagnostic, but continue as if no error occurred since the self-type
// is semantically valid.
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, since this is a recoverable error, we might want to make this into a warning, following https://docs.google.com/document/d/1-H-LwSllXydml49t-dHsUTOt8geY8ocskRMMRTtLfw0/edit?tab=t.0 .

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 thought about that but it's not recoverable in the sense that the code is correct but unintended. The code is syntactically wrong but we're able to fish for more errors by not inserting ErrorInst. I didn't think that sounded like a warning. Anyhow - if it is, let's address it separately.

bool need_witness_table =
is_definition || !rewrites_into_interface_to_witness.empty();
if (!need_witness_table) {
if (rewrites_into_interface_to_witness.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems we lost && !is_definition in the most recent changes. I'm having difficulty following what is happening, there are too many changes happening together in a single PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that is how we now have a single call to RequireCompleteType. I had attempted to explain the change in here: #6420 (comment)

We only need a non-placeholder witness table here if there is a rewrite into .Self. In that case we know .Self ensured the interface is already complete. For a declaration that is a definition the rule is the same.

Then we unconditionally RequireCompleteType of the facet type in the definition - inside the generic. This avoids the coordination between these two files to avoid doing RequireCompleteType twice.

@danakj danakj removed the request for review from zygoloid December 2, 2025 22:33
Copy link
Contributor Author

@danakj danakj left a comment

Choose a reason for hiding this comment

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

PTAL

bool need_witness_table =
is_definition || !rewrites_into_interface_to_witness.empty();
if (!need_witness_table) {
if (rewrites_into_interface_to_witness.empty()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that is how we now have a single call to RequireCompleteType. I had attempted to explain the change in here: #6420 (comment)

We only need a non-placeholder witness table here if there is a rewrite into .Self. In that case we know .Self ensured the interface is already complete. For a declaration that is a definition the rule is the same.

Then we unconditionally RequireCompleteType of the facet type in the definition - inside the generic. This avoids the coordination between these two files to avoid doing RequireCompleteType twice.

Comment on lines +87 to +89
// If the explicit self type is the default, suggest removing it with a
// diagnostic, but continue as if no error occurred since the self-type
// is semantically valid.
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 thought about that but it's not recoverable in the sense that the code is correct but unintended. The code is syntactically wrong but we're able to fish for more errors by not inserting ErrorInst. I didn't think that sounded like a warning. Anyhow - if it is, let's address it separately.

@danakj danakj requested a review from josh11b December 2, 2025 23:11
@danakj danakj removed the request for review from josh11b December 4, 2025 19:04
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.

2 participants