rust/compiler/rustc_ast/src
Nicholas Nethercote 1e848a564b Remove TokenStreamBuilder.
`TokenStreamBuilder` exists to concatenate multiple `TokenStream`s
together. This commit removes it, and moves the concatenation
functionality directly into `TokenStream`, via two new methods
`push_tree` and `push_stream`. This makes things both simpler and
faster.

`push_tree` is particularly important. `TokenStreamBuilder` only had a
single `push` method, which pushed a stream. But in practice most of the
time we push a single token tree rather than a stream, and `push_tree`
avoids the need to build a token stream with a single entry (which
requires two allocations, one for the `Lrc` and one for the `Vec`).

The main `push_tree` use arises from a change to one of the `ToInternal`
impls in `proc_macro_server.rs`. It now returns a `SmallVec` instead of
a `TokenStream`. This return value is then iterated over by
`concat_trees`, which does `push_tree` on each element. Furthermore, the
use of `SmallVec` avoids more allocations, because there is always only
one or two token trees.

Note: the removed `TokenStreamBuilder::push` method had some code to
deal with a quadratic blowup case from #57735. This commit removes the
code. I tried and failed to reproduce the blowup from that PR, before
and after this change. Various other changes have happened to
`TokenStreamBuilder` in the meantime, so I suspect the original problem
is no longer relevant, though I don't have proof of this. Generally
speaking, repeatedly extending a `Vec` without pre-determining its
capacity is *not* quadratic. It's also incredibly common, within rustc
and many other Rust programs, so if there were performance problems
there you'd think it would show up in other places, too.
2022-10-05 12:42:54 +11:00
..
attr add debug assertion for max attr_id 2022-09-14 08:49:12 +08:00
expand Make allocator_kind a query. 2021-06-20 11:52:51 +02:00
util more simple formatting 2022-09-16 19:07:42 +08:00
ast_traits.rs Rename {Create,Lazy}TokenStream as {To,Lazy}AttrTokenStream. 2022-09-09 17:25:38 +10:00
ast.rs remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
entry.rs Fixup missing renames from #[main] to #[rustc_main] 2022-06-22 18:24:09 +02:00
lib.rs remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
mut_visit.rs Rename {Create,Lazy}TokenStream as {To,Lazy}AttrTokenStream. 2022-09-09 17:25:38 +10:00
node_id.rs rustc_error, rustc_private, rustc_ast: Switch to stable hash containers 2022-09-10 11:49:12 +02:00
ptr.rs Use delayed error handling for Encodable and Encoder infallible. 2022-06-08 07:01:26 +10:00
token.rs Rewrite Token::is_op. 2022-10-03 11:42:29 +11:00
tokenstream.rs Remove TokenStreamBuilder. 2022-10-05 12:42:54 +11:00
visit.rs Remove unused span argument from walk_fn. 2022-09-12 13:24:27 +10:00