-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Simplify materialization of specialized generics #20121
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
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
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.
This seems like a win to me. The materialization kind is part of the specialization; it seems reasonable that apply_specialization methods would be responsible for handling it.
I think if we wanted to invest in better error-resilience here (if we find ourselves forgetting to apply the materialization in more cases), the approach would be to extract a Rust type that holds only the types part of a Specialization, and have TypeMappling::Specialization hold only that Rust type, so you'd have to extract that and the materialization from a Specialization in order to wrap it in a TypeMapping. This would make it impossible to ignore the materialization part accidentally.
| ) -> Self { | ||
| if let Some(specialization) = specialization { | ||
| self.apply_type_mapping_impl( | ||
| let new_self = self.apply_type_mapping_impl( |
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.
Nice find!
This is a variant of astral-sh#20076 that moves some complexity out of `apply_type_mapping_impl` in `generics.rs`. The tradeoff is that now every place that applies `TypeMapping::Specialization` must take care to call `.materialize()` afterwards. (A previous version of this didn't work because I had missed a spot where I had to call `.materialize()`.) @carljm as asked in astral-sh#20076 (comment) .
This is a variant of #20076 that moves some complexity out of
apply_type_mapping_implingenerics.rs. The tradeoff is that now every place that appliesTypeMapping::Specializationmust take care to call.materialize()afterwards. (A previous version of this didn't work because I had missed a spot where I had to call.materialize().)@carljm as asked in #20076 (comment) .