Commit Graph

106 Commits

Author SHA1 Message Date
Vadim Petrochenkov
09703e3843 Adjust other names after the Mark renaming 2019-07-19 12:01:49 +03:00
Vadim Petrochenkov
31e10aec83 libsyntax: Remove Mark into ExpnId 2019-07-19 12:01:48 +03:00
Mark Rousskov
8a7dded1a2 Switch master to 1.38 2019-07-04 11:26:57 -04:00
Felix S Klock II
0baa9258dd
put back the workarounds for #60846
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-14 12:19:26 +02:00
Niko Matsakis
6fdcc8281a remove hacks that are no longer needed 2019-06-12 13:56:29 -04:00
Vadim Petrochenkov
25b05147b3 syntax: Remove Deref impl from Token 2019-06-08 22:38:23 +03:00
Vadim Petrochenkov
0ca3c2f881 syntax: Move most of the TokenKind methods to Token 2019-06-08 22:38:12 +03:00
Vadim Petrochenkov
ff40e37b98 Some code cleanup and tidy/test fixes 2019-06-06 14:04:02 +03:00
Vadim Petrochenkov
67ce3f4589 syntax: Switch function parameter order in TokenTree::token 2019-06-06 14:04:02 +03:00
Vadim Petrochenkov
f745e5f9b6 syntax: Remove duplicate span from token::Ident 2019-06-06 14:04:02 +03:00
Vadim Petrochenkov
5e693531ff syntax: Add some helper methods to Token 2019-06-06 14:04:02 +03:00
Vadim Petrochenkov
e0127dbf81 syntax: Use Token in TokenTree::Token 2019-06-06 14:03:15 +03:00
Vadim Petrochenkov
a3425edb46 syntax: Rename TokenAndSpan into Token 2019-06-06 14:03:15 +03:00
Vadim Petrochenkov
99b27d749c syntax: Rename Token into TokenKind 2019-06-06 14:03:14 +03:00
Vadim Petrochenkov
eac3846b65 Always use token kinds through token module rather than Token type 2019-06-06 14:01:57 +03:00
John Kåre Alsaker
3ed05613ee Short circuit Send and Sync impls for TokenTree 2019-05-27 08:58:05 +02:00
John Kåre Alsaker
a1f2dceaeb Move edition outside the hygiene lock and avoid accessing it 2019-05-21 18:17:05 +02:00
Vadim Petrochenkov
88fa5c6a45 Improve type size assertions
Now they
- Tell what the new size is, when it changes
- Do not require passing an identifier
2019-05-19 13:59:44 +03:00
Esteban Küber
0e505d427a Add guard for missing comma in macro call suggestion 2019-04-24 16:45:29 -07:00
Nicholas Nethercote
17a8aff20a Use SmallVec in TokenStreamBuilder.
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-29 09:32:58 +11:00
Esteban Küber
27abd52170 Fix operator precedence 2019-03-13 00:10:16 -07:00
Esteban Küber
b9d12edd6c Be more discerning on when to attempt suggesting a comma in a macro invocation 2019-03-11 15:07:07 -07:00
Vadim Petrochenkov
8e1b5d897a Restrict value in key-value attributes to literals 2019-02-25 22:40:38 +03:00
Nicholas Nethercote
82ad4f1f45 Make interpolated_to_tokenstream a method on Nonterminal. 2019-02-18 10:06:26 +11:00
Alexander Regueiro
c3e182cf43 rustc: doc comments 2019-02-10 23:42:32 +00:00
Taiki Endo
7bb082d27f libsyntax => 2018 2019-02-07 02:33:01 +09:00
bors
2596bc1368 Auto merge of #58061 - nnethercote:overhaul-syntax-Folder, r=petrochenkov
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-06 06:01:37 +00:00
Nicholas Nethercote
9fcb1658ab 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.
2019-02-06 09:06:27 +11:00
Felix S. Klock II
1a18336808 proc_macro: make TokenStream::from_streams pre-allocate its vector.
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-30 15:12:41 +01:00
Nicholas Nethercote
7285724401 Make TokenStream use Option.
Because that's the more typical way of representing an all-or-nothing
type.
2019-01-14 11:05:56 +11:00
Nicholas Nethercote
ce0d9949b8 Remove ThinTokenStream.
`TokenStream` is now almost identical to `ThinTokenStream`. This commit
removes the latter, replacing it with the former.
2019-01-14 09:10:26 +11:00
Nicholas Nethercote
28966e1a7a Remove TokenStream::Tree variant.
`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-14 09:10:26 +11:00
Nicholas Nethercote
e80a93040f Make TokenStream less recursive.
`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.
2019-01-08 15:08:46 +11:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Mazdak Farrokhzad
61f50d9d2e
Rollup merge of #56964 - nnethercote:TokenStream-IsJoint, r=petrochenkov
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()`.
2018-12-23 23:09:07 +01:00
Nicholas Nethercote
e7c5146c5d 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()`.
2018-12-20 10:18:16 +11:00
Vadim Petrochenkov
f756257fb7 Do not interpret mismatches from pretty-printed $crate as token stream invalidation 2018-12-19 23:17:54 +03:00
Nicholas Nethercote
e80c7ddb05 Rename TokenStream::concat and remove TokenStream::concat_rc_vec.
`TokenStream::new` is a better name for the former, and the latter is
now just equivalent to `TokenStream::Stream`.
2018-12-12 20:36:00 +11:00
Nicholas Nethercote
07c12fa89e Merge TokenStreamKind into TokenStream.
Because the distinction provides little value, and removing it cleans up
the code quite a bit.
2018-12-12 20:36:00 +11:00
Nicholas Nethercote
3c9aef1f45 Use TokenStream::concat more.
It's a better choice in a few places.
2018-12-12 20:36:00 +11:00
Nicholas Nethercote
67f8fb5960 Use Lrc<Vec<TokenStream>> instead of RcVec<TokenStream>.
This shrinks:
- ThinTokenStream: 16 to 8 bytes
- TokenTree: 32 to 24 bytes
- TokenStream: 40 to 32 bytes

The only downside is that in a couple of places this requires using
`to_vec()` (which allocates) instead of `sub_slice()`. But those places
are rarely executed, so it doesn't hurt perf.

Overall, this reduces instruction counts on numerous benchmarks by up to
3%.
2018-12-12 20:36:00 +11:00
Nicholas Nethercote
1fe2c03240 Remove tokenstream::Delimited.
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-10 12:10:10 +11:00
bors
5aff30734b Auto merge of #55971 - SergioBenitez:skip-non-semantic, r=alexcrichton
Ignore non-semantic tokens for 'probably_eq' streams.

Improves the situation in #43081 by skipping typically non-semantic tokens when checking for 'probably_eq'.

r? @alexcrichton
2018-11-19 19:57:02 +00:00
Sergio Benitez
78eb516dda Ignore non-semantic tokens for 'probably_eq' streams. 2018-11-16 23:37:23 -08:00
Andy Russell
4e35cbb22e
fix various typos in doc comments 2018-11-13 14:45:31 -05:00
ljedrz
d28aed6dc4 Prefer unwrap_or_else to unwrap_or in case of function calls/allocations 2018-10-19 09:45:45 +02:00
David Tolnay
a1dd39e724
Track distinct spans for open and close delimiter 2018-09-08 19:01:48 -07:00
David Tolnay
2fa1da9919
TokenStream::extend 2018-08-12 22:45:32 -07:00
Esteban Küber
f4039affa3 Suggest comma when missing in macro call
When missing a comma in a macro call, suggest it, regardless of
position. When a macro call doesn't match any of the patterns, check
if the call's token stream could be missing a comma between two idents,
and if so, create a new token stream containing the comma and try to
match against the macro patterns. If successful, emit the suggestion.
2018-08-07 22:31:57 -07:00
Esteban Küber
daa5bd35a8 fix typo 2018-08-06 23:46:28 -07:00