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

Clarify that RUST_MIN_STACK may be internally cached #109225

Merged
merged 2 commits into from
Apr 14, 2023

Conversation

seanlinsley
Copy link
Contributor

For larger applications it's important that users set RUST_MIN_STACK at the start of their program because min_stack caches the value. Not doing so can lead to their env::set_var call surprisingly not having any effect.

In my own testing RUST_MIN_STACK had no effect until I moved it to the top of main(). Hopefully this clarification in the docs will help others going forward.

For larger applications it's important that users set `RUST_MIN_STACK`
at the start of their program because `min_stack` caches the value.
Not doing so can lead to their `env::set_var` call surprisingly not having any effect.
@rustbot
Copy link
Collaborator

rustbot commented Mar 16, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @m-ou-se (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@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 16, 2023
@workingjubilee
Copy link
Member

It's not clear that we should not be not-caching it instead.

@ChrisDenton
Copy link
Member

With environment variables like these we don't make any promises since the intent is for users (or other, external, tools) to set them. They aren't intended as an internal API.

It's possible that in the future RUST_MIN_STACK could be cached before main (heck it's even possible that the entire environment block could be frozen on some platforms). Conversely it's also possible we don't cache them at all.

Making strong promises here would be a libs-api decision. But personally I think that if we want to support a global override then we should have a proper API for that rather than messing with the environment.

@seanlinsley
Copy link
Contributor Author

seanlinsley commented Mar 16, 2023

I think it's reasonable to expose RUST_MIN_STACK as a global setting similar to #[global_allocator]. But in the meantime, this PR at least clarifies the current behavior.

@workingjubilee
Copy link
Member

Can we note it down in a more "the check on this environment variable shouldn't be relied on to happen at a particular moment, and that's partly because currently we cache it as an optimization" way, then, so this doesn't get construed as a promise?

@ChrisDenton
Copy link
Member

I am still super nervous about mentioning implementation details that shouldn't be relied upon. We tend to avoid that.

We could document that setting RUST_MIN_STACK once the program is running may not have any effect and instead to use Builder::stack_size. This would alert the user to potentially surprising behaviour and the "may" gives enough wriggle room in the implementation.

@rustbot
Copy link
Collaborator

rustbot commented Mar 17, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@seanlinsley
Copy link
Contributor Author

Okay, I've changed it to:

Be aware that changes to RUST_MIN_STACK may be ignored after program start.

@seanlinsley seanlinsley changed the title Clarify that RUST_MIN_STACK is internally cached Clarify that RUST_MIN_STACK may be internally cached Mar 18, 2023
@ChrisDenton
Copy link
Member

That seems reasonable to me.

@bors r+

@bors
Copy link
Contributor

bors commented Apr 14, 2023

📌 Commit 6eef755 has been approved by ChrisDenton

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 Apr 14, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 14, 2023
Clarify that RUST_MIN_STACK may be internally cached

For larger applications it's important that users set `RUST_MIN_STACK` at the start of their program because [`min_stack`](https://github.com/rust-lang/rust/blob/7d3e03666a93bd2b0f78b3933f9305832af771a5/library/std/src/sys_common/thread.rs) caches the value. Not doing so can lead to their `env::set_var` call surprisingly not having any effect.

In my own testing `RUST_MIN_STACK` had no effect until I moved it to the top of `main()`. Hopefully this clarification in the docs will help others going forward.
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 14, 2023
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#109225 (Clarify that RUST_MIN_STACK may be internally cached)
 - rust-lang#109800 (Improve safe transmute error reporting)
 - rust-lang#110158 (Remove obsolete test case)
 - rust-lang#110180 (don't uniquify regions when canonicalizing)
 - rust-lang#110207 (Assemble `Unpin` candidates specially for generators in new solver)
 - rust-lang#110276 (Remove all but one of the spans in `BoundRegionKind::BrAnon`)
 - rust-lang#110279 (rustdoc: Correctly handle built-in compiler proc-macros as proc-macro and not macro)
 - rust-lang#110298 (Cover edge cases for {f32, f64}.hypot() docs)
 - rust-lang#110299 (Switch to `EarlyBinder` for `impl_subject` query)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit ec08676 into rust-lang:master Apr 14, 2023
@rustbot rustbot added this to the 1.70.0 milestone Apr 14, 2023
@seanlinsley seanlinsley deleted the patch-1 branch June 13, 2023 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants