remove AliasTerm::def_id()#157653
Conversation
|
|
| let cx = self.cx(); | ||
| let free_alias = goal.predicate.alias; | ||
|
|
||
| let def_id = match free_alias.kind { |
There was a problem hiding this comment.
thoughts on mirroring the expect_projection_def_id setup for free aliases and inherent aliases and then dropping all these explicit matches? i feel like these kinda matches detract from the surrounding code and a method would flow better :3
There was a problem hiding this comment.
sure! I could see it either way, explicit for clarity vs. concise for quick readability. Probably good to add expect_free_def_id and friends, which would then make it clear in the future where ty::Alias<ty::FreeAliasTermKind> should be introduced by find-all-refs on the expect methods. (just explaining my logic, I kept expect_projection_def_id because it's used a bunch, but free/inherent matching a bit less often)
| ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> { | ||
| let cx = ecx.cx(); | ||
| let def_id = goal.predicate.def_id().try_into().unwrap(); | ||
| let def_id = match goal.predicate.alias.kind { |
There was a problem hiding this comment.
could also have an expect_projecftion_ty_def_id 🤔
| selcx: &'a mut SelectionContext<'b, 'tcx>, | ||
| param_env: ty::ParamEnv<'tcx>, | ||
| alias_term: ty::AliasTerm<'tcx>, | ||
| alias_def_id: DefId, |
There was a problem hiding this comment.
feels vaguely unfortunate to have to take a defid here even though its part of alias_term. feels like a bit of a code smell because the latter argument is implied by the former argument.
do you think it matters for perf to not match on the alias kind inside of here.
separately, kinda makes me wonder whether we want to make ProjectionAliasTerm FreeAliasTerm and InherentAliasTerm types so we can track this in the type system? might be too much effort... I want pattern types 😭...
There was a problem hiding this comment.
separately, kinda makes me wonder whether we want to make
ProjectionAliasTermFreeAliasTermandInherentAliasTermtypes so we can track this in the type system? might be too much effort... I want pattern types 😭...
my long-term hot take is that after #156538 lands, all the unwraps here could be replaced by narrowing the type to ty::Alias<ty::ProjectionAliasTermKind> instead of the current ty::Alias<ty::AliasTermKind> (perhaps with a fn def_id impl on ty::Alias<ty::ProjectionAliasTermKind> that would replace expect_projection_def_id)
that requires waiting for that PR to land though, and would also make this PR even bigger than it currently is, so IMO I'll do it in a followup!
feels like a bit of a code smell. do you think it matters for perf
but yeah there's parts that are pretty gross. it probably doesn't matter for perf, was just trying to make code style decisions, there's not really a clear good answer for many of these places.
| /// into `self.out`. | ||
| fn add_wf_preds_for_alias_term(&mut self, data: ty::AliasTerm<'tcx>) { | ||
| /// Pushes the obligations required for a projection to be WF into `self.out`. | ||
| fn add_wf_preds_for_projection_term(&mut self, data: ty::AliasTerm<'tcx>) { |
There was a problem hiding this comment.
this is a weird method lmao, it has a single call site and isnt used by half the places in this module which add wf predicates for projection terms (e.g. handling of projection types in visit_ty)
kinda makes me wonder if we should inline it into its one caller, but that is orthogonal to your PR
There was a problem hiding this comment.
yeaah. add_wf_preds_for_projection_args also has only a single callsite, and it's this method, so the two could probably be combined into a single method.
at least the method is no longer mis-named, before my rename, add_wf_preds_for_alias_term called add_wf_preds_for_projection_args which is like, ???
the caller (clause_obligations) is currently cute tho, just invokes out to helper methods for each case of the match, so keeping this a separate method is cute IMO :3
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
c893b93 to
acdf4ec
Compare
|
@rustbot ready I added a One ambient thought I had for |
There was a problem hiding this comment.
Why do we want to be explicit about Aliasterm variants when retrieving their defIds? Earlier, these methods relied on the caller to pass the right kind of Aliasterm. Is the intent now to make that requirement explicit and fail if an unexpected variant is passed?
PS: Super awesome PR, really easy to follow, helping me understand better. These are some newbie questions..
| let def_id = match kind { | ||
| AliasTermKind::ProjectionTy { def_id } => def_id.into(), | ||
| AliasTermKind::InherentTy { def_id } => def_id.into(), | ||
| AliasTermKind::OpaqueTy { def_id } => def_id.into(), | ||
| AliasTermKind::FreeTy { def_id } => def_id.into(), | ||
| AliasTermKind::AnonConst { def_id } => def_id.into(), | ||
| AliasTermKind::ProjectionConst { def_id } => def_id.into(), | ||
| AliasTermKind::FreeConst { def_id } => def_id.into(), | ||
| AliasTermKind::InherentConst { def_id } => def_id.into(), | ||
| }; |
There was a problem hiding this comment.
Would it make sense to keep an abstraction for cases like this? Since all variants are handled uniformly here.
There was a problem hiding this comment.
The point of this change is to allow non-def_id containing variants to be easily added. In this case, a new non-def_id containing variant will presumably have its own version of debug_assert_args_compatible that will be implemented here (or perhaps debug_assert_args_compatible will take a AliasTermKind) - i.e. the explicit match here forces you to look at this piece of code when adding a variant. So I agree with you that this looks very silly right now, because this PR doesn't actually have any use cases for non-def_id variants, but, yeah.
| alias_term: ty::AliasTerm<'tcx>, | ||
| alias_def_id: DefId, |
There was a problem hiding this comment.
Shouldn't we get the alias_def_if from alias_term, and match explicitly like other places?
There was a problem hiding this comment.
woop, thank you! update pushed
Ah, whoops, yeah, saw your file comment before I saw this review comment. Yeah, the point is to add variants to AliasTermKind/AliasTyKind/AliasConstKind that do not contain a DefId, so a blanket
|
acdf4ec to
dc0b517
Compare
Thanks for explaining. Much clear now!!! |
This comment has been minimized.
This comment has been minimized.
cea948b to
5faf7ac
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. |
This comment has been minimized.
This comment has been minimized.
5faf7ac to
a93777a
Compare
|
sorry for all the force pushes, bit of a headache to rebase this |
|
A job failed! Check out the build log: (web) (plain enhanced) (plain) Click to see the possible cause of the failure (guessed by this bot) |
View all comments
this is part of #156181
as well as part of #152245
fyi @lcnr
r? @BoxyUwU