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

alloc: add some try_* methods Rust-for-Linux needs #86938

Closed

Conversation

Ericson2314
Copy link
Contributor

@Ericson2314 Ericson2314 commented Jul 7, 2021

Based off of Rust-for-Linux/linux@487d757

I also added a second commit to dedup the code using the new try_ ones in the old infallible ones.
I hope this doesn't cause performance issues, but I am not sure.

I didn't yet dedup the specialization traits, simply because I am less familiar with them. If that is desired, I'll do it too.

CC @joshtriplett @TimDiekmann

@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 7, 2021
Comment on lines +87 to +115
/// Panic, or worse, according to the global handlers for each case.
pub(crate) fn handle(self) -> ! {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might be useful to expose this outside the crate, but I didn't get into that for now.

Comment on lines +206 to +225
match Self::try_allocate_in(capacity, init, alloc) {
Ok(r) => r,
Err(e) => e.handle(),
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I saw some comment about unwrap_or_else slowing doing the LLVM portion of compilation so I didn't use it, but if that is no longer the case I am happy to change these.

@rust-log-analyzer

This comment has been minimized.

library/alloc/src/raw_vec.rs Outdated Show resolved Hide resolved
@joshtriplett
Copy link
Member

For the file-length tidy check, I'd suggest just adding // ignore-tidy-filelength for now.

@joshtriplett
Copy link
Member

Once this passes CI, we can do a try build and a perf run, to see if deduplicating the non-try methods causes a noticeable performance impact.

@Ericson2314 Ericson2314 force-pushed the more-try-methods-0 branch from f5f6357 to e2dfe01 Compare July 7, 2021 15:00
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@Ericson2314 Ericson2314 force-pushed the more-try-methods-0 branch from 77ea711 to fa2063b Compare July 7, 2021 16:40
@rust-log-analyzer

This comment has been minimized.

@the8472
Copy link
Member

the8472 commented Jul 7, 2021

Once this passes CI, we can do a try build and a perf run, to see if deduplicating the non-try methods causes a noticeable performance impact.

It looks like these will change both inlining and where the panic is called. In the past Vec code has been quite sensitive even to minor perturbations in this area. This is going to be interesting.

@Ericson2314
Copy link
Contributor Author

It's stuff like this that makes me wish one could #[inline_always] f(x) a specific call even if a function isn't normally inlined.

@Mark-Simulacrum
Copy link
Member

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

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

bors commented Jul 11, 2021

⌛ Trying commit fa2063bc810fab690f0f7d76dbd12ffa8a70e6f6 with merge 27957d81236ab9a355af3d1636314f8272e8ab11...

@Ericson2314
Copy link
Contributor Author

Huh I thought i ran the formatter. Will fix and rebase.

@rust-log-analyzer

This comment has been minimized.

Ericson2314 referenced this pull request in Rust-for-Linux/linux Jul 11, 2021
In preparation for enabling `no_global_oom_handling` for `alloc`,
we need to add some new methods.

They are all marked as:

    #[stable(feature = "kernel", since = "1.0.0")]

for easy identification.

Signed-off-by: Miguel Ojeda <[email protected]>
@Mark-Simulacrum
Copy link
Member

@rust-timer build 27957d81236ab9a355af3d1636314f8272e8ab11

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jul 14, 2021
@JohnCSimon JohnCSimon 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 Jul 31, 2021
@JohnCSimon
Copy link
Member

ping from triage:
@Ericson2314 can you please address the build failures?

@bors
Copy link
Contributor

bors commented Aug 7, 2021

☔ The latest upstream changes (presumably #87408) made this pull request unmergeable. Please resolve the merge conflicts.

@JohnCSimon
Copy link
Member

ping again from triage:
@Ericson2314 can you please address the build failures?

@rust-log-analyzer

This comment has been minimized.

@JohnCSimon JohnCSimon 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 6, 2021
@the8472 the8472 added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Sep 8, 2021
@JohnCSimon
Copy link
Member

ping from triage:
@Ericson2314 there are still build failures

@JohnCSimon
Copy link
Member

ping again from triage:
@Ericson2314 there are still build failures, after you've addressed them, can you set S-waiting-on-review?

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
    Checking alloc v0.0.0 (/checkout/library/alloc)
    Checking cfg-if v0.1.10
    Checking adler v0.2.3
    Checking rustc-demangle v0.1.21
error[E0433]: failed to resolve: use of undeclared type `TryReserveErrorKind`
    |
    |
245 |             Err(_) => return Err(TryReserveErrorKind::AllocError { layout, non_exhaustive: () }),
    |                                  ^^^^^^^^^^^^^^^^^^^ use of undeclared type `TryReserveErrorKind`

error[E0433]: failed to resolve: use of undeclared type `TryReserveErrorKind`
     |
     |
1218 |             .map_err(|_| TryReserveErrorKind::AllocError { layout, non_exhaustive: () })
     |                          ^^^^^^^^^^^^^^^^^^^ use of undeclared type `TryReserveErrorKind`

error[E0433]: failed to resolve: use of undeclared type `TryReserveErrorKind`
    |
    |
105 |             Err(TryReserveErrorKind::CapacityOverflow)
    |                 ^^^^^^^^^^^^^^^^^^^ use of undeclared type `TryReserveErrorKind`
error[E0308]: mismatched types
   --> library/alloc/src/collections/mod.rs:117:13
    |
92  |     CapacityOverflow,
92  |     CapacityOverflow,
    |     ---------------- unit variant defined here
...
116 |         match self {
    |               ---- this expression has type `TryReserveError`
117 |             TryReserveErrorKind::CapacityOverflow => capacity_overflow(),
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `TryReserveError`, found enum `TryReserveErrorKind`
    |
help: you might have meant to use field `kind` whose type is `TryReserveErrorKind`
116 |         match self.kind {
    |               ~~~~~~~~~

error[E0308]: mismatched types
error[E0308]: mismatched types
   --> library/alloc/src/collections/mod.rs:118:13
    |
116 |         match self {
    |               ---- this expression has type `TryReserveError`
117 |             TryReserveErrorKind::CapacityOverflow => capacity_overflow(),
118 |             TryReserveErrorKind::AllocError { layout, non_exhaustive: () } => {
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `TryReserveError`, found enum `TryReserveErrorKind`
    |
help: you might have meant to use field `kind` whose type is `TryReserveErrorKind`
116 |         match self.kind {
    |               ~~~~~~~~~


error[E0277]: the trait bound `TryReserveError: From<core::alloc::LayoutError>` is not satisfied
    |
    |
237 |         let layout = Layout::array::<T>(capacity)?;
    |                                                  ^ the trait `From<core::alloc::LayoutError>` is not implemented for `TryReserveError`
    = help: the following implementations were found:
    = help: the following implementations were found:
              <TryReserveError as From<TryReserveErrorKind>>
    = note: required because of the requirements on the impl of `FromResidual<Result<Infallible, core::alloc::LayoutError>>` for `Result<RawVec<T, A>, TryReserveError>`
note: required by `from_residual`
    |
    |
339 |     fn from_residual(residual: R) -> Self;


error[E0277]: the trait bound `TryReserveError: From<core::alloc::LayoutError>` is not satisfied
     |
     |
1212 |             let layout = Layout::array::<T>(len)?;
     |                                                 ^ the trait `From<core::alloc::LayoutError>` is not implemented for `TryReserveError`
     = help: the following implementations were found:
     = help: the following implementations were found:
               <TryReserveError as From<TryReserveErrorKind>>
     = note: required because of the requirements on the impl of `FromResidual<Result<Infallible, core::alloc::LayoutError>>` for `Result<*mut ArcInner<[T]>, TryReserveError>`
note: required by `from_residual`
     |
     |
339  |     fn from_residual(residual: R) -> Self;

Some errors have detailed explanations: E0277, E0308, E0433.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `alloc` due to 7 previous errors

@bors
Copy link
Contributor

bors commented Oct 20, 2021

☔ The latest upstream changes (presumably #90067) made this pull request unmergeable. Please resolve the merge conflicts.

@JohnCSimon JohnCSimon 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 8, 2021
@JohnCSimon
Copy link
Member

@Ericson2314
Ping from triage: I'm closing this one due to inactivity, please feel to reopen when you are ready to continue with this.

@rustbot label: +S-inactive

@JohnCSimon JohnCSimon closed this Dec 5, 2021
@rustbot rustbot added the S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. label Dec 5, 2021
@Xuanwo
Copy link
Contributor

Xuanwo commented Dec 5, 2021

As discussed in #86942 (comment), I'm interested in taking over this PR. How could I continue this work? Maybe I need to fork from @Rust-for-Linux and send a new PR?

@the8472
Copy link
Member

the8472 commented Dec 5, 2021

You can fetch the latest commit from rust-lang (PR commits are available as remote refs) and create a branch from it, rebase it against master and open a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.