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

Inline const_eval_select #98059

Merged
merged 1 commit into from
Jun 16, 2022
Merged

Conversation

tmiasko
Copy link
Contributor

@tmiasko tmiasko commented Jun 13, 2022

To avoid circular link time dependency between core and compiler
builtins when building with -Zshare-generics.

r? @Amanieu

To avoid circular link time dependency between core and compiler
builtins when building with `-Zshare-generics`.
@rust-highfive
Copy link
Collaborator

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

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Jun 13, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 13, 2022
@Amanieu
Copy link
Member

Amanieu commented Jun 13, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Jun 13, 2022

📌 Commit 8a8404b has been approved by Amanieu

@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 Jun 13, 2022
@bjorn3
Copy link
Member

bjorn3 commented Jun 13, 2022

Shouldn't

let rt_f32_to_u32 = |rt| unsafe { mem::transmute::<f32, u32>(rt) };
and the equivalent f64 closures be inlined too? (And preferably turned into functions to also help debug mode)

@tmiasko
Copy link
Contributor Author

tmiasko commented Jun 13, 2022

Are you referring to a situation where we would generate an internal copy of to_bits, const_eval_select in the compiler builtins but attempt to link to a closure function exported from the core? As far as I know, whenever #[inline] functions generate CGU internal copies so do the closures, so this shouldn't be possible.

And preferably turned into functions to also help debug mode

What is the implied difference between the closures and functions? And how does using functions help in debug mode?

@bjorn3
Copy link
Member

bjorn3 commented Jun 13, 2022

As far as I know, whenever #[inline] functions generate CGU internal copies so do the closures, so this shouldn't be possible.

I see.

What is the implied difference between the closures and functions?

Closure calls seem to generate significantly more code: https://rust.godbolt.org/z/KaP4rKzoa Basically instead of a direct call of the closure function itself, FnOnce::call_once is called, which then calls the closure function.

And how does using functions help in debug mode?

Less llvm ir generated -> lower compile time & better runtime performance in debug mode

@tmiasko
Copy link
Contributor Author

tmiasko commented Jun 13, 2022

The extra indirection is a shim that adapts Fn / FnMut closure to FnOnce. Functions would also use a shim in this context.

@bjorn3
Copy link
Member

bjorn3 commented Jun 13, 2022

I see. Would be nice to somehow remove the need for that shim in the context of const_eval_select.

@tmiasko
Copy link
Contributor Author

tmiasko commented Jun 13, 2022

If closure captures a non-copy value then it would be FnOnce and shim will be omitted. Not exactly a serious proposal, but it's possible :-).

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jun 15, 2022
…=Amanieu

Inline `const_eval_select`

To avoid circular link time dependency between core and compiler
builtins when building with `-Zshare-generics`.

r? `@Amanieu`
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jun 15, 2022
…=Amanieu

Inline `const_eval_select`

To avoid circular link time dependency between core and compiler
builtins when building with `-Zshare-generics`.

r? ``@Amanieu``
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 15, 2022
Rollup of 7 pull requests

Successful merges:

 - rust-lang#97202 (os str capacity documentation)
 - rust-lang#97964 (Fix suggestions for `&a: T` parameters)
 - rust-lang#98053 (Fix generic impl rustdoc json output)
 - rust-lang#98059 (Inline `const_eval_select`)
 - rust-lang#98092 (Fix sidebar items expand collapse)
 - rust-lang#98119 (Refactor path segment parameter error)
 - rust-lang#98135 (Add regression test for rust-lang#93775)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit b91c4d5 into rust-lang:master Jun 16, 2022
@rustbot rustbot added this to the 1.63.0 milestone Jun 16, 2022
@tmiasko tmiasko deleted the inline-const-eval-select branch June 16, 2022 07:35
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.

None yet

6 participants