Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double handling in collect_tokens #129346

Merged

Conversation

nnethercote
Copy link
Contributor

Double handling of AST nodes can occur in collect_tokens. This is when an inner call to collect_tokens produces an AST node, and then an outer call to collect_tokens produces the same AST node. This can happen in a few places, e.g. expression statements where the statement delegates HasTokens and HasAttrs to the expression. It will also happen more after #124141.

This PR fixes some double handling cases that cause problems, including #129166.

r? @petrochenkov

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 21, 2024
@nnethercote
Copy link
Contributor Author

The last three commits are tricky and hard to review. Even after multiple weeks of working with this code, I still find it hard to understand and reason about, and I wish it could be made simpler. But the good news is that these commits are enough to the get final failing test (tests/ui/proc-macros/macro-rules-derive-cfg.rs) working in #124141.

@rust-log-analyzer

This comment has been minimized.

@nnethercote nnethercote force-pushed the fix-double-handling-in-collect_tokens branch from a0f9bfd to 7d65809 Compare August 21, 2024 07:44
@nnethercote
Copy link
Contributor Author

I think this should get a crater run, just because I don't fully trust that the test suite is thoroughly testing cfg_attr stuff.

And why not do a perf run, just to check there's no regressions.

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 21, 2024
@bors
Copy link
Contributor

bors commented Aug 21, 2024

⌛ Trying commit 7d65809 with merge 8b22b49...

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 21, 2024
…ollect_tokens, r=<try>

Fix double handling in `collect_tokens`

Double handling of AST nodes can occur in `collect_tokens`. This is when an inner call to `collect_tokens` produces an AST node, and then an outer call to `collect_tokens` produces the same AST node. This can happen in a few places, e.g. expression statements where the statement delegates `HasTokens` and `HasAttrs` to the expression. It will also happen more after rust-lang#124141.

This PR fixes some double handling cases that cause problems, including rust-lang#129166.

r? `@petrochenkov`
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Aug 21, 2024

☀️ Try build successful - checks-actions
Build commit: 8b22b49 (8b22b49ea046aed5d405c5bda40972c039aa70b5)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8b22b49): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.3% [0.2%, 0.7%] 43
Regressions ❌
(secondary)
0.4% [0.1%, 0.6%] 16
Improvements ✅
(primary)
-0.3% [-0.3%, -0.3%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [-0.3%, 0.7%] 44

Max RSS (memory usage)

Results (secondary -2.7%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.7% [-3.4%, -2.0%] 2
All ❌✅ (primary) - - 0

Cycles

Results (secondary -2.3%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.3% [-2.3%, -2.3%] 1
All ❌✅ (primary) - - 0

Binary size

Results (secondary 0.0%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Bootstrap: 748.876s -> 749.555s (0.09%)
Artifact size: 338.91 MiB -> 338.99 MiB (0.02%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Aug 21, 2024
@petrochenkov
Copy link
Contributor

Which change is a source of the perf regression, 7d65809 probably?
All the others look like optimizations.

@petrochenkov
Copy link
Contributor

I'll start crater once #129346 (comment) is addressed and CI is green.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 21, 2024
@nnethercote nnethercote force-pushed the fix-double-handling-in-collect_tokens branch from 7d65809 to aeaa62b Compare August 21, 2024 22:54
@nnethercote
Copy link
Contributor Author

I have adding a commit that avoids cloning ret.attrs() except when necessary. This gets back part of the perf regression. The rest is due to Parser::clone being more expensive because of the new FxHashSet in CaptureState. I tried changing it to a GrowableBitSet which seemed like it should have helped but didn't.

Let's see what the new status is:
@bors try @rust-time queue

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 22, 2024
…ollect_tokens, r=<try>

Fix double handling in `collect_tokens`

Double handling of AST nodes can occur in `collect_tokens`. This is when an inner call to `collect_tokens` produces an AST node, and then an outer call to `collect_tokens` produces the same AST node. This can happen in a few places, e.g. expression statements where the statement delegates `HasTokens` and `HasAttrs` to the expression. It will also happen more after rust-lang#124141.

This PR fixes some double handling cases that cause problems, including rust-lang#129166.

r? `@petrochenkov`
@bors
Copy link
Contributor

bors commented Aug 22, 2024

⌛ Trying commit cab3178 with merge a70947b...

@bors
Copy link
Contributor

bors commented Aug 22, 2024

☀️ Try build successful - checks-actions
Build commit: a70947b (a70947b8062a88e6f76266f2540de6ea6c2bfba5)

@lqd
Copy link
Member

lqd commented Aug 22, 2024

@rust-timer build a70947b

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (a70947b): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.3% [0.2%, 0.7%] 25
Regressions ❌
(secondary)
0.4% [0.2%, 0.6%] 17
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [0.2%, 0.7%] 25

Max RSS (memory usage)

Results (primary -0.8%, secondary 2.4%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.9% [0.5%, 1.3%] 2
Regressions ❌
(secondary)
2.4% [2.1%, 2.7%] 2
Improvements ✅
(primary)
-4.3% [-4.3%, -4.3%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.8% [-4.3%, 1.3%] 3

Cycles

Results (secondary 2.3%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.3% [2.3%, 2.3%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

Results (secondary -0.1%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.1%] 1
All ❌✅ (primary) - - 0

Bootstrap: 750.761s -> 751.313s (0.07%)
Artifact size: 338.92 MiB -> 339.03 MiB (0.03%)

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 7, 2024
@bors
Copy link
Contributor

bors commented Sep 8, 2024

⌛ Testing commit d4bf28c with merge 6d05f12...

@bors
Copy link
Contributor

bors commented Sep 8, 2024

☀️ Test successful - checks-actions
Approved by: petrochenkov
Pushing 6d05f12 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 8, 2024
@bors bors merged commit 6d05f12 into rust-lang:master Sep 8, 2024
7 checks passed
@rustbot rustbot added this to the 1.83.0 milestone Sep 8, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6d05f12): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.3% [0.3%, 0.3%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.4% [-0.4%, -0.3%] 2
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -1.9%, secondary 1.9%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.6% [2.6%, 2.6%] 1
Regressions ❌
(secondary)
3.0% [2.3%, 4.2%] 7
Improvements ✅
(primary)
-3.4% [-3.5%, -3.4%] 3
Improvements ✅
(secondary)
-0.7% [-0.7%, -0.6%] 3
All ❌✅ (primary) -1.9% [-3.5%, 2.6%] 4

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 754.658s -> 756.515s (0.25%)
Artifact size: 341.04 MiB -> 341.16 MiB (0.04%)

@rustbot rustbot removed the perf-regression Performance regression. label Sep 8, 2024
@nnethercote nnethercote deleted the fix-double-handling-in-collect_tokens branch September 8, 2024 22:13
@danielhenrymantilla
Copy link
Contributor

FWIW, this did regress the following test: https://docs.rs/crate/cfg_eval/0.1.2/source/tests/item.rs

I don't know why crater did not see it 😔

Comment on lines -17 to -22
struct Foo {
val: [bool; {
let a = #[cfg_attr(not(FALSE), rustc_dummy(first))] $expr;
0
}]
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case stopped working?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #132587.

@Noratrieb
Copy link
Member

even if crater found your crate, it was only a check run

nnethercote added a commit to nnethercote/rust that referenced this pull request Nov 4, 2024
It caused a test regression in the `cfg_eval.rs` crate. (The bugfix
in rust-lang#129346 was in a different commit; this commit was just a code
simplification.)
nnethercote added a commit to nnethercote/rust that referenced this pull request Nov 4, 2024
It caused a test regression in the `cfg_eval.rs` crate. (The bugfix
in rust-lang#129346 was in a different commit; this commit was just a code
simplification.)
@lqd
Copy link
Member

lqd commented Nov 4, 2024

even if crater found your crate, it was only a check run

and since beta runs are test runs, the regression is indeed present in the 1.83 unexpected test failures: https://crater-reports.s3.amazonaws.com/beta-1.83-1/beta-2024-10-19/gh/danielhenrymantilla.cfg_eval.rs/log.txt

workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Nov 4, 2024
…placement-ranges, r=petrochenkov

Revert "Avoid nested replacement ranges" from rust-lang#129346.

It caused a test regression in the `cfg_eval.rs` crate. (The bugfix in rust-lang#129346 was in a different commit; this commit was just a code simplification.)

r? `@petrochenkov`
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 4, 2024
…kingjubilee

Rollup of 10 pull requests

Successful merges:

 - rust-lang#129884 (mark some target features as 'forbidden' so they cannot be (un)set with -Ctarget-feature)
 - rust-lang#132153 (Stabilise `const_char_encode_utf16`.)
 - rust-lang#132473 ([core/fmt] Replace checked slice indexing by unchecked to support panic-free code)
 - rust-lang#132571 (add const_eval_select macro to reduce redundancy)
 - rust-lang#132587 (Revert "Avoid nested replacement ranges" from rust-lang#129346.)
 - rust-lang#132596 ([rustdoc] Fix `--show-coverage` when JSON output format is used)
 - rust-lang#132598 (Clippy: Move some attribute lints to be early pass (post expansion))
 - rust-lang#132601 (Update books)
 - rust-lang#132606 (Improve example of `impl Pattern for &[char]`)
 - rust-lang#132609 (docs: fix grammar in doc comment at unix/process.rs)

r? `@ghost`
`@rustbot` modify labels: rollup
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Nov 5, 2024
…placement-ranges, r=petrochenkov

Revert "Avoid nested replacement ranges" from rust-lang#129346.

It caused a test regression in the `cfg_eval.rs` crate. (The bugfix in rust-lang#129346 was in a different commit; this commit was just a code simplification.)

r? `@petrochenkov`
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 5, 2024
…kingjubilee

Rollup of 11 pull requests

Successful merges:

 - rust-lang#131153 (Improve duplicate derive Copy/Clone diagnostics)
 - rust-lang#132025 (fix suggestion for diagnostic error E0027)
 - rust-lang#132303 (More tests for non-exhaustive C-like enums in FFI)
 - rust-lang#132492 (remove support for extern-block const intrinsics)
 - rust-lang#132587 (Revert "Avoid nested replacement ranges" from rust-lang#129346.)
 - rust-lang#132596 ([rustdoc] Fix `--show-coverage` when JSON output format is used)
 - rust-lang#132598 (Clippy: Move some attribute lints to be early pass (post expansion))
 - rust-lang#132601 (Update books)
 - rust-lang#132606 (Improve example of `impl Pattern for &[char]`)
 - rust-lang#132608 (document `type_implements_trait`)
 - rust-lang#132609 (docs: fix grammar in doc comment at unix/process.rs)

r? `@ghost`
`@rustbot` modify labels: rollup
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 5, 2024
Rollup merge of rust-lang#132587 - nnethercote:revert-avoid-nested-replacement-ranges, r=petrochenkov

Revert "Avoid nested replacement ranges" from rust-lang#129346.

It caused a test regression in the `cfg_eval.rs` crate. (The bugfix in rust-lang#129346 was in a different commit; this commit was just a code simplification.)

r? `@petrochenkov`
cuviper pushed a commit to cuviper/rust that referenced this pull request Nov 7, 2024
It caused a test regression in the `cfg_eval.rs` crate. (The bugfix
in rust-lang#129346 was in a different commit; this commit was just a code
simplification.)

(cherry picked from commit 981dc02)
@cuviper cuviper mentioned this pull request Nov 7, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 8, 2024
[beta] backports

- rustdoc: skip stability inheritance for some item kinds rust-lang#132481
- Avoid use imports in thread_local_inner! in static rust-lang#132101
- Also treat `impl` definition parent as transparent regarding modules rust-lang#132453
- Revert "Avoid nested replacement ranges" from rust-lang#129346. rust-lang#132587

r? cuviper
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 8, 2024
[beta] backports

- rustdoc: skip stability inheritance for some item kinds rust-lang#132481
- Avoid use imports in thread_local_inner! in static rust-lang#132101
- Also treat `impl` definition parent as transparent regarding modules rust-lang#132453
- Revert "Avoid nested replacement ranges" from rust-lang#129346. rust-lang#132587

r? cuviper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants