Skip to content

Conversation

danakj
Copy link
Contributor

@danakj danakj commented Sep 23, 2025

When doing impl lookup with a constraint facet type including the builtin TypeCanAggregateDestroy, we look at the type to see if it satisfies it. However if the type is a facet value, we need to look at the FacetType to see if the eventual concrete type is going to satisfy it.

Note that we can do this check up front in the LookupImplWitness() function without creating a symbolic instruction to be modified by future specifics with a more precise type for the facet value, because the result of TypeCanAggregateDestroy does not actually provide a witness, so we don't need the final specific type.

This was noticed by removing the "shortcut" in convert for converting a FacetAccessType(<symbolic binding>) to typeof(<symbolic binding>). By removing the shortcut, we go into impl lookup when checking impl decls containing TypeCanAggregateDestroy via deduce.

@github-actions github-actions bot requested a review from zygoloid September 23, 2025 14:36
@danakj danakj requested a review from jonmeow September 23, 2025 14:37
@danakj
Copy link
Contributor Author

danakj commented Sep 23, 2025

Based on #6107, first commit is mask-facet-value

@danakj danakj removed the request for review from zygoloid September 23, 2025 14:38
Copy link
Contributor

@jonmeow jonmeow left a comment

Choose a reason for hiding this comment

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

LG, thanks!

// here.
//
// See also test:
// facet_access_type_converts_back_to_original_facet_value.carbon
Copy link
Contributor

Choose a reason for hiding this comment

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

Which directory should I look in for this test? I'm not seeing it in this PR or at trunk.

Maybe include the full path to make it easy to find?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a split in another file, so you have to do a search to find it. I didn't want to put both, it felt like a lot...

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe only put the filename, or just remove the mention? I don't know how I'm supposed to find this, also the name could be duplicated in multiple files.

Comment on lines +221 to +225
auto bind = context.insts().Get(bind_id);
if (bind.Is<SemIR::BindSymbolicName>()) {
// If the FacetTypes are the same, then the FacetValue didn't add/remove
// any witnesses.
if (bind.type_id() == inst.type_id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe bundle this together and reduce nesting, such as:

Suggested change
auto bind = context.insts().Get(bind_id);
if (bind.Is<SemIR::BindSymbolicName>()) {
// If the FacetTypes are the same, then the FacetValue didn't add/remove
// any witnesses.
if (bind.type_id() == inst.type_id) {
// If the FacetTypes are the same, then the FacetValue didn't add/remove
// any witnesses.
if (auto bind = context.insts().TryGetAs<SemIR::BindSymbolicName>(bind_id); bind && bind.type_id() == inst.type_id) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reduced nesting is nice but I am kind of averse to using the if (.. ; ..) syntax just cuz it's so easy to forget to test the thing on the lhs of the ; which is automatically tested without the ;. So idk if it's better overall..

Copy link
Contributor

Choose a reason for hiding this comment

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

You could also move the auto bind out of the if -- mainly I'm suggesting the TryGetAs, and use of && instead of nested if

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