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

make the eval() functions on our const types return the resulting value #115803

Merged
merged 3 commits into from
Sep 13, 2023

Conversation

RalfJung
Copy link
Member

This is a part of #115748 that's hopefully perf-neutral, and that does not depend on #115764.

@rustbot
Copy link
Collaborator

rustbot commented Sep 12, 2023

r? @b-naber

(rustbot has picked a reviewer for you, use r? to override)

@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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Sep 12, 2023
@rustbot
Copy link
Collaborator

rustbot commented Sep 12, 2023

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes might have occurred in exhaustiveness checking

cc @Nadrieril

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

ConstantKind::Ty(c) => {
if let ty::ConstKind::Unevaluated(uv) = c.kind() {
// Avoid the round-trip via valtree, evaluate directly to ConstValue.
uv.expand()
Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to start with as small a change as possible, so this avoids the intermediate valtree for now.

@RalfJung
Copy link
Member Author

r? @oli-obk
@bors try
@rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot assigned oli-obk and unassigned b-naber Sep 12, 2023
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 12, 2023
@bors
Copy link
Contributor

bors commented Sep 12, 2023

⌛ Trying commit 35fa022 with merge 9aa0bc9...

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 12, 2023
make the eval() functions on our const types return the resulting value

This is a part of rust-lang#115748 that's hopefully perf-neutral, and that does not depend on rust-lang#115764.
@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member Author

@bors try

@bors
Copy link
Contributor

bors commented Sep 12, 2023

⌛ Trying commit 6086a68 with merge d9931dc...

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 12, 2023
make the eval() functions on our const types return the resulting value

This is a part of rust-lang#115748 that's hopefully perf-neutral, and that does not depend on rust-lang#115764.
@bors
Copy link
Contributor

bors commented Sep 12, 2023

☀️ Try build successful - checks-actions
Build commit: d9931dc (d9931dc754958a938ba2dd00bb8166923191dcec)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d9931dc): comparison URL.

Overall result: ❌ regressions - 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)
0.8% [0.3%, 1.4%] 12
Regressions ❌
(secondary)
0.8% [0.4%, 1.3%] 11
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.8% [0.3%, 1.4%] 12

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)
2.3% [0.7%, 3.8%] 2
Improvements ✅
(primary)
-0.6% [-0.6%, -0.6%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.6% [-0.6%, -0.6%] 1

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.2% [1.5%, 5.2%] 5
Regressions ❌
(secondary)
2.2% [2.2%, 2.2%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.2% [1.5%, 5.2%] 5

Binary size

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

Bootstrap: 631.022s -> 629.231s (-0.28%)
Artifact size: 317.92 MiB -> 317.34 MiB (-0.18%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Sep 13, 2023
tcx.erase_regions(param_env)
.with_reveal_all_normalized(tcx)
.and(tcx.erase_regions(unevaluated))
};
Copy link
Member Author

Choose a reason for hiding this comment

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

This is some magic that only the Valtree path has, maybe that's where the perf diff comes from?

@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 Sep 13, 2023
@bors
Copy link
Contributor

bors commented Sep 13, 2023

⌛ Trying commit 2c1c85b with merge 1c3b6c4...

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 13, 2023
make the eval() functions on our const types return the resulting value

This is a part of rust-lang#115748 that's hopefully perf-neutral, and that does not depend on rust-lang#115764.
@bors
Copy link
Contributor

bors commented Sep 13, 2023

☀️ Try build successful - checks-actions
Build commit: 1c3b6c4 (1c3b6c4ebfd55a4d61ff506771dcd8cc9eaa76f1)

1 similar comment
@bors
Copy link
Contributor

bors commented Sep 13, 2023

☀️ Try build successful - checks-actions
Build commit: 1c3b6c4 (1c3b6c4ebfd55a4d61ff506771dcd8cc9eaa76f1)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1c3b6c4): comparison URL.

Overall result: no relevant changes - no 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.

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

Instruction count

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

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)
3.9% [3.9%, 3.9%] 1
Regressions ❌
(secondary)
0.6% [0.6%, 0.6%] 1
Improvements ✅
(primary)
-2.8% [-4.1%, -1.5%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.6% [-4.1%, 3.9%] 3

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)
- - 0
Regressions ❌
(secondary)
2.2% [1.9%, 2.4%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 631.557s -> 631.698s (0.02%)
Artifact size: 317.99 MiB -> 317.79 MiB (-0.06%)

@rustbot rustbot removed S-waiting-on-perf Status: Waiting on a perf run to be completed. perf-regression Performance regression. labels Sep 13, 2023
@RalfJung
Copy link
Member Author

Nice, so that prepare_for_eval function seems to be the key then. :)

Should be ready to land. This can be further cleaned up, but given how perf-sensitive this is I like landing this in small chunks that can be separately benchmarked.

Further cleanup would be:

  • In MIR const fn eval, call the ty const fn eval and then do valtree-to-value conversion. But this changes the data flow through our queries, unlike the current PR which should be a complete NOP in terms of queries.
  • Also use the new fn eval in the interpreter. This needs some ConstValue refactoring #115764 to avoid fresh AllocId generation from going via ConstValue instead of directly via raw constants.


/// Normalizes the constant to a value or an error if possible.
#[inline]
pub fn normalize(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want this method to translate a ValTree into a ConstValue? For normalization, it may be more interesting to keep the ValTree unchanged, as it is already a legal value.

Copy link
Member Author

@RalfJung RalfJung Sep 13, 2023

Choose a reason for hiding this comment

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

This is a MIR constant, its normal form is a ConstValue. (Also this matches prior behavior.)

If we leave this as a valtree, then every future call to eval has to do the conversion again. That seems like a lot of wasted effort.

@oli-obk
Copy link
Contributor

oli-obk commented Sep 13, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Sep 13, 2023

📌 Commit 8ef6b7a has been approved by oli-obk

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 Sep 13, 2023
@bors
Copy link
Contributor

bors commented Sep 13, 2023

⌛ Testing commit 8ef6b7a with merge 76e59c7...

@bors
Copy link
Contributor

bors commented Sep 13, 2023

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 76e59c7 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 13, 2023
@bors bors merged commit 76e59c7 into rust-lang:master Sep 13, 2023
12 checks passed
@rustbot rustbot added this to the 1.74.0 milestone Sep 13, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (76e59c7): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

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

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)
1.0% [0.5%, 1.5%] 2
Improvements ✅
(primary)
-1.9% [-2.1%, -1.7%] 4
Improvements ✅
(secondary)
-3.2% [-3.2%, -3.2%] 1
All ❌✅ (primary) -1.9% [-2.1%, -1.7%] 4

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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.0% [-1.0%, -1.0%] 1
Improvements ✅
(secondary)
-2.8% [-3.1%, -2.5%] 2
All ❌✅ (primary) -1.0% [-1.0%, -1.0%] 1

Binary size

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

Bootstrap: 632.169s -> 632.671s (0.08%)
Artifact size: 317.92 MiB -> 317.85 MiB (-0.02%)

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. 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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants