-
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
ast::mut_visit::MutVisitor
and ast::visit::Visitor
do not have corresponding methods for all their methods
#127615
Comments
Make ast `MutVisitor` have the same method name and style as `Visitor` It doesn't map 100% because some `MutVisitor` methods can filter or even expand to multiple items, but consistency seems nicer. The last commit showcases how similar they are by changing ast validation to a `MutVisitor` (without actually doing any mutation yet). My plan is to replace all nodes that support it with error nodes if validation failed on them. This allows ast lowering to just assume things are error or valid, and avoids having to redo some checks, delaying bugs or checking the global error counter. tracking issue: rust-lang#127615
Make ast `MutVisitor` have the same method name and style as `Visitor` It doesn't map 100% because some `MutVisitor` methods can filter or even expand to multiple items, but consistency seems nicer. tracking issue: rust-lang#127615
…nkov Make ast `MutVisitor` have the same method name and style as `Visitor` It doesn't map 100% because some `MutVisitor` methods can filter or even expand to multiple items, but consistency seems nicer. tracking issue: rust-lang#127615
…nkov Make ast `MutVisitor` have the same method name and style as `Visitor` It doesn't map 100% because some `MutVisitor` methods can filter or even expand to multiple items, but consistency seems nicer. tracking issue: rust-lang#127615
Make ast `MutVisitor` have the same method name and style as `Visitor` It doesn't map 100% because some `MutVisitor` methods can filter or even expand to multiple items, but consistency seems nicer. tracking issue: rust-lang/rust#127615
Make ast `MutVisitor` have the same method name and style as `Visitor` It doesn't map 100% because some `MutVisitor` methods can filter or even expand to multiple items, but consistency seems nicer. tracking issue: rust-lang/rust#127615
All of these should be added, correct? |
For the ones that only exist in Visitor but not in MutVisitor, it may be useful to see if anyone actually overrides these and potentially entirely remove them. For the ones that only exist in MutVisitor but not Visitor, there are some that don't really make sense for Visitor, like the one for ids or the one for spans. There won't be any immutable visitors that just want to see all spans I think. So it seems ok to have such differences for leaf functions (where the Walker is a noop) |
Also sometimes MutVisitor has things like ItemKind visiting, but not Item... Looks like my idea was a bit naive. We basically need to analyze every missing method and see if there isn't one almost like it and if it can reasonably be refactored or if the mut visitor is just too different because of the mutation |
Someone can correct me if I'm wrong, but I don't think claiming this issue is entirely appropriate, as it involves tracking sub-issues. I for one would be wanting to pick the low hanging fruit for the 4th suggestion for example, but leave the others alone. |
I think I can begin to implement the macro that generates both traits and |
I did some digging and this is what I found out:
|
I was digging around to find out what to do with methods that have a |
There are implementors of MutVisitor that produce multiple items. E.g. when expanding a macro in item position, it may yield multiple items |
Ohhh, now I get it. Sorry, I didn't read the docs for SmallVec well enough. |
Is there a master list of what |
Hi @noahmbright! I didn't do it immediately as I think it deserves a bit more discussion. Sorry for not starting it until now. =/ I noticed that every type whose |
not entirely clear what is left to do, which easy issue is still left, and how can I claim it? |
…chenkov Add `visit` methods to ast nodes that already have `walk`s on ast visitors Some `walk` functions are called directly, because there were no correspondent visit functions. related to rust-lang#128974 & rust-lang#127615 r? `@petrochenkov`
Rollup merge of rust-lang#133188 - maxcabrajac:walk_no_visit, r=petrochenkov Add `visit` methods to ast nodes that already have `walk`s on ast visitors Some `walk` functions are called directly, because there were no correspondent visit functions. related to rust-lang#128974 & rust-lang#127615 r? `@petrochenkov`
Add visits to nodes that already have flat_maps in ast::MutVisitor This PR aims to add `visit_` methods for every node that has a `flat_map_` in MutVisitor, giving implementers free choice over overriding `flat_map` for 1-to-n conversions or `visit` for a 1-to-1. There is one major problem: `flat_map_stmt`. While all other default implementations of `flat_map`s are 1-to-1 conversion, as they either only call visits or a internal 1-to-many conversions are natural, `flat_map_stmt` doesn't follow this pattern. `flat_map_stmt`'s default implementation is a 1-to-n conversion that panics if n > 1 (effectively being a 1-to-[0;1]). This means that it cannot be used as is for a default `visit_stmt`, which would be required to be a 1-to-1. Implementing `visit_stmt` without runtime checks would require it to reach over a potential `flat_map_item` or `filter_map_expr` overrides and call for their `visit` counterparts directly. Other than that, if we want to keep the behavior of `flat_map_stmt` it cannot call `visit_stmt` internally. To me, it seems reasonable to make all default implementations 1-to-1 conversions and let implementers handle `visit_stmt` if they need it, but I don't know if calling `visit` directly when a 1-to-1 is required is ok or not. related to rust-lang#128974 & rust-lang#127615 r? `@petrochenkov`
Add visits to nodes that already have flat_maps in ast::MutVisitor This PR aims to add `visit_` methods for every node that has a `flat_map_` in MutVisitor, giving implementers free choice over overriding `flat_map` for 1-to-n conversions or `visit` for a 1-to-1. There is one major problem: `flat_map_stmt`. While all other default implementations of `flat_map`s are 1-to-1 conversion, as they either only call visits or a internal 1-to-many conversions are natural, `flat_map_stmt` doesn't follow this pattern. `flat_map_stmt`'s default implementation is a 1-to-n conversion that panics if n > 1 (effectively being a 1-to-[0;1]). This means that it cannot be used as is for a default `visit_stmt`, which would be required to be a 1-to-1. Implementing `visit_stmt` without runtime checks would require it to reach over a potential `flat_map_item` or `filter_map_expr` overrides and call for their `visit` counterparts directly. Other than that, if we want to keep the behavior of `flat_map_stmt` it cannot call `visit_stmt` internally. To me, it seems reasonable to make all default implementations 1-to-1 conversions and let implementers handle `visit_stmt` if they need it, but I don't know if calling `visit` directly when a 1-to-1 is required is ok or not. related to rust-lang#128974 & rust-lang#127615 r? ``@petrochenkov``
Rollup merge of rust-lang#133153 - maxcabrajac:flat_maps, r=petrochenkov Add visits to nodes that already have flat_maps in ast::MutVisitor This PR aims to add `visit_` methods for every node that has a `flat_map_` in MutVisitor, giving implementers free choice over overriding `flat_map` for 1-to-n conversions or `visit` for a 1-to-1. There is one major problem: `flat_map_stmt`. While all other default implementations of `flat_map`s are 1-to-1 conversion, as they either only call visits or a internal 1-to-many conversions are natural, `flat_map_stmt` doesn't follow this pattern. `flat_map_stmt`'s default implementation is a 1-to-n conversion that panics if n > 1 (effectively being a 1-to-[0;1]). This means that it cannot be used as is for a default `visit_stmt`, which would be required to be a 1-to-1. Implementing `visit_stmt` without runtime checks would require it to reach over a potential `flat_map_item` or `filter_map_expr` overrides and call for their `visit` counterparts directly. Other than that, if we want to keep the behavior of `flat_map_stmt` it cannot call `visit_stmt` internally. To me, it seems reasonable to make all default implementations 1-to-1 conversions and let implementers handle `visit_stmt` if they need it, but I don't know if calling `visit` directly when a 1-to-1 is required is ok or not. related to rust-lang#128974 & rust-lang#127615 r? ``@petrochenkov``
In contrast to the MIR mut and immut visitors
rust/compiler/rustc_middle/src/mir/visit.rs
Lines 1235 to 1236 in c92a8e4
which are generated from a single macro, and are thus exactly the same except for mutation, the ast visitors are each handwritten. Their method naming scheme doesn't even match up, so changing from a
Visitor
to aMutVisitor
requires extensive changes.Work items
visit_*
vswalk_*
naming schemeMutVisitor::visit_*
method a correspondingflat_map_*
method. E-mediumvisit_foo
orflat_map_foo
without there being problems. Thewalk_bar
functions must invokeflat_map_foo
, so that they can pick up on more/fewer items being produced. Sowalk_flat_map_foo
(which only ever maps to a single output element) needs to invokevisit_foo
, notwalk_foo
. Otherwise overridingvisit_foo
will do nothing.(Optional): move all thediscussed, should not be donewalk_
functions to defaulted methods on the trait (not sure this should be done, discuss on zulip first!)MutVisitor::visit_*
method a correspondingVisitor
method and vice versa E-easywalk_
functions in one go, just like with the MIR visitors E-hardPrevious work
MutVisitor
have the same method name and style asVisitor
#127524The text was updated successfully, but these errors were encountered: