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

Make transpose const and inline #103127

Merged
merged 1 commit into from
Oct 19, 2022
Merged

Conversation

SUPERCILEX
Copy link
Contributor

r? @scottmcm

  • These should have been const from the beginning since we're never going to do more than a transmute.
  • Inline these always because that's what every other method in MaybeUninit which simply casts does. :) Ok, but a stronger justification is that because we're taking in arrays by self, not inlining would defeat the whole purpose of using MaybeUninit due to the copying.

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Oct 16, 2022
@rustbot
Copy link
Collaborator

rustbot commented Oct 16, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 16, 2022
@rust-log-analyzer

This comment has been minimized.

@@ -1297,7 +1297,8 @@ impl<T, const N: usize> MaybeUninit<[T; N]> {
/// let data: [MaybeUninit<u8>; 1000] = MaybeUninit::uninit().transpose();
/// ```
#[unstable(feature = "maybe_uninit_uninit_array_transpose", issue = "96097")]
pub fn transpose(self) -> [MaybeUninit<T>; N] {
#[inline(always)]
Copy link
Member

Choose a reason for hiding this comment

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

If you make these just #[inline] instead of #[inline(always)], I'll approve it right away.

But for always you need to make a case that it actually matters to have the stronger version.

Copy link
Contributor Author

@SUPERCILEX SUPERCILEX Oct 16, 2022

Choose a reason for hiding this comment

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

I guess I don't understand when #[inline] wouldn't fire vs. #[inline(always)]. As for why the stronger version matters, if the compiler ever decides not to inline we end up with a memcpy whereas inlining blocks this memcpy.

Copy link
Member

Choose a reason for hiding this comment

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

Right, the inlining is clearly important. But the main thing that, compared to nothing, #[inline] actually does on generic methods is force it to be available in all CGUs.

Whereas inline-vs-inline(always) in comparison is just the difference between inlinehint and alwaysinline https://llvm.org/docs/LangRef.html#function-attributes, so we generally don't use always. If LLVM really thinks that sometimes it's not worth doing despite the inlinehint, odds are that we should probably let it make that choice. Sometimes we override it, where someone shows that it's worth it, but non-always #[inline] seems sufficient in your above example.

So let's start with non-always, and can always put it there later if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, the inlining is clearly important. But the main thing that, compared to nothing, #[inline] actually does on generic methods is force it to be available in all CGUs.

Interesting, was able to find this. I still don't think I get it, but it kind of seemed like inline leads to a potentially major hit and then always doesn't matter on top of that.

If LLVM really thinks that sometimes it's not worth doing despite the inlinehint, odds are that we should probably let it make that choice.

Except that transpose is supposed to generate no code since it's just a cast. If LLVM doesn't inline, that would probably indicate a bug or some truly big-brain stuff. 😆

Anyway, downgraded.

@scottmcm scottmcm 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 Oct 16, 2022
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
@SUPERCILEX
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 17, 2022
@scottmcm
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Oct 17, 2022

📌 Commit 1a1ebb0 has been approved by scottmcm

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 Oct 17, 2022
@bors
Copy link
Contributor

bors commented Oct 17, 2022

⌛ Testing commit 1a1ebb0 with merge fa91a1fe99106e14fa44eacbbfcf76a787afb6db...

@bors
Copy link
Contributor

bors commented Oct 17, 2022

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 17, 2022
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] regex_automata test:false 10.399
[RUSTC-TIMING] regex test:false 10.838
[RUSTC-TIMING] salsa_macros test:false 2.927
   Compiling salsa v0.17.0-pre.2
rustc: /checkout/src/llvm-project/llvm/include/llvm/CodeGen/MachineInstr.h:506: llvm::MachineOperand& llvm::MachineInstr::getOperand(unsigned int): Assertion `i < getNumOperands() && "getOperand() out of range!"' failed.
[RUSTC-TIMING] tracing_attributes test:false 3.394
rustc exited with signal: 6 (SIGABRT) (core dumped)
error: could not compile `tracing-attributes`
Caused by:
Caused by:
  process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustc --crate-name tracing_attributes --edition=2018 /cargo/registry/src/github.com-1ecc6299db9ec823/tracing-attributes-0.1.22/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type proc-macro --emit=dep-info,link -C prefer-dynamic -C embed-bitcode=no -C debuginfo=0 -Zunstable-options --check-cfg 'values(feature, "async-await")' --check-cfg 'names()' --check-cfg 'values()' -C metadata=94c3cd2c5427dc2a -C extra-filename=-94c3cd2c5427dc2a --out-dir /checkout/obj/build/aarch64-unknown-linux-gnu/stage2-tools/release/deps -L dependency=/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-tools/release/deps --extern proc_macro2=/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-tools/release/deps/libproc_macro2-0fb922aca1091b45.rlib --extern quote=/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-tools/release/deps/libquote-2b2b5ad8408c0769.rlib --extern syn=/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-tools/release/deps/libsyn-c0b14e37bec48564.rlib --extern proc_macro --cap-lints allow -Z binary-dep-depinfo` (exit status: 254)
[RUSTC-TIMING] thiserror_impl test:false 3.258
[RUSTC-TIMING] pulldown_cmark test:false 11.288
[RUSTC-TIMING] notify test:false 8.944
[RUSTC-TIMING] regex_syntax test:false 16.336

@SUPERCILEX
Copy link
Contributor Author

@scottmcm can you rerun this? I don't how this failure could be related:

Compiling salsa v0.17.0-pre.2
rustc: /checkout/src/llvm-project/llvm/include/llvm/CodeGen/MachineInstr.h:506: llvm::MachineOperand& llvm::MachineInstr::getOperand(unsigned int): Assertion `i < getNumOperands() && "getOperand() out of range!"' failed.

@scottmcm
Copy link
Member

Agreed that that's a super-weird error.

@bors retry

@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 Oct 17, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 19, 2022
Rollup of 6 pull requests

Successful merges:

 - rust-lang#102863 (Standardize "use parentheses to call" suggestions between typeck and trait selection)
 - rust-lang#103034 (Let expressions on RHS shouldn't be terminating scopes)
 - rust-lang#103127 (Make transpose const and inline)
 - rust-lang#103153 (Allow `Vec::leak` when using `no_global_oom_handling`)
 - rust-lang#103182 (Clean up query descriptions)
 - rust-lang#103216 (Consider patterns in fn params in an `Elided(Infer)` lifetime rib.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit f4afb9d into rust-lang:master Oct 19, 2022
@rustbot rustbot added this to the 1.66.0 milestone Oct 19, 2022
@SUPERCILEX SUPERCILEX deleted the inline-const-uninit branch November 6, 2022 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library 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