delegation: refactor AST -> HIR lowering#158434
Open
aerooneqq wants to merge 1 commit into
Open
Conversation
Contributor
Author
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
Contributor
|
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? |
Collaborator
|
Reminder, once the PR becomes ready for a review, use |
67f05b8 to
2196005
Compare
Contributor
Author
|
@rustbot ready |
petrochenkov
reviewed
Jul 2, 2026
Contributor
Author
|
@rustbot ready |
aerooneqq
commented
Jul 2, 2026
petrochenkov
reviewed
Jul 2, 2026
Contributor
Contributor
|
✌️ @aerooneqq, you can now approve this pull request! If @petrochenkov told you to " |
This comment has been minimized.
This comment has been minimized.
aec2af7 to
d42cca5
Compare
Contributor
Author
|
@bors r=petrochenkov |
Contributor
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Jul 3, 2026
…r=petrochenkov delegation: refactor AST -> HIR lowering 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: 1. Resolution - we collect all information about signature, signature parent context, delegation parent, delegation generics. Then this information is used in AST -> HIR lowering, 2. AST -> HIR lowering - we generate everything based on the output of resolution. This PR explicitly splits those two phases: as a first step we collect all needed information into `DelegationResolution` struct and then use it during AST -> HIR lowering. The `delegation.rs` file is moved into `delegation` folder and renamed to `mod.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 name `LoweringContext` contains many additional information which is used for lowering, I've created `LoweringContextForResolution` trait which abstracts operations which are used during delegation resolution. Benefits of this PR: - Resolution information is grouped into single struct, is extracted from AST -> HIR lowering which leads to better transfer of resolution across lowering (through a single struct, not through many arguments) and enhanced understanding of which information we use for delegation lowering, - There is now a single path for generating error delegation - if an error was returned from delegation resolution, - Refactorings of `uplift_delegation_generics` which was creating generic params for delegation made the code more understandable. Part of rust-lang#118212. r? @petrochenkov
rust-bors Bot
pushed a commit
that referenced
this pull request
Jul 5, 2026
Rollup of 18 pull requests Successful merges: - #158692 (Add release notes for 1.96.1) - #134021 (Implement `IntoIterator` for `[&[mut]] Box<[T; N], A>`) - #152860 (Port the `without_debuginfo` test from `backtrace-rs` to the testsuite) - #155932 (MIR Call terminator: evaluate destination place before arguments) - #156777 (Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme to make autodiff tests more robust) - #157151 (JSON target specs: remove 'x86-softfloat' compatibility alias) - #157835 (expand free alias types in the auto-trait orphan check) - #158377 (add `-Zforce-intrinsic-fallback` flag) - #158434 (delegation: refactor AST -> HIR lowering) - #158552 (make some tidy errors around python easier to understand) - #158624 (borrowck: Introduce BlameConstraint::to_obligation_cause_from_path()) - #158704 (Optimize `ArrayChunks::try_rfold` with `DoubleEndedIterator::next_chunk_back`) - #158711 (library: Comment on libtest's dicey internal soundness) - #158539 (Move `SizeHint` and `IoHandle` to `core::io`) - #158659 (refactor the normalization in `coerce_shared_info`) - #158689 (resolver: don't use `Finalize` when resolving visibilities during AST expansion) - #158698 (Update TypeVisitable implementation) - #158706 (Tweaks to MIR building scope API)
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Jul 5, 2026
…r=petrochenkov delegation: refactor AST -> HIR lowering 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: 1. Resolution - we collect all information about signature, signature parent context, delegation parent, delegation generics. Then this information is used in AST -> HIR lowering, 2. AST -> HIR lowering - we generate everything based on the output of resolution. This PR explicitly splits those two phases: as a first step we collect all needed information into `DelegationResolution` struct and then use it during AST -> HIR lowering. The `delegation.rs` file is moved into `delegation` folder and renamed to `mod.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 name `LoweringContext` contains many additional information which is used for lowering, I've created `LoweringContextForResolution` trait which abstracts operations which are used during delegation resolution. Benefits of this PR: - Resolution information is grouped into single struct, is extracted from AST -> HIR lowering which leads to better transfer of resolution across lowering (through a single struct, not through many arguments) and enhanced understanding of which information we use for delegation lowering, - There is now a single path for generating error delegation - if an error was returned from delegation resolution, - Refactorings of `uplift_delegation_generics` which was creating generic params for delegation made the code more understandable. Part of rust-lang#118212. r? @petrochenkov
rust-bors Bot
pushed a commit
that referenced
this pull request
Jul 5, 2026
…uwer Rollup of 20 pull requests Successful merges: - #158692 (Add release notes for 1.96.1) - #134021 (Implement `IntoIterator` for `[&[mut]] Box<[T; N], A>`) - #155932 (MIR Call terminator: evaluate destination place before arguments) - #155989 (Update `transmute_copy` to ub_checks and `?Sized`) - #156777 (Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme to make autodiff tests more robust) - #157151 (JSON target specs: remove 'x86-softfloat' compatibility alias) - #157835 (expand free alias types in the auto-trait orphan check) - #157857 (Stabilize `#[my_macro] mod foo;` (part of `proc_macro_hygiene`)) - #158377 (add `-Zforce-intrinsic-fallback` flag) - #158434 (delegation: refactor AST -> HIR lowering) - #158552 (make some tidy errors around python easier to understand) - #158624 (borrowck: Introduce BlameConstraint::to_obligation_cause_from_path()) - #158704 (Optimize `ArrayChunks::try_rfold` with `DoubleEndedIterator::next_chunk_back`) - #158711 (library: Comment on libtest's dicey internal soundness) - #158751 (rustdoc: Fix crash when trying to inline foreign item which cannot have attributes) - #158539 (Move `SizeHint` and `IoHandle` to `core::io`) - #158659 (refactor the normalization in `coerce_shared_info`) - #158689 (resolver: don't use `Finalize` when resolving visibilities during AST expansion) - #158698 (Update TypeVisitable implementation) - #158706 (Tweaks to MIR building scope API)
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Jul 5, 2026
…r=petrochenkov delegation: refactor AST -> HIR lowering 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: 1. Resolution - we collect all information about signature, signature parent context, delegation parent, delegation generics. Then this information is used in AST -> HIR lowering, 2. AST -> HIR lowering - we generate everything based on the output of resolution. This PR explicitly splits those two phases: as a first step we collect all needed information into `DelegationResolution` struct and then use it during AST -> HIR lowering. The `delegation.rs` file is moved into `delegation` folder and renamed to `mod.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 name `LoweringContext` contains many additional information which is used for lowering, I've created `LoweringContextForResolution` trait which abstracts operations which are used during delegation resolution. Benefits of this PR: - Resolution information is grouped into single struct, is extracted from AST -> HIR lowering which leads to better transfer of resolution across lowering (through a single struct, not through many arguments) and enhanced understanding of which information we use for delegation lowering, - There is now a single path for generating error delegation - if an error was returned from delegation resolution, - Refactorings of `uplift_delegation_generics` which was creating generic params for delegation made the code more understandable. Part of rust-lang#118212. r? @petrochenkov
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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