about summary refs log tree commit diff
path: root/src/libsyntax/fold.rs
AgeCommit message (Collapse)AuthorLines
2019-02-06Rename `fold.rs` as `mut_visit.rs`.Nicholas Nethercote-1330/+0
2019-02-06Overhaul `syntax::fold::Folder`.Nicholas Nethercote-1042/+960
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.
2019-02-05Streamline `Folder` some more.Nicholas Nethercote-43/+39
By eliminating some unnecessary methods, and moving/renaming some functions that look like they might be methods but aren't.
2019-02-05Neaten up `fold_crate`.Nicholas Nethercote-24/+15
2019-02-05Change `fold_qpath` to `fold_qself`.Nicholas Nethercote-14/+8
It's simpler that way.
2019-02-05Simplify `fold_attribute`.Nicholas Nethercote-10/+6
It doesn't need to return an `Option`.
2019-02-05Fold some overlooked spans.Nicholas Nethercote-11/+16
2019-02-05Streamline `Folder`.Nicholas Nethercote-77/+20
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.
2019-02-05Remove some unnecessary `ast::` and `fold::` qualifiers.Nicholas Nethercote-42/+34
2019-01-22Corrected spelling inconsistencyMarcel Hellwig-6/+6
resolves #57773
2019-01-14Remove `ThinTokenStream`.Nicholas Nethercote-1/+1
`TokenStream` is now almost identical to `ThinTokenStream`. This commit removes the latter, replacing it with the former.
2018-12-27Get rid of `Block::recovered`Vadim Petrochenkov-2/+1
2018-12-27AST/HIR: Introduce `ExprKind::Err` for better error recovery in the front-endVadim Petrochenkov-0/+1
2018-12-25Remove licensesMark Rousskov-10/+0
2018-12-10Remove `tokenstream::Delimited`.Nicholas Nethercote-5/+3
Because it's an extra type layer that doesn't really help; in a couple of places it actively gets in the way, and overall removing it makes the code nicer. It does, however, move `tokenstream::TokenTree` further away from the `TokenTree` in `quote.rs`. More importantly, this change reduces the size of `TokenStream` from 48 bytes to 40 bytes on x86-64, which is enough to slightly reduce instruction counts on numerous benchmarks, the best by 1.5%. Note that `open_tt` and `close_tt` have gone from being methods on `Delimited` to associated methods of `TokenTree`.
2018-12-07Various minor/cosmetic improvements to codeAlexander Regueiro-2/+2
2018-11-07Rollup merge of #55734 - teresy:shorthand-fields, r=davidtwcokennytm-1/+1
refactor: use shorthand fields refactor: use shorthand for single fields everywhere (excluding tests).
2018-11-06refactor: use shorthand fieldsteresy-1/+1
2018-10-26Give each PathSegment a NodeIdNick Cameron-1/+3
2018-10-23Remove redundant cloneShotaro Yamada-1/+1
2018-09-27Auto merge of #52319 - tinco:issue_12590, r=pnkfelixbors-1/+3
Track whether module declarations are inline (fixes #12590) To track whether module declarations are inline I added a field `inline: bool` to `ast::Mod`. The main use case is for pretty to know whether it should render the items associated with the module, but perhaps there are use cases for this information to not be forgotten in the AST.
2018-09-26Remove OneVectorljedrz-15/+25
2018-09-10Track whether module declarations are inline (fixes #12590)Tinco Andringa-1/+3
2018-09-08Track distinct spans for open and close delimiterDavid Tolnay-4/+7
2018-09-01Auto merge of #53815 - F001:if-let-guard, r=petrochenkovbors-1/+11
refactor match guard This is the first step to implement RFC 2294: if-let-guard. Tracking issue: https://github.com/rust-lang/rust/issues/51114 The second step should be introducing another variant `IfLet` in the Guard enum. I separated them into 2 PRs for the convenience of reviewers. r? @petrochenkov
2018-08-30introduce Guard enumF001-1/+11
2018-08-23Auto merge of #53384 - gootorov:use-servo-smallvec, r=michaelwoeristerbors-9/+10
Use optimized SmallVec implementation This PR replaces current SmallVec implementation with the one from the Servo project. Closes https://github.com/rust-lang/rust/issues/51640 r? @Mark-Simulacrum
2018-08-23Auto merge of #52602 - scottmcm:tryblock-expr, r=nikomatsakisbors-1/+1
Implement try block expressions I noticed that `try` wasn't a keyword yet in Rust 2018, so... ~~Fix​es https://github.com/rust-lang/rust/issues/52604~~ That was fixed by PR https://github.com/rust-lang/rust/pull/53135 cc https://github.com/rust-lang/rust/issues/31436 https://github.com/rust-lang/rust/issues/50412
2018-08-23Use optimized SmallVec implementationIgor Gutorov-9/+10
2018-08-19Rename `Catch` variants to `TryBlock`Scott McMurray-1/+1
(Not `Try` since `QuestionMark` is using that.)
2018-08-19mv (mod) codemap source_mapDonato Sciarra-1/+1
2018-08-13Move SmallVec and ThinVec out of libsyntaxljedrz-18/+19
2018-07-18Implement existential typesOliver Schneider-0/+7
2018-06-27Generate `DefId`s for the impl trait of `async` functionsOliver Schneider-10/+21
2018-06-27Generate the `NodeId` for `existential type` in the ASTOliver Schneider-2/+2
2018-06-26inclusive range syntax lint (`...` → `..=`)Zack M. Davis-2/+2
Our implementation ends up changing the `PatKind::Range` variant in the AST to take a `Spanned<RangeEnd>` instead of just a `RangeEnd`, because the alternative would be to try to infer the span of the range operator from the spans of the start and end subexpressions, which is both hideous and nontrivial to get right (whereas getting the change to the AST right was a simple game of type tennis). This is concerning #51043.
2018-06-21async await desugaring and testsTaylor Cramer-2/+23
2018-06-21Parse async fn header.Without Boats-5/+3
This is gated on edition 2018 & the `async_await` feature gate. The parser will accept `async fn` and `async unsafe fn` as fn items. Along the same lines as `const fn`, only `async unsafe fn` is permitted, not `unsafe async fn`.The parser will not accept `async` functions as trait methods. To do a little code clean up, four fields of the function type struct have been merged into the new `FnHeader` struct: constness, asyncness, unsafety, and ABI. Also, a small bug in HIR printing is fixed: it previously printed `const unsafe fn` as `unsafe const fn`, which is grammatically incorrect.
2018-06-20Rename ParenthesizedArgData to ParenthesisedArgsvarkor-6/+6
2018-06-20Make GenericBound explicitvarkor-3/+5
2018-06-20Rename ParamBound(s) to GenericBound(s)varkor-8/+8
2018-06-20Rename TraitTyParamBound to ParamBound::Traitvarkor-2/+2
2018-06-20Take advantage of the lifetime refactoringvarkor-31/+29
2018-06-20Lift bounds into GenericParamvarkor-12/+11
2018-06-20Rename structures in astvarkor-12/+12
2018-06-20Refactor ast::GenericParam as a structvarkor-21/+6
2018-06-20Rename ast::GenericParam and ast::GenericArgvarkor-11/+11
It's so confusing to have everything having the same name, at least while refactoring.
2018-06-20Make method and variable names more consistentvarkor-20/+24
2018-06-20Rename "parameter" to "arg"varkor-19/+19
2018-06-20Rename PathParameter(s) to GenericArg(s)varkor-25/+16