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

Use const initialized thread locals where possible #4677

Merged
merged 4 commits into from Jun 29, 2022

Conversation

a1phyr
Copy link
Contributor

@a1phyr a1phyr commented May 10, 2022

Motivation

This PR uses a new feature (stabilized in Rust 1.59) to initialize some thread-local statics at compile time. This should bring better performances and code size.

Drawbacks

It adds back a build script to check the version of rustc.

@github-actions github-actions bot added the R-loom Run loom tests on this PR label May 10, 2022
@Noah-Kennedy
Copy link
Contributor

I'm not entirely sure how I feel about this approach to getting by our MSRV. @Darksonn @hawkw thoughts?

@Darksonn Darksonn added the A-tokio Area: The main tokio crate label May 10, 2022
@Darksonn
Copy link
Contributor

I think we have done something similar in the past for #[track_caller].

@hawkw
Copy link
Member

hawkw commented May 10, 2022

Yeah, we've done similar things in the past, so I'm fine with introducing the build script again provided that the benefit outweighs the extra complexity.

Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

This looks good to me.

@Darksonn Darksonn enabled auto-merge (squash) June 29, 2022 09:01
@Darksonn Darksonn merged commit 7f92bce into tokio-rs:master Jun 29, 2022
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Jul 18, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [tokio](https://tokio.rs) ([source](https://github.com/tokio-rs/tokio)) | dependencies | minor | `1.19.2` -> `1.20.0` |
| [tokio](https://tokio.rs) ([source](https://github.com/tokio-rs/tokio)) | dev-dependencies | minor | `1.19.2` -> `1.20.0` |

---

### Release Notes

<details>
<summary>tokio-rs/tokio</summary>

### [`v1.20.0`](https://github.com/tokio-rs/tokio/releases/tag/tokio-1.20.0)

[Compare Source](tokio-rs/tokio@tokio-1.19.2...tokio-1.20.0)

##### 1.20.0 (July 12, 2022)

##### Added

-   tokio: add track_caller to public APIs ([#&#8203;4772], [#&#8203;4791], [#&#8203;4793], [#&#8203;4806], [#&#8203;4808])
-   sync: Add `has_changed` method to `watch::Ref` ([#&#8203;4758])

##### Changed

-   time: remove `src/time/driver/wheel/stack.rs` ([#&#8203;4766])
-   rt: clean up arguments passed to basic scheduler ([#&#8203;4767])
-   net: be more specific about winapi features ([#&#8203;4764])
-   tokio: use const initialized thread locals where possible ([#&#8203;4677])
-   task: various small improvements to LocalKey ([#&#8203;4795])

##### Fixed

##### Documented

-   fs: warn about performance pitfall ([#&#8203;4762])
-   chore: fix spelling ([#&#8203;4769])
-   sync: document spurious failures in oneshot ([#&#8203;4777])
-   sync: add warning for watch in non-Send futures ([#&#8203;4741])
-   chore: fix typo ([#&#8203;4798])

##### Unstable

-   joinset: rename `join_one` to `join_next` ([#&#8203;4755])
-   rt: unhandled panic config for current thread rt ([#&#8203;4770])

[#&#8203;4677]: tokio-rs/tokio#4677

[#&#8203;4741]: tokio-rs/tokio#4741

[#&#8203;4755]: tokio-rs/tokio#4755

[#&#8203;4758]: tokio-rs/tokio#4758

[#&#8203;4762]: tokio-rs/tokio#4762

[#&#8203;4764]: tokio-rs/tokio#4764

[#&#8203;4766]: tokio-rs/tokio#4766

[#&#8203;4767]: tokio-rs/tokio#4767

[#&#8203;4769]: tokio-rs/tokio#4769

[#&#8203;4770]: tokio-rs/tokio#4770

[#&#8203;4772]: tokio-rs/tokio#4772

[#&#8203;4777]: tokio-rs/tokio#4777

[#&#8203;4791]: tokio-rs/tokio#4791

[#&#8203;4793]: tokio-rs/tokio#4793

[#&#8203;4795]: tokio-rs/tokio#4795

[#&#8203;4798]: tokio-rs/tokio#4798

[#&#8203;4806]: tokio-rs/tokio#4806

[#&#8203;4808]: tokio-rs/tokio#4808

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzMi4xMTEuMSIsInVwZGF0ZWRJblZlciI6IjMyLjExMS4xIn0=-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1458
Reviewed-by: crapStone <crapstone@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
@caldwell
Copy link

I'm getting an error with tokio 1.20.0 on nightly-aarch64-apple-darwin updated - rustc 1.64.0-nightly (7fe022f5a 2022-07-24):

error[E0658]: use of unstable library feature 'thread_local_const_init'
  --> /Users/david/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.20.0/src/coop.rs:34:1
   |
34 | / thread_local! {
35 | |     static CURRENT: Cell<Budget> = const { Cell::new(Budget::unconstrained()) };
36 | | }
   | |_^
   |
   = note: see issue #84223 <https://github.com/rust-lang/rust/issues/84223> for more information
   = help: add `#![feature(thread_local_const_init)]` to the crate attributes to enable
   = note: this error originates in the macro `$crate::__thread_local_inner` (in Nightly builds, run with -Z macro-backtrace for more info)

This looks related to this change. Is this something I'm doing wrong, or is this a Tokio bug?

@Darksonn
Copy link
Contributor

@caldwell The thread_local_const_init feature was stabilized in rustc 1.59.0, so it seems very weird that you would get such an error on a nightly newer than 1.59.0.

@Darksonn
Copy link
Contributor

Does this compile for you?

thread_local! {
    static FOO: usize = const { 10 };
}

fn main() {
    println!("Hello, world!");
}

@caldwell
Copy link

caldwell commented Jul 25, 2022

Sigh, this was operator error: I had run rustup update but it merely downloaded a new compiler but didn't activate it like I expected. I was actually running 1.58 from December. With the latest nightly (2022-07-24) it builds just fine.

Thanks for your response and sorry about the bug spam!

@Darksonn
Copy link
Contributor

Can you elaborate on how you were running it? Tokio should detect that you are on 1.58.0 and avoid using the feature. I just tried compiling with 1.58.0 myself and it worked fine.

@caldwell
Copy link

It was just cargo build, where tokio was a dependency. It also happened on a cargo install pijul (which is basically the same thing). The specific version(s) I was running:

$ rustc --version
rustc 1.59.0-nightly (532d2b14c 2021-12-03)
$ cargo version
cargo 1.58.0-nightly (294967c53 2021-11-29)

(I don't understand how those could be different.)

@Darksonn
Copy link
Contributor

@caldwell I figured out what issue you ran into. See #4860 for the fix.

@caldwell
Copy link

Thanks, I appreciate your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate R-loom Run loom tests on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants