Uh oh!
There was an error while loading. Please reload this page.
Implement token-based handling of attributes during expansion - #82608
Conversation
Aaron1011
commented
Feb 27, 2021
@bors try @rust-timer queue |
rust-timer
commented
Feb 27, 2021
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
bors
commented
Feb 27, 2021
⌛ Trying commit ac71b40b84add10df1cc6b4394ca53f5c3bfe16d with merge b86108850e24b4dd26ad05cb34d04ef489f2385a... |
bors
commented
Feb 27, 2021
☀️ Try build successful - checks-actions |
rust-timer
commented
Feb 27, 2021
Queued b86108850e24b4dd26ad05cb34d04ef489f2385a with parent ec7f8d9, future comparison URL. |
rust-timer
commented
Feb 27, 2021
Finished benchmarking try commit (b86108850e24b4dd26ad05cb34d04ef489f2385a): comparison url. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up. @bors rollup=never |
petrochenkov
commented
Feb 28, 2021
@Aaron1011 |
Aaron1011
commented
Feb 28, 2021
@petrochenkov Sure |
Aaron1011
commented
Feb 28, 2021
Opened #82643 |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
petrochenkov
commented
Feb 28, 2021
(Still need to review changes in |
ac71b40 to
87977c6CompareAaron1011
commented
Feb 28, 2021
@bors try @rust-timer queue |
rust-timer
commented
Feb 28, 2021
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
bors
commented
Feb 28, 2021
⌛ Trying commit 87977c6a776ca0b4075f0998bde21267b3addcd6 with merge f1c431c58af7789983cbdfd61c470034c37eb631... |
bors
commented
Feb 28, 2021
☀️ Try build successful - checks-actions |
rust-timer
commented
Feb 28, 2021
Queued f1c431c58af7789983cbdfd61c470034c37eb631 with parent 573a697, future comparison URL. |
rust-timer
commented
Mar 1, 2021
Finished benchmarking try commit (f1c431c58af7789983cbdfd61c470034c37eb631): comparison url. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up. @bors rollup=never |
Aaron1011
commented
Mar 1, 2021
There appears to be a significant hit from being unable to bail out early from
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Aaron1011
commented
Apr 11, 2021
I've rebased against master - this should now be ready to merge. |
petrochenkov
commented
Apr 11, 2021
r=me with commits squashed. |
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.
Aaron1011
commented
Apr 11, 2021
@bors r=petrochenkov |
bors
commented
Apr 11, 2021
📌 Commit a93c4f0 has been approved by |
bors
commented
Apr 11, 2021
bors
commented
Apr 11, 2021
☀️ Test successful - checks-actions |
EliaGeretto
commented
Apr 12, 2021
I believe this PR introduced a regression, breaking the |
Aaron1011
commented
Apr 12, 2021
@EliaGeretto: Thanks for finding that! I've opened #84130 to fix it |
This PR modifies the macro expansion infrastructure to handle attributes
in a fully token-based manner. As a result:
by eager cfg-expansion. This is accomplished by performing eager
cfg-expansion on the token stream that we pass to the derive
proc-macro
have multiple inner attributes in a row.
This is accomplished through the following changes:
AttrAnnotatedTokenStreamandAttrAnnotatedTokenTreeare introduced.These are very similar to a normal
TokenTree, but they also trackthe position of attributes and attribute targets within the stream.
They are built when we collect tokens during parsing.
An
AttrAnnotatedTokenStreamis converted to a regularTokenStreamwhenwe invoke a macro.
LazyTokenStreamare modified to work withAttrAnnotatedTokenStream. A newReplaceRangetype is introduced, whichis 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.
#[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.