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

Don't walk the bodies of free constants for reachability. #122505

Merged
merged 3 commits into from
Jun 6, 2024

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Mar 14, 2024

follow-up to #122371

cc #119214

This avoids codegening items (e.g. functions) that are only used during const eval, but do not reach their final constant value (e.g. via function pointers).

r? @tmiasko

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 14, 2024
@rustbot
Copy link
Collaborator

rustbot commented Mar 14, 2024

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@oli-obk
Copy link
Contributor Author

oli-obk commented Mar 14, 2024

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 14, 2024
@bors
Copy link
Contributor

bors commented Mar 14, 2024

⌛ Trying commit d46c98d with merge 5620969...

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 14, 2024
Don't walk the bodies of free constants for reachability.

follow-up to rust-lang#122371

we don't have generic constants yet, so we don't need to handle failure to eval a free constant.

Associated consts and generic consts will be a different topic, that I will look into in a follow-up

r? `@tmiasko`
@fmease
Copy link
Member

fmease commented Mar 14, 2024

What about generic_const_items? :P Or is that not what you meant?

@oli-obk
Copy link
Contributor Author

oli-obk commented Mar 14, 2024

Yea, those xD. I keep forgetting they already exist. Will add a test that hits my new span_bug

@oli-obk oli-obk added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 14, 2024
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Mar 14, 2024

☀️ Try build successful - checks-actions
Build commit: 5620969 (5620969908da123892bbe342730e38a9a6141180)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (5620969): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.3% [2.0%, 2.7%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.2% [-1.6%, -0.3%] 4
All ❌✅ (primary) 2.3% [2.0%, 2.7%] 3

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.7% [-4.3%, -0.9%] 6
Improvements ✅
(secondary)
-2.3% [-3.8%, -0.8%] 26
All ❌✅ (primary) -2.7% [-4.3%, -0.9%] 6

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
3.8% [3.1%, 4.5%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.8% [3.1%, 4.5%] 3

Binary size

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.0% [-0.1%, -0.0%] 6
Improvements ✅
(secondary)
-0.7% [-3.7%, -0.0%] 6
All ❌✅ (primary) -0.0% [-0.1%, -0.0%] 6

Bootstrap: 669.602s -> 670.27s (0.10%)
Artifact size: 310.86 MiB -> 310.86 MiB (0.00%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Mar 15, 2024
@oli-obk oli-obk added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 3, 2024
@tmiasko
Copy link
Contributor

tmiasko commented Jun 4, 2024

Left a question in a review comment, but other than that r=me. Thanks.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 4, 2024

@bors r=tmiasko

@bors
Copy link
Contributor

bors commented Jun 4, 2024

📌 Commit 66cca33 has been approved by tmiasko

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 Jun 4, 2024
@rust-log-analyzer

This comment has been minimized.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 4, 2024

huh... this still worked yesterday and is failing now...

@tmiasko
Copy link
Contributor

tmiasko commented Jun 4, 2024

Minimized reproducer (doesn't require changes from this pull request):

$ cat a.rs
pub static A: fn() -> fn() = {
    const {
        #[inline(never)]
        fn f() {}
        || -> fn() { f }
    }
};
$ cat b.rs
static A: fn() -> fn () = a::A;
fn main() { A()() }
$ rustc a.rs --crate-type=lib -Zprint-mono-items=lazy -O
MONO_ITEM fn <{[email protected]:5:9: 5:19} as std::ops::FnOnce<()>>::call_once - shim @@ a.a67665f9196cd4be-cgu.0[Internal]
MONO_ITEM fn A::f @@ a.a67665f9196cd4be-cgu.0[Internal]
MONO_ITEM fn A::{closure#0} @@ a.a67665f9196cd4be-cgu.0[Internal]
MONO_ITEM static A @@ a.a67665f9196cd4be-cgu.0[External]
$ rustc b.rs --crate-type=bin --extern a -L. 
error: missing optimized MIR for an item in the crate `a`
  |
note: missing optimized MIR for this item (was the crate `a` compiled with `--emit=metadata`?)
 --> /tmp/a.rs:4:9
  |
4 |         fn f() {}
  |         ^^^^^^

error: aborting due to 1 previous error
$ rustc --version
rustc 1.80.0-nightly (7c52d2db6 2024-06-03)

@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 4, 2024

oof, I hope this isn't hitting stable next week. Tho it would be easy to fix

@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 5, 2024

@bors r=tmiasko

@bors
Copy link
Contributor

bors commented Jun 5, 2024

📌 Commit a0358f4 has been approved by tmiasko

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 5, 2024
@bors
Copy link
Contributor

bors commented Jun 6, 2024

⌛ Testing commit a0358f4 with merge d0ccb54...

@bors
Copy link
Contributor

bors commented Jun 6, 2024

☀️ Test successful - checks-actions
Approved by: tmiasko
Pushing d0ccb54 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 6, 2024
@bors bors merged commit d0ccb54 into rust-lang:master Jun 6, 2024
7 checks passed
@rustbot rustbot added this to the 1.80.0 milestone Jun 6, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d0ccb54): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.8% [0.2%, 2.6%] 4
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.8% [0.2%, 2.6%] 4

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

Results (primary 2.8%, secondary -2.1%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.8% [2.3%, 3.2%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.1% [-2.1%, -2.1%] 1
All ❌✅ (primary) 2.8% [2.3%, 3.2%] 3

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 667.497s -> 669.842s (0.35%)
Artifact size: 319.04 MiB -> 319.03 MiB (-0.01%)

@Kobzol
Copy link
Contributor

Kobzol commented Jun 11, 2024

This had a few instruction count wins, and also binary size wins before merge, but no binary size wins after merge. Was that expected? In any case, the regression is small and only on a single benchmark, so I don't need that we need to investigate further, just wanted to ask, especially about the missing binary size wins.

@RalfJung
Copy link
Member

I don't think I understand why being a free constant vs an associated constant makes a difference here. Even for free constants we store their MIR, not their computed result, in the rmeta, right?

@RalfJung
Copy link
Member

Ah I think I get it... I have clarified the comments in #126259.

@oli-obk oli-obk deleted the visit_nested_body2 branch June 11, 2024 07:09
@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 11, 2024

Yea, we could evaluate associated constants, often even generic ones can be evaluated to a concrete value.

@RalfJung
Copy link
Member

RalfJung commented Jun 11, 2024 via email

@Kobzol
Copy link
Contributor

Kobzol commented Jun 11, 2024

Marking as triaged after a discussion with Oli, the small perf. regression is expected.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Jun 11, 2024
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Jun 11, 2024
reachable computation: clarify comments around consts

Follow-up to rust-lang#122505
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jun 11, 2024
Rollup merge of rust-lang#126259 - RalfJung:reachable-const, r=oli-obk

reachable computation: clarify comments around consts

Follow-up to rust-lang#122505
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants