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

library: Use size_of from the prelude instead of imported #138034

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thaliaarchi
Copy link
Contributor

@thaliaarchi thaliaarchi commented Mar 5, 2025

Use std::mem::{size_of, size_of_val, align_of, align_of_val} from the prelude instead of importing or qualifying them.

These functions were added to all preludes in Rust 1.80.

@rustbot
Copy link
Collaborator

rustbot commented Mar 5, 2025

r? @jieyouxu

rustbot has assigned @jieyouxu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-compiletest Area: The compiletest test runner A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) A-testsuite Area: The testsuite used to check the correctness of rustc O-itron Operating System: ITRON O-SGX Target: SGX O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-windows Operating system: Windows PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Mar 5, 2025
@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member

compiler-errors commented Mar 5, 2025

Please revert all the changes to tests. We don't typically "correct" tests for things like this, formatting, etc. It's simply unnecessary churn. Especially unless you want to verify that every test that was changed doesn't implicitly change the meaning or intention of the test that when it was originally committed (e.g. that the test wasn't exercising minutiae of resolver or path semantics or something else).

You also probably should split this out between library, compiler, and changes to the various tools in src/tools. Different parts of the repository are the responsibility of different teams, and right now the review-ability of a 444 file test is really not great.

@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 Mar 5, 2025
@rustbot
Copy link
Collaborator

rustbot commented Mar 5, 2025

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

Some changes occurred in src/tools/compiletest

cc @jieyouxu

Some changes occurred in coverage tests.

cc @Zalathar

This PR changes Stable MIR

cc @oli-obk, @celinval, @ouz-a

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

The Miri subtree was changed

cc @rust-lang/miri

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

Portable SIMD is developed in its own repository. If possible, consider making this change to rust-lang/portable-simd instead.

cc @calebzulawski, @programmerjake

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

Some changes occurred in const_evaluatable.rs

cc @BoxyUwU

Some changes occurred in tests/ui/sanitizer

cc @rust-lang/project-exploit-mitigations, @rcvalle

@rust-log-analyzer

This comment has been minimized.

@thaliaarchi thaliaarchi force-pushed the use-prelude-size-of branch from 88cec8c to ae1a15a Compare March 5, 2025 05:53
@thaliaarchi
Copy link
Contributor Author

Please revert all the changes to tests.

I've removed changes to files in the following directories:

src/tools/clippy/tests/
src/tools/miri/tests/
src/tools/rustfmt/tests/
tests/

@rust-log-analyzer

This comment has been minimized.

@thaliaarchi
Copy link
Contributor Author

Roughly by team, the distribution is now:

library/: 124 files
compiler/: 31 files
src/tools/rust-analyzer/: 11 files
src/tools/clippy/: 4 files
src/bootstrap/: 2 files
src/tools/compiletest/: 1 file
src/tools/miri/: 1 file

Unless I'm splitting library/ somehow, compiler/ might not even be worth splitting out. It's just a lot of files. But, I'm open if you have ideas on how to split it well.

@compiler-errors
Copy link
Member

compiler-errors commented Mar 5, 2025

By split, I mean there's no reason this needs to happen in a single PR, since it's not like this changes something that needs to be applied concurrently across all the repository in a singular PR. It's just a bunch of changes squashed into one by choice.

The 31 changes in compiler/ can get reviewed and approved by a compiler reviewer separately. Same with library/, which should have a dedicated reviewer, though that likely requires a bunch of CI back and forth with all the platform cfg's that aren't tested locally. What I mean is to split this into several PRs.

This PR also touches several tools that really should have PRs made to their own repositories, like rust-analyzer, rustfmt, etc (pls re-read the rustbot ping list for some of those submodules by name), since this is not a critical change or something that breaks rust-analyzer or rustfmt in CI or anything.

@jieyouxu
Copy link
Member

jieyouxu commented Mar 5, 2025

I can review the bootstrap/compiletest bits if you split those out. But the rust-analyzer, rustfmt, clippy changes need (well, really should) to be sent against their own repos since they're subtrees and does not otherwise need compiler changes to minimize subtree sync conflicts.

@thaliaarchi thaliaarchi force-pushed the use-prelude-size-of branch 2 times, most recently from 1297a50 to 4f07a0b Compare March 5, 2025 08:44
@thaliaarchi thaliaarchi changed the title Use size_of from the prelude instead of imported library: Use size_of from the prelude instead of imported Mar 5, 2025
@rustbot rustbot assigned tgross35 and unassigned compiler-errors Mar 5, 2025
@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 Mar 5, 2025
@thaliaarchi
Copy link
Contributor Author

I have checked it with x check library on all tier 1 and tier 2 with host tools targets, as well as a few odd targets. Some tier 3 targets fail to build tests for unrelated reasons.

List of targets checked
# Tier 1:
x check library --target=aarch64-apple-darwin
x check library --target=aarch64-unknown-linux-gnu
x check library --target=i686-pc-windows-gnu
x check library --target=i686-pc-windows-msvc
x check library --target=i686-unknown-linux-gnu
x check library --target=x86_64-apple-darwin
x check library --target=x86_64-pc-windows-gnu
x check library --target=x86_64-pc-windows-msvc
x check library --target=x86_64-unknown-linux-gnu

# Tier 2 with host tools:
x check library --target=aarch64-pc-windows-msvc
x check library --target=aarch64-unknown-linux-musl
x check library --target=arm-unknown-linux-gnueabi
x check library --target=arm-unknown-linux-gnueabihf
x check library --target=armv7-unknown-linux-gnueabihf
x check library --target=loongarch64-unknown-linux-gnu
x check library --target=loongarch64-unknown-linux-musl
x check library --target=powerpc-unknown-linux-gnu
x check library --target=powerpc64-unknown-linux-gnu
x check library --target=powerpc64le-unknown-linux-gnu
x check library --target=powerpc64le-unknown-linux-musl
x check library --target=riscv64gc-unknown-linux-gnu
x check library --target=riscv64gc-unknown-linux-musl
x check library --target=s390x-unknown-linux-gnu
x check library --target=x86_64-unknown-freebsd
x check library --target=x86_64-unknown-illumos
x check library --target=x86_64-unknown-linux-musl
x check library --target=x86_64-unknown-netbsd

# Other:
x check library --target=wasm32-wasip1
x check library --target=wasm32-wasip1-threads
x check library --target=wasm32-wasip2
x check library --target=x86_64-fortanix-unknown-sgx

# Fail (but unrelated):
x check library --target=aarch64-kmc-solid_asp3
x check library --target=aarch64-unknown-teeos
x check library --target=riscv32im-risc0-zkvm-elf
x check library --target=riscv32imac-unknown-xous-elf
x check library --target=wasm32-unknown-unknown
x check library --target=x86_64-unknown-hermit
x check library --target=x86_64-unknown-uefi

@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

Notes from my initial quick pass, mostly use statements that could be removed. Based on CI it seems like there may be other instances that aren't picked up by ./x c library?

@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 Mar 5, 2025
Copy link
Contributor

@Sky9x Sky9x left a comment

Choose a reason for hiding this comment

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

why does this change some docs to use turbofish syntax? (second commit)

@compiler-errors
Copy link
Member

Because it's not valid rust, perhaps?

@thaliaarchi thaliaarchi force-pushed the use-prelude-size-of branch from 4f07a0b to 94f866c Compare March 5, 2025 22:03
@thaliaarchi
Copy link
Contributor Author

why does this change some docs to use turbofish syntax? (second commit)

That was at Jubilee's suggestion: #138034 (comment)

Because it's not valid rust, perhaps?

Exactly

@thaliaarchi
Copy link
Contributor Author

@tgross35 I've now fixed (what should be) all the now-unnecessary imports for doc tests. Running x check library --doc caught everything you found and some more.

@rust-log-analyzer

This comment has been minimized.

@thaliaarchi thaliaarchi force-pushed the use-prelude-size-of branch from 94f866c to 3f51211 Compare March 5, 2025 23:06
@thaliaarchi
Copy link
Contributor Author

…and now benches are fixed

@rust-log-analyzer

This comment has been minimized.

@thaliaarchi thaliaarchi force-pushed the use-prelude-size-of branch from 3f51211 to 7f4ce71 Compare March 5, 2025 23:40
@thaliaarchi
Copy link
Contributor Author

This round caught some tests in library/coretests, which I couldn't check locally with x check library/coretests, because of “can't find crate for std”.

All this CI bouncing isn't really inspiring confidence, so while this run is going, I'll do a manual review of the imports.

Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the
prelude instead of importing or qualifying them.

These functions were added to all preludes in Rust 1.80.
@thaliaarchi thaliaarchi force-pushed the use-prelude-size-of branch from 7f4ce71 to b4a107d Compare March 6, 2025 02:50
@thaliaarchi
Copy link
Contributor Author

I reviewed every file to check whether a use {std, core, crate}::mem became unused, gated or always, and found a few which weren't uncovered by CI or local testing. I think this covers everything.

I was hoping to wait until the previus CI run finished, but builders weren't picking up the last two jobs, since the tree is currently closed, so I've pushed the fixes I found. But the jobs which actually did run passed, so that's a good sign.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) A-testsuite Area: The testsuite used to check the correctness of rustc O-itron Operating System: ITRON O-SGX Target: SGX O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-windows Operating system: Windows PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants