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

try to downgrade Arc -> Lrc -> Rc -> no-Rc in few places #111014

Merged
merged 3 commits into from
May 4, 2023

Conversation

klensy
Copy link
Contributor

@klensy klensy commented Apr 30, 2023

Expecting this be not slower on non-parallel compiler and probably faster on parallel (checked that this PR builds on it).

@rustbot
Copy link
Collaborator

rustbot commented Apr 30, 2023

r? @WaffleLapkin

(rustbot has picked a reviewer for you, use r? to override)

@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 Apr 30, 2023
Copy link
Member

@WaffleLapkin WaffleLapkin left a comment

Choose a reason for hiding this comment

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

a couple of nits

/// processing sequences. Mostly for sequence-ending possibilities that must be tried but end
/// up failing.
matches: Lrc<Vec<NamedMatch>>,
matches: Rc<Vec<NamedMatch>>,
Copy link
Member

Choose a reason for hiding this comment

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

could this be Rc<[NamedMatch]>? would it be better?

Copy link
Contributor Author

@klensy klensy May 4, 2023

Choose a reason for hiding this comment

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

Maybe. I've tried to only change rc stuff. This thing noted as hot, so changing vec<->slice can potentially shadow other changes. @nnethercote changed this last time, maybe he already tried that and found, that there no gains?

Copy link
Member

Choose a reason for hiding this comment

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

Okay, we can leave those nits for the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

I just tried it, there are tons of problems.

error[E0277]: the trait bound `[NamedMatch]: Clone` is not satisfied
    --> compiler/rustc_expand/src/mbe/macro_parser.rs:275:37
     |
275  |         let matches = Lrc::make_mut(&mut self.matches);
     |                       ------------- ^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `[NamedMatch]`
     |                       |
     |                       required by a bound introduced by this call
     |
     = help: the trait `Clone` is implemented for `[T; N]`
note: required by a bound in `Lrc::<T>::make_mut`
    --> /home/njn/dev/rust1/library/alloc/src/rc.rs:1191:9
     |
1191 | impl<T: Clone> Rc<T> {
     |         ^^^^^ required by this bound in `Rc::<T>::make_mut`

error[E0599]: no method named `push` found for mutable reference `&mut [NamedMatch]` in the current scope
   --> compiler/rustc_expand/src/mbe/macro_parser.rs:280:25
    |
280 |                 matches.push(m);
    |                         ^^^^ method not found in `&mut [NamedMatch]`

error[E0277]: the trait bound `[NamedMatch]: Clone` is not satisfied
    --> compiler/rustc_expand/src/mbe/macro_parser.rs:591:35
     |
591  |                     Lrc::make_mut(&mut eof_mp.matches);
     |                     ------------- ^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `[NamedMatch]`
     |                     |
     |                     required by a bound introduced by this call
     |
     = help: the trait `Clone` is implemented for `[T; N]`
note: required by a bound in `Lrc::<T>::make_mut`
    --> /home/njn/dev/rust1/library/alloc/src/rc.rs:1191:9
     |
1191 | impl<T: Clone> Rc<T> {
     |         ^^^^^ required by this bound in `Rc::<T>::make_mut`

error[E0277]: the size for values of type `[NamedMatch]` cannot be known at compilation time
   --> compiler/rustc_expand/src/mbe/macro_parser.rs:592:51
    |
592 |                     let matches = Lrc::try_unwrap(eof_mp.matches).unwrap().into_iter();
    |                                   --------------- ^^^^^^^^^^^^^^ doesn't have a size known at compile-time
    |                                   |
    |                                   required by a bound introduced by this call
    |
    = help: the trait `Sized` is not implemented for `[NamedMatch]`
note: required by a bound in `Lrc::<T>::try_unwrap`
   --> /home/njn/dev/rust1/library/alloc/src/rc.rs:360:6
    |
360 | impl<T> Rc<T> {
    |      ^ required by this bound in `Rc::<T>::try_unwrap`

error[E0599]: the method `unwrap` exists for enum `Result<[NamedMatch], Rc<[NamedMatch]>>`, but its trait bounds were not satisfied
   --> compiler/rustc_expand/src/mbe/macro_parser.rs:592:67
    |
592 |                     let matches = Lrc::try_unwrap(eof_mp.matches).unwrap().into_iter();
    |                                                                   ^^^^^^ method cannot be called on `Result<[NamedMatch], Rc<[NamedMatch]>>` due to unsatisfied trait bounds
    |
    = note: the following trait bounds were not satisfied:
            `[NamedMatch]: Sized`

error[E0277]: the size for values of type `[NamedMatch]` cannot be known at compilation time
   --> compiler/rustc_expand/src/mbe/macro_parser.rs:592:35
    |
592 |                     let matches = Lrc::try_unwrap(eof_mp.matches).unwrap().into_iter();
    |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
    |
    = help: the trait `Sized` is not implemented for `[NamedMatch]`
note: required by a bound in `Result`
   --> /home/njn/dev/rust1/library/core/src/result.rs:502:17
    |
502 | pub enum Result<T, E> {
    |                 ^ required by this bound in `Result`

error[E0308]: mismatched types
   --> compiler/rustc_expand/src/mbe/macro_parser.rs:625:57
    |
625 |         self.cur_mps.push(MatcherPos { idx: 0, matches: self.empty_matches.clone() });
    |                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Rc<[NamedMatch]>`, found `Rc<Vec<NamedMatch>>`
    |
    = note: expected struct `Lrc<[NamedMatch]>`
               found struct `Lrc<Vec<NamedMatch>>`

Copy link
Member

Choose a reason for hiding this comment

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

Ugh. Clone requiring Sized was a mistake :(

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps, but that's not the only problem here.

Comment on lines +592 to +593
Rc::make_mut(&mut eof_mp.matches);
let matches = Rc::try_unwrap(eof_mp.matches).unwrap().into_iter();
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to just

Suggested change
Rc::make_mut(&mut eof_mp.matches);
let matches = Rc::try_unwrap(eof_mp.matches).unwrap().into_iter();
let matches = Rc::make_mut(&mut eof_mp.matches).take().into_iter();

or even

Suggested change
Rc::make_mut(&mut eof_mp.matches);
let matches = Rc::try_unwrap(eof_mp.matches).unwrap().into_iter();
eof_mp.matches.iter().cloned()

@WaffleLapkin
Copy link
Member

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented May 4, 2023

📌 Commit 0726636 has been approved by WaffleLapkin

It is now in the queue for this repository.

@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 May 4, 2023
@bors
Copy link
Contributor

bors commented May 4, 2023

⌛ Testing commit 0726636 with merge 74c4821...

@nnethercote
Copy link
Contributor

@klensy: how did you find these? Did you just spot them manually, or did you have some kind of process for finding them?

@klensy
Copy link
Contributor Author

klensy commented May 4, 2023

@klensy: how did you find these? Did you just spot them manually, or did you have some kind of process for finding them?

Manual process: switched build to parallel = true, walked over Arc - Lrc - Rc (there not so many places with them), an tried to use next rc kind, if it looks easy and don't lead to rewriting more than i want. There more things probably can be rewritten, for example in RegionInferenceContext.

@bors
Copy link
Contributor

bors commented May 4, 2023

☀️ Test successful - checks-actions
Approved by: WaffleLapkin
Pushing 74c4821 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 4, 2023
@bors bors merged commit 74c4821 into rust-lang:master May 4, 2023
@rustbot rustbot added this to the 1.71.0 milestone May 4, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (74c4821): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

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

Max RSS (memory usage)

Results

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)
4.2% [3.7%, 4.6%] 2
Regressions ❌
(secondary)
2.9% [2.9%, 2.9%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.4% [-2.4%, -2.4%] 1
All ❌✅ (primary) 4.2% [3.7%, 4.6%] 2

Cycles

Results

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

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

Bootstrap: 657.762s -> 654.9s (-0.44%)

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.

6 participants