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

Simplify key-based thread locals #122494

Merged
merged 2 commits into from May 24, 2024
Merged

Conversation

joboet
Copy link
Contributor

@joboet joboet commented Mar 14, 2024

This PR simplifies key-based thread-locals by:

  • unifying the macro expansion of const and non-const initializers
  • reducing the amount of code in the expansion
  • simply reallocating on recursive initialization instead of going through LazyKeyInner
  • replacing catch_unwind with the shared abort_on_dtor_unwind

It does not change the initialization behaviour described in #110897.

@rustbot
Copy link
Collaborator

rustbot commented Mar 14, 2024

r? @cuviper

rustbot has assigned @cuviper.
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 S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 14, 2024
@cuviper
Copy link
Member

cuviper commented Mar 19, 2024

r? @m-ou-se

^ since you hopefully remember more about this code from #110897.

@rustbot rustbot assigned m-ou-se and unassigned cuviper Mar 19, 2024
Comment on lines +113 to +118
// If the variable was recursively initialized, drop the old value.
// SAFETY: We cannot be inside a `LocalKey::with` scope, as the
// initializer has already returned and the next scope only starts
// after we return the pointer. Therefore, there can be no references
// to the old value.
drop(unsafe { Box::from_raw(old) });
Copy link
Member

Choose a reason for hiding this comment

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

I think it'd be good to swap this around (such that it behaves like OnceCell) in a future PR. (That PR will need an FCP and perhaps a crater run though.)

@m-ou-se
Copy link
Member

m-ou-se commented Mar 20, 2024

This looks great.

@bors r+

@bors
Copy link
Contributor

bors commented Mar 20, 2024

📌 Commit 5fd4a84 has been approved by m-ou-se

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 Mar 20, 2024
@m-ou-se m-ou-se added the A-thread-locals Area: Thread local storage (TLS) label Mar 20, 2024
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Mar 20, 2024
Simplify key-based thread locals

This PR simplifies key-based thread-locals by:
* unifying the macro expansion of `const` and non-`const` initializers
* reducing the amount of code in the expansion
* simply reallocating on recursive initialization instead of going through `LazyKeyInner`
* replacing `catch_unwind` with the shared `abort_on_dtor_unwind`

It does not change the initialization behaviour described in rust-lang#110897.
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 20, 2024
…llaumeGomez

Rollup of 8 pull requests

Successful merges:

 - rust-lang#122494 (Simplify key-based thread locals)
 - rust-lang#122644 (pattern analysis: add a custom test harness)
 - rust-lang#122723 (Use same file permissions for ar_archive_writer as the LLVM archive writer)
 - rust-lang#122729 (Relax SeqCst ordering in standard library.)
 - rust-lang#122740 (use more accurate terminology)
 - rust-lang#122764 (coverage: Remove incorrect assertions from counter allocation)
 - rust-lang#122765 (Add `usize::MAX` arg tests for Vec)
 - rust-lang#122776 (Rename `hir::Let` into `hir::LetExpr`)

r? `@ghost`
`@rustbot` modify labels: rollup
@GuillaumeGomez
Copy link
Member

I think this is the PR which failed in #122778.

@m-ou-se
Copy link
Member

m-ou-se commented Mar 21, 2024

@bors r-

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 21, 2024
@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Mar 21, 2024
@joboet
Copy link
Contributor Author

joboet commented Mar 21, 2024

The failing UI tests only check internal perma-unstable implementations, so I think they are fine to remove.

@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 Mar 21, 2024
@bors
Copy link
Contributor

bors commented Apr 6, 2024

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

@joboet
Copy link
Contributor Author

joboet commented May 23, 2024

r? libs

@m-ou-se
Copy link
Member

m-ou-se commented May 23, 2024

@bors r+

@bors
Copy link
Contributor

bors commented May 23, 2024

📌 Commit cef00ea has been approved by m-ou-se

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 23, 2024
@bors
Copy link
Contributor

bors commented May 23, 2024

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

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 23, 2024
@joboet
Copy link
Contributor Author

joboet commented May 24, 2024

Rebased to resolve the conflict with the native TLS rewrite. I've also added a second commit that makes the #[allow(dead_code)] more local and removed the unnecessary imports that are now detected.

@joboet joboet 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 May 24, 2024
@joboet joboet assigned m-ou-se and unassigned workingjubilee May 24, 2024
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@m-ou-se
Copy link
Member

m-ou-se commented May 24, 2024

@bors r+

@bors
Copy link
Contributor

bors commented May 24, 2024

📌 Commit 0e7e75e has been approved by m-ou-se

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 24, 2024
@bors
Copy link
Contributor

bors commented May 24, 2024

⌛ Testing commit 0e7e75e with merge 9e297bf...

@bors
Copy link
Contributor

bors commented May 24, 2024

☀️ Test successful - checks-actions
Approved by: m-ou-se
Pushing 9e297bf to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 24, 2024
@bors bors merged commit 9e297bf into rust-lang:master May 24, 2024
7 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 24, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (9e297bf): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.6% [0.4%, 1.2%] 8
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -2.2%, secondary -5.1%)

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)
-2.2% [-2.2%, -2.2%] 1
Improvements ✅
(secondary)
-5.1% [-5.1%, -5.1%] 1
All ❌✅ (primary) -2.2% [-2.2%, -2.2%] 1

Cycles

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

Binary size

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

Bootstrap: 673.59s -> 674.001s (0.06%)
Artifact size: 315.74 MiB -> 315.67 MiB (-0.02%)

@joboet joboet deleted the simplify_key_tls branch May 24, 2024 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc A-thread-locals Area: Thread local storage (TLS) 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-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.

None yet

9 participants