-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Overhaul syntax::fold::Folder
.
#58061
Merged
Merged
Commits on Feb 5, 2019
-
Configuration menu - View commit details
-
Copy full SHA for b968641 - Browse repository at this point
Copy the full SHA b968641View commit details -
Specifically: - Remove dead methods: fold_usize, fold_meta_items, fold_opt_bounds. - Remove useless methods: fold_global_asm, fold_range_end. - Inline and remove unnecessary methods: fold_item_simple, fold_foreign_item_simple.
Configuration menu - View commit details
-
Copy full SHA for faa82eb - Browse repository at this point
Copy the full SHA faa82ebView commit details -
Configuration menu - View commit details
-
Copy full SHA for eea2dfe - Browse repository at this point
Copy the full SHA eea2dfeView commit details -
Configuration menu - View commit details
-
Copy full SHA for f97e896 - Browse repository at this point
Copy the full SHA f97e896View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8909f70 - Browse repository at this point
Copy the full SHA 8909f70View commit details -
Configuration menu - View commit details
-
Copy full SHA for 4730953 - Browse repository at this point
Copy the full SHA 4730953View commit details -
By eliminating some unnecessary methods, and moving/renaming some functions that look like they might be methods but aren't.
Configuration menu - View commit details
-
Copy full SHA for 372fe84 - Browse repository at this point
Copy the full SHA 372fe84View commit details -
Configuration menu - View commit details
-
Copy full SHA for 970b5d1 - Browse repository at this point
Copy the full SHA 970b5d1View commit details -
Overhaul
syntax::fold::Folder
.This commit changes `syntax::fold::Folder` from a functional style (where most methods take a `T` and produce a new `T`) to a more imperative style (where most methods take and modify a `&mut T`), and renames it `syntax::mut_visit::MutVisitor`. The first benefit is speed. The functional style does not require any reallocations, due to the use of `P::map` and `MoveMap::move_{,flat_}map`. However, every field in the AST must be overwritten; even those fields that are unchanged are overwritten with the same value. This causes a lot of unnecessary memory writes. The imperative style reduces instruction counts by 1--3% across a wide range of workloads, particularly incremental workloads. The second benefit is conciseness; the imperative style is usually more concise. E.g. compare the old functional style: ``` fn fold_abc(&mut self, abc: ABC) { ABC { a: fold_a(abc.a), b: fold_b(abc.b), c: abc.c, } } ``` with the imperative style: ``` fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) { visit_a(a); visit_b(b); } ``` (The reductions get larger in more complex examples.) Overall, the patch removes over 200 lines of code -- even though the new code has more comments -- and a lot of the remaining lines have fewer characters. Some notes: - The old style used methods called `fold_*`. The new style mostly uses methods called `visit_*`, but there are a few methods that map a `T` to something other than a `T`, which are called `flat_map_*` (`T` maps to multiple `T`s) or `filter_map_*` (`T` maps to 0 or 1 `T`s). - `move_map.rs`/`MoveMap`/`move_map`/`move_flat_map` are renamed `map_in_place.rs`/`MapInPlace`/`map_in_place`/`flat_map_in_place` to reflect their slightly changed signatures. - Although this commit renames the `fold` module as `mut_visit`, it keeps it in the `fold.rs` file, so as not to confuse git. The next commit will rename the file.
Configuration menu - View commit details
-
Copy full SHA for 9fcb165 - Browse repository at this point
Copy the full SHA 9fcb165View commit details -
Configuration menu - View commit details
-
Copy full SHA for bfcbd23 - Browse repository at this point
Copy the full SHA bfcbd23View commit details
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.