about summary refs log tree commit diff
path: root/library/core/src/sync/atomic.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-12-30 07:04:49 +0000
committerbors <bors@rust-lang.org>2020-12-30 07:04:49 +0000
commitb9c403be11bef38638b38012be80444ad3f09dde (patch)
tree493ebc9e7433aa7ab71616eceb90a998b3ba644b /library/core/src/sync/atomic.rs
parentf3eead1c69d5ce9cb128a9068250581ad28103f0 (diff)
parent530a629635030c47f9d7886bb20a1959fa0198db (diff)
downloadrust-b9c403be11bef38638b38012be80444ad3f09dde.tar.gz
rust-b9c403be11bef38638b38012be80444ad3f09dde.zip
Auto merge of #79472 - Aaron1011:new-remove-pretty-print-hack, r=petrochenkov
Replace pretty-print/compare/retokenize hack with targeted workarounds

Based on https://github.com/rust-lang/rust/pull/78296
cc https://github.com/rust-lang/rust/issues/43081

The 'pretty-print/compare/retokenize' hack is used to try to avoid passing an outdated `TokenStream` to a proc-macro when the underlying AST is modified in some way (e.g. cfg-stripping before derives). Unfortunately, retokenizing throws away spans (including hygiene information), which causes issues of its own. Every improvement to the accuracy of the pretty-print/retokenize comparison has resulted in non-trivial ecosystem breakage due to hygiene changes. In extreme cases, users deliberately wrote unhygienic `macro_rules!` macros (likely because they did not realize that the compiler's behavior was a bug).

Additionaly, the comparison between the original and pretty-printed/retoknized token streams comes at a non-trivial runtime cost, as shown by https://github.com/rust-lang/rust/pull/79338

This PR removes the pretty-print/compare/retokenize logic from `nt_to_tokenstream`. We only discard the original `TokenStream` under two circumstances:
* Inner attributes are used (detected by examining the AST)
* `cfg`/`cfg_attr` processing modifies the AST. This is detected by making the visitor update a flag when it performs a modification, instead of trying to detect the modification after-the-fact. Note that a 'matching' `cfg` (e.g. `#[cfg(not(FALSE)]`) does not actually get removed from the AST, allowing us to preserve the original `TokenStream`.

In all other cases, we preserve the original `TokenStream`.

This could use a bit of refactoring/renaming - opening for a Crater run.

r? `@ghost`
Diffstat (limited to 'library/core/src/sync/atomic.rs')
0 files changed, 0 insertions, 0 deletions