-
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
Use FacetAccessType when converting to a value of type FacetType #4925
Conversation
2dff78a
to
5c758da
Compare
When attempting to convert to a value of type FacetType, and the source value is a FacetAccessType, then if the type of the underlying FacetValue is the same as the target, we can use the FacetValue there as the conversion output. If the type of the FacetValue differs, then we still want to do impl lookup with the FacetValue to see if it matches with the target FacetType, but that is still a TODO. This allows a generic function with a value whose type is constrained by a FacetType (thus the value's type is a FacetAccessType), to call other functions with the value as an argument when it is constrained by the same FacetType: ``` fn F[T:! FacetType](x: T); fn G[T:! FacetType](x: T) { F(x); } ``` It is also an optimization to avoid impl lookup where we've already done it to produce the FacetAccessType. Adds a bunch of new tests with values of types which are constrained by a facet type (or "facet value value" for short), with some more tests that currently fail and should be made to pass.
5c758da
to
34220ff
Compare
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.
Looks great, thanks.
toolchain/check/convert.cpp
Outdated
@@ -991,7 +991,24 @@ static auto PerformBuiltinConversion(Context& context, SemIR::LocId loc_id, | |||
} | |||
|
|||
if (sem_ir.types().Is<SemIR::FacetType>(target.type_id)) { | |||
if (sem_ir.types().Is<SemIR::FacetType>(value_type_id)) { | |||
auto lookup_inst = value_id; |
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.
We'd usually call this lookup_inst_id
instead to indicate that it's an InstId
not an Inst
.
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.
Right, done. Thanks for the review!
When attempting to convert to a value of type FacetType, and the source value is a FacetAccessType, then if the type of the underlying FacetValue is the same as the target, we can use the FacetValue there as the conversion output.
If the type of the FacetValue differs, then we still want to do impl lookup with the FacetValue to see if it matches with the target FacetType, but that is still a TODO.
This allows a generic function with a value whose type is constrained by a FacetType (thus the value's type is a FacetAccessType), to call other functions with the value as an argument when it is constrained by the same FacetType:
It is also an optimization to avoid impl lookup where we've already done it to produce the FacetAccessType.
Adds a bunch of new tests with values of types which are constrained by a facet type (or "facet value value" for short), with some more tests that currently fail and should be made to pass.