Refactor AliasTy & AliasTerm to use Alias#156538
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
a630681 to
89cd50d
Compare
|
can you say more about the errors you had to work around? this feels odd to me and something we should fix in the derives instead of requiring manual impls here imo |
| )] | ||
| pub struct AliasTy<I: Interner> { | ||
| /// The parameters of the associated or opaque type. | ||
| pub struct Alias<I: Interner, K> { |
There was a problem hiding this comment.
can you move Alias and AliasTerm in a separate rustc_type_ir/ty/alias module?
There was a problem hiding this comment.
667b095 👍, Only moved Alias & AliasTerm, not AliasTy
|
Edit: I've been experimenting and think I've expanded Original MessageI've whittled it down to only a manual (comments omitted for brevity) #[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner, K)]
#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)]
#[cfg_attr(
feature = "nightly",
derive(Decodable_NoContext, Encodable_NoContext, StableHash_NoContext)
)]
pub struct Alias<I: Interner, K> {
pub args: I::GenericArgs,
pub kind: K,
#[derive_where(skip(Debug))]
#[type_visitable(ignore)]
#[type_foldable(identity)]
pub(crate) _use_alias_new_instead: (),
}I get 2000+ errors of which fall into the following; A sample of errors being; And so on... This was similar to |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
667b095 to
b7965ca
Compare
This comment has been minimized.
This comment has been minimized.
|
The latest commits expand pub struct Binder<I: Interner, T> {
//
}and then pub struct Binder<I: Interner, T = SomeKind<I>> {
//
}e83546d, fbf009a Not sure if these would be best in a separate PR that also clean up Which I then used to clean up I can't get Eq Erroredit: Actually we can remove the empty implementation if we make |
This comment has been minimized.
This comment has been minimized.
…ric-capabilities, r=lcnr
Support generic params in `Lift_Generic`
Handle generic type parameters, including nested occurrences, when deriving `Lift_Generic`.
This lets types like `Binder<I, T>` use `#[derive(Lift_Generic)]` instead of requiring a manual `Lift` impl.
Concretely it can now handle structs as follows;
```rs
// Generic type parameter
struct Binder<I: Interner, T> {
// body
}
// Nested generic type parameter
pub struct Binder<I: Interner, T = SomeKind<I>> {
//
}
```
Split off from the `Alias` refactor work; rust-lang#156538
r? @lcnr
Rollup merge of #156956 - Jamesbarford:feat/extend-lift-generic-capabilities, r=lcnr Support generic params in `Lift_Generic` Handle generic type parameters, including nested occurrences, when deriving `Lift_Generic`. This lets types like `Binder<I, T>` use `#[derive(Lift_Generic)]` instead of requiring a manual `Lift` impl. Concretely it can now handle structs as follows; ```rs // Generic type parameter struct Binder<I: Interner, T> { // body } // Nested generic type parameter pub struct Binder<I: Interner, T = SomeKind<I>> { // } ``` Split off from the `Alias` refactor work; #156538 r? @lcnr
e2ba945 to
c3bdf72
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
71c7efb to
bf409af
Compare
| /// The parameters of the associated, opaque, or constant alias. | ||
| /// | ||
| /// For a projection, these are the generic parameters for the trait and the | ||
| /// GAT parameters, if there are any. | ||
| /// | ||
| /// For an inherent projection, they consist of the self type and the GAT parameters, | ||
| /// if there are any. | ||
| /// | ||
| /// For RPIT the generic parameters are for the generics of the function, | ||
| /// while for TAIT it is used for the generic parameters of the alias. | ||
| pub args: I::GenericArgs, | ||
|
|
||
| pub kind: K, |
There was a problem hiding this comment.
| /// The parameters of the associated, opaque, or constant alias. | |
| /// | |
| /// For a projection, these are the generic parameters for the trait and the | |
| /// GAT parameters, if there are any. | |
| /// | |
| /// For an inherent projection, they consist of the self type and the GAT parameters, | |
| /// if there are any. | |
| /// | |
| /// For RPIT the generic parameters are for the generics of the function, | |
| /// while for TAIT it is used for the generic parameters of the alias. | |
| pub args: I::GenericArgs, | |
| pub kind: K, | |
| pub kind: K, | |
| /// The parameters of the associated, opaque, or constant alias. | |
| /// | |
| /// For a projection, these are the generic parameters for the trait and the | |
| /// GAT parameters, if there are any. | |
| /// | |
| /// For an inherent projection, they consist of the self type and the GAT parameters, | |
| /// if there are any. | |
| /// | |
| /// For RPIT the generic parameters are for the generics of the function, | |
| /// while for TAIT it is used for the generic parameters of the alias. | |
| pub args: I::GenericArgs, |
personal style preference
| interner.debug_assert_args_compatible(kind.into(), args); | ||
| Alias { kind, args, _use_alias_new_instead: () } | ||
| } | ||
| } |
There was a problem hiding this comment.
hmm, could we change this to
trait AliasKind<I: Interner>: Copy {
fn assert_args_compatible(self, cx: I, args: I::GenericArgs);
#[inline]
fn debug_assert_args_compatible(self, cx: I, args: I::GenericArgs) {
if cfg!(debug_assertions) { self.assert... }
}
}
impl<I: Interner, K: AliasKind> Alias<I, K> {
pub fn new(
cx: I,
kind: K,
args: I::GenericArgs,
) -> Self {
kind.debug_assert_args_compatible(interner, args);
Alias { kind, args, _use_alias_new_instead: () }
}
pub fn new_from_iter(
cx: I,
kind: K,
args: impl IntoIterator<...>,
) -> Self { ... }
}| fn fold_with<F: TypeFolder<I>>(self, folder: &mut F) -> Self { | ||
| NormalizesTo { alias: self.alias.fold_with(folder), term: self.term.fold_with(folder) } | ||
| } | ||
| } |
There was a problem hiding this comment.
why do the derives not work?
Refactors
AliasTy&AliasTermto useAlias. To move around errors I had to manually implementLift,TypeVisitableandTypeFoldablePart of #156181
r? @lcnr