delegation: refactor AST -> HIR lowering#158434
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
d6dd2be to
c2d7c9c
Compare
This comment has been minimized.
This comment has been minimized.
ae9c536 to
faa250b
Compare
This comment has been minimized.
This comment has been minimized.
faa250b to
002fc94
Compare
|
Could you split this into 2 commits - one moving code around (to different files, or within files), and the second one doing the code changes/refactorings? |
|
Reminder, once the PR becomes ready for a review, use |
67f05b8 to
2196005
Compare
|
@rustbot ready |
|
@rustbot ready |
| /// Abstracts operations that are needed for delegation's resolution, so resolution | ||
| /// is independent of `LoweringContext`. Placed in a separate module so `LoweringContext` | ||
| /// can not be accessed directly. | ||
| pub(crate) struct DelegationResolverWrapper<'a, 'hir>(&'a LoweringContext<'a, 'hir>); |
There was a problem hiding this comment.
| pub(crate) struct DelegationResolverWrapper<'a, 'hir>(&'a LoweringContext<'a, 'hir>); | |
| pub(crate) struct DelegationResolver<'a, 'hir>(&'a LoweringContext<'a, 'hir>); |
There's no naming ambiguity with the trait anymore.
| } | ||
|
|
||
| pub(super) fn check_for_cycles( | ||
| impl<'tcx> wrapper::DelegationResolverWrapper<'_, 'tcx> { |
There was a problem hiding this comment.
| impl<'tcx> wrapper::DelegationResolverWrapper<'_, 'tcx> { | |
| impl<'tcx> DelegationResolver<'_, 'tcx> { |
Import, here and in one more place.
| (!args.args.is_empty()).then(|| args) | ||
| } | ||
|
|
||
| pub(super) fn resolve_generics( |
There was a problem hiding this comment.
| pub(super) fn resolve_generics( | |
| pub(super) fn resolve_and_generate_generics( |
Because we produce GenericsGenerationResults here and not GenericsResolution.
create_generics_resolution can then be renamed to resolve_generics.
|
✌️ @aerooneqq, you can now approve this pull request! If @petrochenkov told you to " |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
View all comments
After a lot of new features were added to delegation the code became a bit worse, as resolution and lowering logic is mixed in
delegation.rs. In this file the output of resolution step of delegation is transferred as function params (in some functions up to 7 or 8 params), which is not good looking for me.As I mentioned in the previous paragraph delegation AST -> HIR lowering can be split into two phases:
This PR explicitly splits those two phases: as a first step we collect all needed information into
DelegationResolutionstruct and then use it during AST -> HIR lowering. Thedelegation.rsfile is moved intodelegationfolder and renamed tomod.rs, the final file structure is as follows:mod.rs- contains lowering logic for everything but generics,generics.rs- contains logic for resolution and uplifting of generic params, placed in a separate file as it is a significant and independent part of lowering,attributes.rs- contains relatively small piece of logic which connects to attributes inheritance,resolution.rs- contains logic for resolution of everything but generics.As resolution of delegation and generics logically does not depend on
LoweringContext, as from its nameLoweringContextcontains many additional information which is used for lowering, I've createdLoweringContextForResolutiontrait which abstracts operations which are used during delegation resolution.Benefits of this PR:
uplift_delegation_genericswhich was creating generic params for delegation made the code more understandable.Part of #118212.
r? @petrochenkov