Skip to content
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

Add visits to nodes that already have flat_maps in ast::MutVisitor #133153

Merged
merged 9 commits into from
Nov 21, 2024

Conversation

maxcabrajac
Copy link
Contributor

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_maps 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 #128974 & #127615

r? @petrochenkov

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 18, 2024
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Nov 18, 2024

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 19, 2024
@bors

This comment was marked as resolved.

@maxcabrajac
Copy link
Contributor Author

Should I make a first test implementation of what I think should be done with flat_map_stmt? Do you have any opinions on it?

@petrochenkov
Copy link
Contributor

The current changes are good to go, after cleaning up history to avoid the back and forth changes.
The statement visiting can be done separately so I can think about it later, and not right now.

@maxcabrajac
Copy link
Contributor Author

Ok =)
History cleaned.
I'll open another pr with a first implementation of statement visiting.

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Nov 20, 2024

📌 Commit 01b26e6 has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 20, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 21, 2024
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`
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 21, 2024
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#131736 (Emscripten: link with -sWASM_BIGINT)
 - rust-lang#132207 (Store resolution for self and crate root module segments)
 - rust-lang#133153 (Add visits to nodes that already have flat_maps in ast::MutVisitor)
 - rust-lang#133218 (Implement `~const` item bounds in RPIT)
 - rust-lang#133228 (Rewrite `show_md_content_with_pager`)
 - rust-lang#133247 (Reduce integer `Display` implementation size)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 21, 2024
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#131736 (Emscripten: link with -sWASM_BIGINT)
 - rust-lang#132207 (Store resolution for self and crate root module segments)
 - rust-lang#133153 (Add visits to nodes that already have flat_maps in ast::MutVisitor)
 - rust-lang#133218 (Implement `~const` item bounds in RPIT)
 - rust-lang#133228 (Rewrite `show_md_content_with_pager`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 9d70af5 into rust-lang:master Nov 21, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Nov 21, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 21, 2024
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``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants