Skip to content

Make TLS accessors closures that return pointers#125525

Merged
bors merged 2 commits into
rust-lang:masterfrom
joboet:tls_accessor
Jun 4, 2024
Merged

Make TLS accessors closures that return pointers#125525
bors merged 2 commits into
rust-lang:masterfrom
joboet:tls_accessor

Conversation

@joboet

@joboet joboet commented May 24, 2024

Copy link
Copy Markdown
Member

The current TLS macros generate a function that returns an Option<&'static T>. This is both risky as we lie about lifetimes, and necessitates that those functions are unsafe. By returning a *const T instead, the accessor function do not have safety requirements any longer and can be made closures without hassle. This PR does exactly that!

For native TLS, the closure approach makes it trivial to select the right accessor function at compile-time, which could result in a slight speed-up (I have the hope that the accessors are now simple enough for the MIR-inliner to kick in).

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-thread-locals Area: Thread local storage (TLS) merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. 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.

7 participants