-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Conversation
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 cc @BoxyUwU |
compiler/rustc_middle/src/mir/mod.rs
Outdated
| ty::ConstKind::Expr(..) => return Err(ErrorHandled::TooGeneric(const_.span)), | ||
}, | ||
ConstantKind::Unevaluated(uv, _) => uv, | ||
ConstantKind::Val(..) => return Ok(()), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. :)
This comment has been minimized.
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 }); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.)
Some changes occurred to the core trait solver cc @rust-lang/initiative-trait-system-refactor Some changes occurred in 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 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The Miri subtree was changed cc @rust-lang/miri |
937560c
to
7076372
Compare
This comment has been minimized.
This comment has been minimized.
2a11ab7
to
3aa3e8b
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
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`
This comment has been minimized.
This comment has been minimized.
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 |
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.
Do not clone the Body for ConstProp ~Based on rust-lang/rust#115748 for the `POST_MONO_CHECKS` flag.~
consistently pass ty::Const through valtrees Some drive-by things extracted from rust-lang/rust#115748.
@bors r+ |
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`
💔 Test failed - checks-actions |
@bors retry failed to download from |
☀️ Test successful - checks-actions |
Finished benchmarking commit (cebb9cf): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesResultsThis 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.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 633.591s -> 631.896s (-0.27%) |
Propagate changes from rust-lang/rust#115748.
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`
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`
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