-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Investigate mutating the AST during late resolution #99669
Comments
I'm not sure whether it's a good idea in general, but the implementation/prototyping here can be simplified by splitting this job into two steps:
|
@cjgillot |
I'm taking a lock on it because its feet on my learning path! and see the evolution of the discussion in the meanwhile @rustbot claim |
@vincenzopalazzo are you still working on this? |
@Nilstrieb it is in my todo list my I had some other priority, so I unassign me if you had any other good target to assign this |
@rustbot claim Hi, I'd like to try this out. |
Hi @jon-chuang are you working on this? And @cjgillot is this still a relevant issue? |
Hello, not anymore |
This issue is still relevant. |
cool, I will work on this then. |
Stepping down from this issue -- the complexity is a bit much for me right now, and my priorities have shifted. @rustbot release-assignment |
Having a pre-lowering pass working on AST may be useful for implementing delegation (#118212). impl Foo { // id_foo
reuse Trait::{a, b, c}; // id_reuse
} => impl Foo { // id_foo
reuse Trait::a; // id_a
reuse Trait::b; // id_b
reuse Trait::c; // id_c
} Then AST lowering will turn the With the current lowering we immediately go inside the Not sure how to do it better without a pre-lowering pass. UPD: Design for this specific question about delegation - rust-lang/rfcs#3530 (comment). |
Late name resolution happens on the AST and is responsible for finding which definition each name in the AST points to, be it a type, trait expression, pattern, lifetime or label. The name "late" means that this resolution happens after all macros have been expanded, in opposition to "early" resolution which resolves macros. The corresponding code lives in
rustc_resolve::late
.The results of this late resolution are stored in tables, and used by HIR lowering to directly embed the information in HIR.
Later, lowering reinterprets some of the AST where the syntax is ambiguous. For instance, lowering is responsible for making bare trait objects explicit: interpreting types of the form
T
withdyn T
when resolution finds thatT
is a trait. Lowering also introduces implicit lifetime parameters for lifetime elision. The corresponding code lives inrustc_ast_lowering
.This re-interpretation of the AST needs to closely mirror what resolution is doing. Mismatches can cause bugs, like AST and HIR disagreeing on how to resolve lifetimes in the
dyn T
discussed above.The objective of this project is to have this resolution-based desugaring in only one place. We would like to have late resolution modify the AST to directly perform these transformations, and remove them from lowering.
At the same time, lowering also performs its own transformations, like transforming
impl Trait
to generic parameters or opaque types. Those transformations should stay in lowering for the time being. Rule of thumb: if the transformation inspects resolutions, it should go in resolution, if it's purely syntactic it can stay in lowering.Steps:
rustc_resolve::late
by an ASTMutVisitor
.MutVisitor
is designed for macro expansions, so it may lack some methods to make resolution practical. There can be design work here, so feel free to suggest new methods / a differentMutVisitor
trait / ...rustc_ast_lowering::path
, and aims to transforma::b::c::d
to<a::b::c>::d
whena::b::c
can be resolved to a type and::d
cannot (for instance because it is a trait method). Seerustc_resolve::late::smart_resolve_path
and associated methods.rustc_resolve::late::visit_ty
.Please contact me on zulip (cjgillot) for any questions.
Note: this project is a large body of work, with possibly many changes to the resolution code. The point is to simplify the lowering code. If this simplification goal is not reached, or if the perf impact is prohibitive, we may end-up not merging the modifications, and instead document why.
To be merged, the PR will probably require a major change proposal. I will take care of this proposal once the perspectives become a bit clear.
The text was updated successfully, but these errors were encountered: