Make {Mutex, Condvar, RwLock}::new() const. by m-ou-se · Pull Request #97791 · rust-lang/rust (original) (raw)

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

m-ou-se

This makes it possible to have static M: Mutex<_> = Mutex::new(..); 🎉

Our implementations on Linux, on Windows, and various BSDs and some tier 3 platforms have already been using a non-allocating const-constructible implementation. As of #97647, the remaining platforms (most notably macOS) now have a const-constructible implementation as well. This means we can finally make these functions publicly const.

Tracking issue: #93740

stepancheg, pluiedev, Cassy343, up-to-you, and pronebird reacted with thumbs up emoji taiki-e, wwylele, slanterns, Folyd, darksv, BurntSushi, lcnr, bestgopher, rtzoeller, Kobzol, and 40 more reacted with hooray emoji Noratrieb, Lokathor, CryZe, Dushistov, mati865, saiksy, akiross, Kogia-sima, tux3, IndigoLily, and 9 more reacted with heart emoji

@m-ou-se

@m-ou-se

@m-ou-se m-ou-se added T-libs-api

Relevant to the library API team, which will review and decide on the PR/issue.

needs-fcp

This change is insta-stable, so needs a completed FCP to proceed.

labels

Jun 6, 2022

@m-ou-se

@rfcbot

Team member @m-ou-se has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added the final-comment-period

In the final comment period and will be merged soon unless new substantive objections are raised.

label

Jun 7, 2022

@rfcbot

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@m-ou-se

@bors

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

@bors bors added the S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

label

Jun 18, 2022

@bors

@bors

@rust-timer

Finished benchmarking commit (15fc228): comparison url.

Instruction count

mean1 max count2
Regressions 😿 (primary) N/A N/A 0
Regressions 😿 (secondary) N/A N/A 0
Improvements 🎉 (primary) N/A N/A 0
Improvements 🎉 (secondary) -1.7% -1.7% 1
All 😿🎉 (primary) N/A N/A 0

Max RSS (memory usage)

Results

mean1 max count2
Regressions 😿 (primary) 0.0% 0.0% 1
Regressions 😿 (secondary) N/A N/A 0
Improvements 🎉 (primary) N/A N/A 0
Improvements 🎉 (secondary) N/A N/A 0
All 😿🎉 (primary) 0.0% 0.0% 1

Cycles

Results

mean1 max count2
Regressions 😿 (primary) N/A N/A 0
Regressions 😿 (secondary) N/A N/A 0
Improvements 🎉 (primary) -3.3% -3.3% 1
Improvements 🎉 (secondary) -2.3% -2.3% 1
All 😿🎉 (primary) -3.3% -3.3% 1

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

Footnotes

  1. the arithmetic mean of the percent change ↩2 ↩3
  2. number of relevant changes ↩2 ↩3

@mejrs mejrs mentioned this pull request

Jun 19, 2022

japaric added a commit to japaric/cargo-call-stack that referenced this pull request

Jun 22, 2022

@japaric

This was referenced

Jun 22, 2022

bors added a commit to rust-lang-ci/rust that referenced this pull request

Sep 25, 2022

@bors

make Condvar, Mutex, RwLock const constructors work with the unsupported impl

applying this patch locally to the rust-src component fixes rust-lang#98378

however, the solution seems wrong to me because PR rust-lang#97791 didn't add any rustc_const_stable attribute to underlying implementations like std::sys::unix::futex, so I must be missing something about how const-stability is checked ... maybe the restricted_std feature (gate?) has an effect?

fixes rust-lang#98378 fixes rust-lang#98293 (probably)

@pronebird

It raised my eyebrows when static mutex just worked, that's how I found this page! Holy shit, great work! 💪

bors added a commit to rust-lang-ci/rust that referenced this pull request

Feb 23, 2024

@bors

…lnay

Make Barrier::new() const

I guess this was just missed in rust-lang#97791?

@rustbot label T-libs-api -T-libs

Labels

disposition-merge

This issue / PR is in PFCP or FCP with a disposition to merge it.

finished-final-comment-period

The final comment period is finished for this PR / Issue.

merged-by-bors

This PR was explicitly merged by bors.

needs-fcp

This change is insta-stable, so needs a completed FCP to proceed.

S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

S-waiting-on-fcp

Status: PR is in FCP and is awaiting for FCP to complete.

T-libs-api

Relevant to the library API team, which will review and decide on the PR/issue.