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

Overhaul syntax::fold::Folder. #58061

Merged
merged 10 commits into from
Feb 6, 2019

Commits on Feb 5, 2019

  1. Configuration menu
    Copy the full SHA
    b968641 View commit details
    Browse the repository at this point in the history
  2. Streamline Folder.

    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.
    nnethercote committed Feb 5, 2019
    Configuration menu
    Copy the full SHA
    faa82eb View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    eea2dfe View commit details
    Browse the repository at this point in the history
  4. Simplify fold_attribute.

    It doesn't need to return an `Option`.
    nnethercote committed Feb 5, 2019
    Configuration menu
    Copy the full SHA
    f97e896 View commit details
    Browse the repository at this point in the history
  5. Change fold_qpath to fold_qself.

    It's simpler that way.
    nnethercote committed Feb 5, 2019
    Configuration menu
    Copy the full SHA
    8909f70 View commit details
    Browse the repository at this point in the history
  6. Neaten up fold_crate.

    nnethercote committed Feb 5, 2019
    Configuration menu
    Copy the full SHA
    4730953 View commit details
    Browse the repository at this point in the history
  7. Streamline Folder some more.

    By eliminating some unnecessary methods, and moving/renaming some
    functions that look like they might be methods but aren't.
    nnethercote committed Feb 5, 2019
    Configuration menu
    Copy the full SHA
    372fe84 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    970b5d1 View commit details
    Browse the repository at this point in the history
  9. 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.
    nnethercote committed Feb 5, 2019
    Configuration menu
    Copy the full SHA
    9fcb165 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    bfcbd23 View commit details
    Browse the repository at this point in the history