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

Tidy ups #549

Merged
merged 1 commit into from
Apr 26, 2022
Merged

Tidy ups #549

merged 1 commit into from
Apr 26, 2022

Conversation

ltratt
Copy link
Contributor

@ltratt ltratt commented Apr 25, 2022

Some random tidy-ups, partly found by Clippy.

The only tricky one is e0aceed which @vext01 might want to take a quick peek at.

@ltratt
Copy link
Contributor Author

ltratt commented Apr 25, 2022

bors try

bors bot added a commit that referenced this pull request Apr 25, 2022
@bors
Copy link
Contributor

bors bot commented Apr 25, 2022

try

Build succeeded:

@@ -25,7 +25,7 @@ thread_local! {
//
// We hide the `ThreadTracer` in a thread local (rather than returning it to the consumer of
// yk). This ensures that the `ThreadTracer` itself cannot appear in traces.
pub static THREAD_TRACER: RefCell<Option<ThreadTracer>> = const { RefCell::new(None) };
pub static THREAD_TRACER: RefCell<Option<ThreadTracer>> = RefCell::new(None);
Copy link
Contributor

Choose a reason for hiding this comment

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

Creating a RefCell (calling RefCell::new()) is const, so this may be right? IIRC, the const isn't talking about whether the data is mutable, but whether the call can be evaluated at compile time(?).

(I didn't know you had to explcitiely mark it const though)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Clippy complained obliquely about this const: I'm not sure what it means for a RefCell to be const if it's instantiated multiple times in multiple threads. Unless we know why it's here, I think that at most const is an optimisation (though possibly not even that in this case), and possible it's incorrect.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what it means for a RefCell to be const if it's instantiated multiple times in multiple threads.

Should be fine. It's a thread local.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What happens if const here means "share one RefCell across multiple threads"? I don't think we know precisely what const means, and there's a small chance it interacts incorrectly with thread locals.

Copy link
Contributor

Choose a reason for hiding this comment

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

That'd be bonkers if that's what happened, but I'll find the answer.

Copy link
Contributor

Choose a reason for hiding this comment

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

I can't find it spelled out anywhere, but some part of tokio has applied the same optimisation recently (it's still under PR, but I think the intent is clear).

FWIW, tracking issue for the feature (no mention of surprising semantic changes).

I just don't see why thread_local! {const ...} would make something not a thread local :P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe try running clippy locally and see what you think of its complaint here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm now questioning clippy. Is it is conflating const data with a const block?!

https://rust-lang.github.io/rust-clippy/master/index.html#declare_interior_mutable_const

Look at the examples. This is different to what is going on here!

And there it is. This is a clippy bug!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good find. So I should delete the commit that makes this change, I think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think so, yes. May as well force push that now.

@ltratt
Copy link
Contributor Author

ltratt commented Apr 26, 2022

Force pushed.

@vext01
Copy link
Contributor

vext01 commented Apr 26, 2022

bors r+

@bors
Copy link
Contributor

bors bot commented Apr 26, 2022

Build succeeded:

@bors bors bot merged commit 7d4511b into ykjit:master Apr 26, 2022
@ltratt ltratt deleted the tidy_ups branch May 16, 2023 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants