about summary refs log tree commit diff
path: root/src/libsyntax/tokenstream.rs
AgeCommit message (Collapse)AuthorLines
2019-10-14Rollup merge of #65261 - nnethercote:rm-Option-from-TokenStream, r=petrochenkovTyler Mandry-133/+91
Remove `Option` from `TokenStream` A code simplification. r? @petrochenkov
2019-10-14Remove the `Option` in `TokenStream`.Nicholas Nethercote-133/+91
It means an allocation is required to create an empty `TokenStream`, but all other operations are simpler and marginally faster due to not having to check for `None`. Overall it simplifies the code for a negligible performance effect. The commit also removes `TokenStream::empty` by implementing `Default`, which is now possible.
2019-10-13tokenstream: don't depend on pprustMazdak Farrokhzad-8/+1
2019-10-08Optimize `TokenStreamBuilder::push`.Nicholas Nethercote-51/+43
Currently, when two tokens must be glued together, this function duplicates large chunks of the existing streams. This can cause quadratic behaviour. This commit changes the function so that it overwrites the last token with a glued token, which avoids the quadratic behaviour. This removes the need for `TokenStreamBuilder::push_all_but_{first,last}_tree`. The commit also restructures `push` somewhat, by removing `TokenStream::{first_tree_and_joint,last_tree_if_joint}` in favour of more pattern matching and some comments. This makes the code shorter, and in my opinion, more readable.
2019-10-08Optimize `TokenStream::from_streams`.Nicholas Nethercote-10/+37
Currently, this function creates a new empty stream, and then appends the elements from each given stream onto that stream. This can cause quadratic behaviour. This commit changes the function so that it modifies the first stream (which can be long) by extending it with the elements from the subsequent streams (which are almost always short), which avoids the quadratic behaviour.
2019-09-22push TokenTree::parse downAleksey Kladov-15/+0
2019-09-22pull mbe token tree definition upAleksey Kladov-2/+2
2019-09-22rename tt -> mbe, part 2Aleksey Kladov-1/+1
2019-09-22reduce visibility of a bunch of stuff in ext::ttAleksey Kladov-1/+1
2019-09-07Aggregation of cosmetic changes made during work on REPL PRs: libsyntaxAlexander Regueiro-4/+3
2019-09-03use TokenStream rather than &[TokenTree] for built-in macrosAleksey Kladov-1/+1
That way, we don't loose the jointness info
2019-08-23hygiene: Require passing transparency explicitly to `apply_mark`Vadim Petrochenkov-8/+1
2019-08-19glue tokens when building token streamAleksey Kladov-1/+1
2019-08-02libsyntax: Unconfigure tests during normal buildVadim Petrochenkov-111/+3
2019-07-23cleanup: Remove `extern crate serialize as rustc_serialize`sVadim Petrochenkov-1/+1
2019-07-19Adjust other names after the `Mark` renamingVadim Petrochenkov-3/+3
2019-07-19libsyntax: Remove `Mark` into `ExpnId`Vadim Petrochenkov-2/+2
2019-07-04Switch master to 1.38Mark Rousskov-11/+0
2019-06-14put back the workarounds for #60846Felix S Klock II-0/+11
based on https://github.com/rust-lang/rust/pull/61754#issuecomment-501743750 I am adding `bootstrap` to the cfg-preconditions for the two manual `unsafe impls`'s of `Send` and `Sync` for `TokenTree`.
2019-06-12remove hacks that are no longer neededNiko Matsakis-11/+0
2019-06-08syntax: Remove `Deref` impl from `Token`Vadim Petrochenkov-8/+0
2019-06-08syntax: Move most of the `TokenKind` methods to `Token`Vadim Petrochenkov-3/+2
2019-06-06Some code cleanup and tidy/test fixesVadim Petrochenkov-2/+3
2019-06-06syntax: Switch function parameter order in `TokenTree::token`Vadim Petrochenkov-9/+9
2019-06-06syntax: Remove duplicate span from `token::Ident`Vadim Petrochenkov-2/+2
2019-06-06syntax: Add some helper methods to `Token`Vadim Petrochenkov-1/+1
2019-06-06syntax: Use `Token` in `TokenTree::Token`Vadim Petrochenkov-57/+54
2019-06-06syntax: Rename `TokenAndSpan` into `Token`Vadim Petrochenkov-1/+0
2019-06-06syntax: Rename `Token` into `TokenKind`Vadim Petrochenkov-7/+7
2019-06-06Always use token kinds through `token` module rather than `Token` typeVadim Petrochenkov-12/+12
2019-05-27Short circuit Send and Sync impls for TokenTreeJohn Kåre Alsaker-0/+22
2019-05-21Move `edition` outside the hygiene lock and avoid accessing itJohn Kåre Alsaker-16/+18
2019-05-19Improve type size assertionsVadim Petrochenkov-2/+2
Now they - Tell what the new size is, when it changes - Do not require passing an identifier
2019-04-24Add guard for missing comma in macro call suggestionEsteban Küber-2/+4
2019-03-29Use `SmallVec` in `TokenStreamBuilder`.Nicholas Nethercote-6/+8
This reduces by 12% the number of allocations done for a "clean incremental" of `webrender_api`, which reduces the instruction count by about 0.5%. It also reduces instruction counts by up to 1.4% across a range of rustc-perf benchmark runs.
2019-03-13Fix operator precedenceEsteban Küber-2/+2
2019-03-11Be more discerning on when to attempt suggesting a comma in a macro invocationEsteban Küber-3/+5
2019-02-25Restrict value in key-value attributes to literalsVadim Petrochenkov-1/+1
2019-02-18Make `interpolated_to_tokenstream` a method on `Nonterminal`.Nicholas Nethercote-2/+2
2019-02-10rustc: doc commentsAlexander Regueiro-2/+3
2019-02-07libsyntax => 2018Taiki Endo-12/+15
2019-02-06Auto merge of #58061 - nnethercote:overhaul-syntax-Folder, r=petrochenkovbors-1/+1
Overhaul `syntax::fold::Folder`. This PR 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`. This makes the code faster and more concise.
2019-02-06Overhaul `syntax::fold::Folder`.Nicholas Nethercote-1/+1
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-01-30proc_macro: make `TokenStream::from_streams` pre-allocate its vector.Felix S. Klock II-1/+7
This requires a pre-pass over the input streams. But that is cheap compared to the quadratic blowup associated with reallocating the accumulating vector on-the-fly.
2019-01-14Make `TokenStream` use `Option`.Nicholas Nethercote-50/+45
Because that's the more typical way of representing an all-or-nothing type.
2019-01-14Remove `ThinTokenStream`.Nicholas Nethercote-52/+3
`TokenStream` is now almost identical to `ThinTokenStream`. This commit removes the latter, replacing it with the former.
2019-01-14Remove `TokenStream::Tree` variant.Nicholas Nethercote-40/+5
`TokenStream::Stream` can represent a token stream containing any number of token trees. `TokenStream::Tree` is the special case representing a single token tree. The latter doesn't occur all that often dynamically, so this commit removes it, which simplifies the code quite a bit. This change has mixed performance effects. - The size of `TokenStream` drops from 32 bytes to 8 bytes, and there is one less case for all the match statements. - The conversion of a `TokenTree` to a `TokenStream` now requires two allocations, for the creation of a single element Lrc<Vec<_>>. (But a subsequent commit in this PR will reduce the main source of such conversions.)
2019-01-08Make `TokenStream` less recursive.Nicholas Nethercote-323/+127
`TokenStream` is currently recursive in *two* ways: - the `TokenTree` variant contains a `ThinTokenStream`, which can contain a `TokenStream`; - the `TokenStream` variant contains a `Vec<TokenStream>`. The latter is not necessary and causes significant complexity. This commit replaces it with the simpler `Vec<(TokenTree, IsJoint)>`. This reduces complexity significantly. In particular, `StreamCursor` is eliminated, and `Cursor` becomes much simpler, consisting now of just a `TokenStream` and an index. The commit also removes the `Extend` impl for `TokenStream`, because it is only used in tests. (The commit also removes those tests.) Overall, the commit reduces the number of lines of code by almost 200.
2018-12-25Remove licensesMark Rousskov-10/+0
2018-12-23Rollup merge of #56964 - nnethercote:TokenStream-IsJoint, r=petrochenkovMazdak Farrokhzad-51/+42
Remove `TokenStream::JointTree`. This is done by adding a new `IsJoint` field to `TokenStream::Tree`, which simplifies a lot of `match` statements. And likewise for `CursorKind`. The commit also adds a new method `TokenTree:stream()` which can replace a choice between `.into()` and `.joint()`.