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

rustc_middle: parallel: TyCtxt: remove "unsafe impl DynSend/DynSync" #136731

Merged
merged 1 commit into from
Feb 10, 2025

Conversation

safinaskar
Copy link
Contributor

@safinaskar safinaskar commented Feb 8, 2025

rustc_middle: parallel: TyCtxt: remove "unsafe impl DynSend/DynSync"

We don't need to "short circuit trait resolution", because DynSend and DynSync are auto traits and thus coinductive

cc "Parallel Rustc Front-end" #113349

r? SparrowLii

@rustbot label: +WG-compiler-parallel

(rustbot sometimes ignores me and doesn't attach labels on my behalf. rustbot banned me?)

We don't need to "short circuit trait resolution", because DynSend and DynSync are auto traits and thus coinductive
@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. WG-compiler-parallel Working group: Parallelizing the compiler labels Feb 8, 2025
@SparrowLii
Copy link
Member

Thanks!

@bors r+

@bors
Copy link
Contributor

bors commented Feb 8, 2025

📌 Commit 8eba29a has been approved by SparrowLii

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 Feb 8, 2025
@safinaskar
Copy link
Contributor Author

@SparrowLii , I'm writing another PR, which will turn RwLock into enum { S(parking_lot::RwLock), U(RefCell) }. Is this ok? Does it have chances of being accepted?

@SparrowLii
Copy link
Member

Actually, I'm not sure. The efficiency of RwLock is not slow in single-thread, and the enum needs runtime matching, which may affect the optimization effect.
My advice is writing a PR draft and test it with the perf tool.

workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Feb 10, 2025
…22, r=SparrowLii

rustc_middle: parallel: TyCtxt: remove "unsafe impl DynSend/DynSync"

rustc_middle: parallel: TyCtxt: remove "unsafe impl DynSend/DynSync"

We don't need to "short circuit trait resolution", because DynSend and DynSync are auto traits and thus coinductive

cc "Parallel Rustc Front-end" rust-lang#113349

r? SparrowLii

`@rustbot` label: +WG-compiler-parallel

(rustbot sometimes ignores me and doesn't attach labels on my behalf. rustbot banned me?)
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 10, 2025
…kingjubilee

Rollup of 9 pull requests

Successful merges:

 - rust-lang#134626 (Add Four Codegen Tests)
 - rust-lang#135408 (x86: make SSE2 required for i686 hardfloat targets and use it to pass SIMD types)
 - rust-lang#136155 (Enable sanitizers on MSVC CI jobs)
 - rust-lang#136419 (adding autodiff tests)
 - rust-lang#136603 (compiler: gate `extern "{abi}"` in ast_lowering)
 - rust-lang#136628 (ci: upgrade to crosstool-ng 1.27.0)
 - rust-lang#136714 (Update `compiler-builtins` to 0.1.146)
 - rust-lang#136731 (rustc_middle: parallel: TyCtxt: remove "unsafe impl DynSend/DynSync")
 - rust-lang#136761 (tests: `-Copt-level=3` instead of `-O` in codegen tests)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 10, 2025
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#136419 (adding autodiff tests)
 - rust-lang#136628 (ci: upgrade to crosstool-ng 1.27.0)
 - rust-lang#136681 (resolve `llvm-config` path properly on cross builds)
 - rust-lang#136714 (Update `compiler-builtins` to 0.1.146)
 - rust-lang#136731 (rustc_middle: parallel: TyCtxt: remove "unsafe impl DynSend/DynSync")
 - rust-lang#136791 (Disable DWARF in linker options for i686-unknown-uefi)

Failed merges:

 - rust-lang#136767 (improve host/cross target checking)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 277dda4 into rust-lang:master Feb 10, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Feb 10, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 10, 2025
Rollup merge of rust-lang#136731 - safinaskar:parallel-2025-02-08-07-22, r=SparrowLii

rustc_middle: parallel: TyCtxt: remove "unsafe impl DynSend/DynSync"

rustc_middle: parallel: TyCtxt: remove "unsafe impl DynSend/DynSync"

We don't need to "short circuit trait resolution", because DynSend and DynSync are auto traits and thus coinductive

cc "Parallel Rustc Front-end" rust-lang#113349

r? SparrowLii

``@rustbot`` label: +WG-compiler-parallel

(rustbot sometimes ignores me and doesn't attach labels on my behalf. rustbot banned me?)
@safinaskar safinaskar deleted the parallel-2025-02-08-07-22 branch February 11, 2025 02:34
@Zoxc
Copy link
Contributor

Zoxc commented Mar 3, 2025

Not having these short circuits regresses compile time.

@SparrowLii
Copy link
Member

@Zoxc You mean this increases the build time of the rustc itself? I think this should be acceptable, as we can check if the TyCtxt contains non-shared structures by removing the unsafe impl here.

@Zoxc
Copy link
Contributor

Zoxc commented Mar 3, 2025

That's already checked. There's no reason to add 7 seconds of compile time to every rustc build.

@SparrowLii
Copy link
Member

How can we guarantee that in the future someone won't incorrectly modify GlobalCtxt to contains non-shared data structures

@Zoxc
Copy link
Contributor

Zoxc commented Mar 3, 2025

There are asserts that GlobalCtxt is appropriately Send/Sync, so we don't need to check TyCtxt which only contains a pointer to it.

@SparrowLii
Copy link
Member

SparrowLii commented Mar 3, 2025

We do have fn _assert_tcx_fields to check &GlobalCtxt: Dynsend/Dynsync . And unsafe impl DynSend/DynSync for TyCtxt will make this check invalid

@Zoxc
Copy link
Contributor

Zoxc commented Mar 4, 2025

You got that the wrong way around. _assert_tcx_fields ensures the safety of the unsafe impl. It's the reason that function exists.

@safinaskar
Copy link
Contributor Author

@Zoxc , I think we should have as few as possible unsafe in the code. Even if this means additional 7 seconds for self-build. If the only reason for _assert_tcx_fields is ensuring safety of unsafe impl, then _assert_tcx_fields should be removed, too

@SparrowLii
Copy link
Member

@Zoxc Ah, it makes me wonder why _assert_tcx_fields doesn't cause the rustc build time to increase. I think it should take the time to check that TyCtxt is a shared type

@Zoxc
Copy link
Contributor

Zoxc commented Mar 5, 2025

It does add an extra check, but it also avoids the checks on other uses of TyCtxt, since it will quickly find these impls instead.

@SparrowLii
Copy link
Member

OK. But it's hard for me to say that using `unsafe impl' is necessary to save some build time, since the average build time for rustc is around 15 minutes.

On the other hand, I think there should be cache for each solved trait to avoid extra 7 seconds of check time. This is probably where trait solver should be optimized.

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-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-compiler-parallel Working group: Parallelizing the compiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants