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

move required_consts check to general post-mono-check function #115748

Merged
merged 2 commits into from Sep 18, 2023

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Sep 11, 2023

This factors some code that is common between the interpreter and the codegen backends into shared helper functions. Also as a side-effect the interpreter now uses the same eval functions as everyone else to get the evaluated MIR constants.

Also this is in preparation for another post-mono check that will be needed for (the current hackfix for) #115709: ensuring that all locals are dynamically sized.

I didn't expect this to change diagnostics, but it's just cycle errors that change.

r? @oli-obk

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative labels Sep 11, 2023
@rustbot
Copy link
Collaborator

rustbot commented Sep 11, 2023

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

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

Some changes occurred in const_evaluatable.rs

cc @BoxyUwU

| ty::ConstKind::Expr(..) => return Err(ErrorHandled::TooGeneric(const_.span)),
},
ConstantKind::Unevaluated(uv, _) => uv,
ConstantKind::Val(..) => return Ok(()),
Copy link
Member Author

Choose a reason for hiding this comment

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

We have this kind of match in a bunch of places (here, interpret, codegen_ssa, codegen_cranelift). There doesn't happen to be some eval function we can call instead? There are eval methods on constants but they return a constant again, i.e. the return type doesn't reflect that anything was evaluated -- not quite what I was expecting from an eval function.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not clear what we can return from such an eval method, we'd need a new enum that can represent Valtree | ConstValue. But yea, would be nice if we could share more code in situations like this

Copy link
Member Author

@RalfJung RalfJung Sep 11, 2023

Choose a reason for hiding this comment

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

Why do we need a new enum? For ty::Const it's a Valtree, for mir::Const it's a ConstValue.

Copy link
Contributor

@oli-obk oli-obk Sep 11, 2023

Choose a reason for hiding this comment

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

mir::Const would then need to convert Valtree to ConstValue in case it starts out with an evaluated ty::Const.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's what I would expect to happen, indeed. Miri/const-eval already do that.

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 seems to actually have worked. :)

@rust-log-analyzer

This comment has been minimized.

cx.tcx().sess.diagnostic().emit_bug(errors::PolymorphicConstantTooGeneric { span });
}
Err(ErrorHandled::Reported(_, span)) => {
cx.tcx().sess.emit_err(errors::ErroneousConstant { span });
Copy link
Member

Choose a reason for hiding this comment

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

Maybe handle TooGeneric entirely inside post_mono_checks, and for Reported emit the error inside it and return Err(()) to allow the backend to skip codegen for the function?

Copy link
Member Author

@RalfJung RalfJung Sep 11, 2023

Choose a reason for hiding this comment

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

One of the goals was to share this code with const-eval, and in const-eval TooGeneric can unfortunately occur since const generics will (try to) evaluate generic MIR. At least I got tons of ICEs when I tried to handle TooGeneric in post_mono_checks. (There's a doc comment at post_mono_checks explaining this.)

@rustbot
Copy link
Collaborator

rustbot commented Sep 11, 2023

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

Some changes occurred in const_evaluatable.rs

cc @BoxyUwU

Some changes might have occurred in exhaustiveness checking

cc @Nadrieril

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Sep 11, 2023

The Miri subtree was changed

cc @rust-lang/miri

@RalfJung RalfJung force-pushed the post-mono branch 2 times, most recently from 937560c to 7076372 Compare September 11, 2023 10:56
@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the post-mono branch 2 times, most recently from 2a11ab7 to 3aa3e8b Compare September 11, 2023 11:11
@RalfJung
Copy link
Member Author

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

bors commented Sep 11, 2023

⌛ Trying commit e0b833e with merge 0ae715c...

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 11, 2023
move required_consts check to general post-mono-check function

I was hoping this would simplify the code. That didn't entirely happen, but I still think it could be useful to have a single place for the "required const" check -- and this does simplify some code in codegen, where the const-eval functions no longer have to return a `Result`.

Also this is in preparation for another post-mono check that will be needed for (the current hackfix for) rust-lang#115709: ensuring that all locals are dynamically sized.

I didn't expect this to change diagnostics, but the changes seem either harmless (for the cycle errors) or improvements (where more spans are shown when something goes wrong in a constant).

r? `@oli-obk`
@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member Author

I was worried about regressions and I'm getting improvements. I'll take it. :) For the stress test that even more than evens out the regressions from my other changes the last weeks. ;)

@rustbot ready

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 14, 2023
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Sep 15, 2023
make the eval() functions on our const types return the resulting value

This is a part of rust-lang/rust#115748 that's hopefully perf-neutral, and that does not depend on rust-lang/rust#115764.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Sep 15, 2023
Do not clone the Body for ConstProp

~Based on rust-lang/rust#115748 for the `POST_MONO_CHECKS` flag.~
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Sep 15, 2023
consistently pass ty::Const through valtrees

Some drive-by things extracted from rust-lang/rust#115748.
@oli-obk
Copy link
Contributor

oli-obk commented Sep 18, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Sep 18, 2023

📌 Commit 9ac8b36 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 18, 2023
@bors
Copy link
Contributor

bors commented Sep 18, 2023

⌛ Testing commit 9ac8b36 with merge 4937664...

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 18, 2023
move required_consts check to general post-mono-check function

This factors some code that is common between the interpreter and the codegen backends into shared helper functions. Also as a side-effect the interpreter now uses the same `eval` functions as everyone else to get the evaluated MIR constants.

Also this is in preparation for another post-mono check that will be needed for (the current hackfix for) rust-lang#115709: ensuring that all locals are dynamically sized.

I didn't expect this to change diagnostics, but it's just cycle errors that change.

r? `@oli-obk`
@rust-log-analyzer
Copy link
Collaborator

The job dist-aarch64-linux failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@bors
Copy link
Contributor

bors commented Sep 18, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 18, 2023
@oli-obk
Copy link
Contributor

oli-obk commented Sep 18, 2023

@bors retry failed to download from [https://crates.io/api/v1/crates/minifier/0.2.2/download](https://crates.io/api/v1/crates/minifier/0.2.2/download%60)

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

bors commented Sep 18, 2023

⌛ Testing commit 9ac8b36 with merge cebb9cf...

@bors
Copy link
Contributor

bors commented Sep 18, 2023

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

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

Finished benchmarking commit (cebb9cf): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -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
Regressions ❌
(secondary)
0.5% [0.5%, 0.5%] 1
Improvements ✅
(primary)
-5.0% [-6.3%, -3.6%] 2
Improvements ✅
(secondary)
-6.1% [-6.6%, -5.7%] 6
All ❌✅ (primary) -5.0% [-6.3%, -3.6%] 2

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.6% [0.6%, 0.6%] 2
Improvements ✅
(primary)
-1.1% [-1.1%, -1.1%] 1
Improvements ✅
(secondary)
-3.3% [-4.8%, -1.5%] 4
All ❌✅ (primary) -1.1% [-1.1%, -1.1%] 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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-5.7% [-7.7%, -3.7%] 2
Improvements ✅
(secondary)
-3.9% [-3.9%, -3.7%] 3
All ❌✅ (primary) -5.7% [-7.7%, -3.7%] 2

Binary size

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

Bootstrap: 633.591s -> 631.896s (-0.27%)
Artifact size: 318.00 MiB -> 317.84 MiB (-0.05%)

@RalfJung RalfJung deleted the post-mono branch September 19, 2023 08:05
remi-delmas-3000 pushed a commit to remi-delmas-3000/kani that referenced this pull request Sep 19, 2023
flip1995 pushed a commit to flip1995/rust that referenced this pull request Sep 25, 2023
move required_consts check to general post-mono-check function

This factors some code that is common between the interpreter and the codegen backends into shared helper functions. Also as a side-effect the interpreter now uses the same `eval` functions as everyone else to get the evaluated MIR constants.

Also this is in preparation for another post-mono check that will be needed for (the current hackfix for) rust-lang#115709: ensuring that all locals are dynamically sized.

I didn't expect this to change diagnostics, but it's just cycle errors that change.

r? `@oli-obk`
bjorn3 pushed a commit to bjorn3/rust that referenced this pull request Oct 9, 2023
move required_consts check to general post-mono-check function

This factors some code that is common between the interpreter and the codegen backends into shared helper functions. Also as a side-effect the interpreter now uses the same `eval` functions as everyone else to get the evaluated MIR constants.

Also this is in preparation for another post-mono check that will be needed for (the current hackfix for) rust-lang#115709: ensuring that all locals are dynamically sized.

I didn't expect this to change diagnostics, but it's just cycle errors that change.

r? `@oli-obk`
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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants