rust/compiler/rustc_session/src
Aaron Hill a93c4f05de
Implement token-based handling of attributes during expansion
This PR modifies the macro expansion infrastructure to handle attributes
in a fully token-based manner. As a result:

* Derives macros no longer lose spans when their input is modified
  by eager cfg-expansion. This is accomplished by performing eager
  cfg-expansion on the token stream that we pass to the derive
  proc-macro
* Inner attributes now preserve spans in all cases, including when we
  have multiple inner attributes in a row.

This is accomplished through the following changes:

* New structs `AttrAnnotatedTokenStream` and `AttrAnnotatedTokenTree` are introduced.
  These are very similar to a normal `TokenTree`, but they also track
  the position of attributes and attribute targets within the stream.
  They are built when we collect tokens during parsing.
  An `AttrAnnotatedTokenStream` is converted to a regular `TokenStream` when
  we invoke a macro.
* Token capturing and `LazyTokenStream` are modified to work with
  `AttrAnnotatedTokenStream`. A new `ReplaceRange` type is introduced, which
  is created during the parsing of a nested AST node to make the 'outer'
  AST node aware of the attributes and attribute target stored deeper in the token stream.
* When we need to perform eager cfg-expansion (either due to `#[derive]` or `#[cfg_eval]`),
we tokenize and reparse our target, capturing additional information about the locations of
`#[cfg]` and `#[cfg_attr]` attributes at any depth within the target.
This is a performance optimization, allowing us to perform less work
in the typical case where captured tokens never have eager cfg-expansion run.
2021-04-11 01:31:36 -04:00
..
cgu_reuse_tracker.rs mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
code_stats.rs mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
config.rs Don't tell users to use a nightly flag on the stable channel 2021-04-10 13:35:35 +01:00
filesearch.rs fix review 2021-02-25 04:21:12 +03:00
lib.rs Move SanitizerSet to rustc_target 2021-04-03 00:37:49 +03:00
options.rs Rollup merge of #82483 - tmiasko:option-from-str, r=matthewjasper 2021-04-05 13:03:37 +02:00
output.rs Collapse all uses of target.options.foo into target.foo 2020-11-08 17:29:13 +03:00
parse.rs Remove (lots of) dead code 2021-03-27 22:16:33 -04:00
search_paths.rs use strip_prefix over starts_with and manual slicing based on pattern length (clippy::manual_strip) 2020-09-17 10:13:16 +02:00
session.rs Maintain supported sanitizers as a target property 2021-04-03 00:37:49 +03:00
utils.rs Implement token-based handling of attributes during expansion 2021-04-11 01:31:36 -04:00