- Notifications
You must be signed in to change notification settings - Fork 14.1k
Replace Rvalue::NullaryOp by a variant in mir::Operand. #148766
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
base: main
Are you sure you want to change the base?
Conversation
| Some changes occurred to the CTFE machinery Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr Some changes occurred in compiler/rustc_codegen_ssa Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt
cc @rust-lang/wg-const-eval Some changes occurred in cc @BoxyUwU Some changes occurred in src/tools/clippy cc @rust-lang/clippy This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @vakaras Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri This PR changes rustc_public cc @oli-obk, @celinval, @ouz-a Some changes occurred in match checking cc @Nadrieril Some changes occurred to constck cc @fee1-dead This PR changes a file inside |
This comment has been minimized.
This comment has been minimized.
9560745 to 741855c Compare This comment has been minimized.
This comment has been minimized.
741855c to dcf0916 Compare | /// Special constants whose value depends on the evaluation context. Their value depends on a | ||
| /// flag on the crate being codegenned. | ||
| RuntimeChecks(RuntimeChecks), |
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.
For const-eval execution, their value is fixed, right?
| It seems slightly odd to call these things "constants" when they have a different value inside and outside of const blocks... I am not sure whether this actually breaks anything today, but it seems at least conceptually suboptimal and could lead to issues down the line. For instance, if a constant's body entirely consists just of one of these new constants, then replacing that outer constant by the inner one is not correct (or at least, it can change program behavior) -- so e.g. @saethlin's "trivial const" machinery might need a special case for this. |
| ☔ The latest upstream changes (presumably #148658) made this pull request unmergeable. Please resolve the merge conflicts. |
| I agree that's not entirely satisfactory. Another design would put the variant inside |
| That would be marginally better ("values" really should be unchanging), though still a footgun e.g. with the trivial const machinery I mentioned. Making them a new variant of |
dcf0916 to 76bdfae Compare This comment has been minimized.
This comment has been minimized.
76bdfae to 68c2a27 Compare This comment has been minimized.
This comment has been minimized.
Latest commit does that. Cleaner than I expected. |
This comment has been minimized.
This comment has been minimized.
68c2a27 to 4183df4 Compare This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| // We can't look at `tcx.sess` here as that can differ across crates, which can lead to | ||
| // unsound differences in evaluating the same constant at different instantiation sites. |
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 comment doesn't really make sense in the dummy machine.
| Constant(ref a) => write!(fmt, "{a:?}"), | ||
| Copy(ref place) => write!(fmt, "copy {place:?}"), | ||
| Move(ref place) => write!(fmt, "move {place:?}"), | ||
| RuntimeChecks(checks) => write!(fmt, "const {checks:?}"), |
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.
"const" is an odd choice, given that we moved it out of the constants
4183df4 to 06de909 Compare This comment has been minimized.
This comment has been minimized.
| @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Replace Rvalue::NullaryOp by a variant in mir::Operand.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| Finished benchmarking commit (f642b25): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -0.1%, secondary -0.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -1.8%, secondary -1.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.1%, secondary -0.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 474.558s -> 478.183s (0.76%) |
| ☔ The latest upstream changes (presumably #147827) made this pull request unmergeable. Please resolve the merge conflicts. |
c15eb6e to 272a51b Compare | This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
| r? @RalfJung maybe? didn't even realize I was assigned |
| What do we do with these perf numbers? It's a mixed bag, but for primary benchmarks the median is red. |
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.
Everything MIR-related LGTM, modulo minor comments.
However, as noted before, I'm not sure how to judge whether those perf regressions are acceptable, or where they even come from. @saethlin do you have thoughts on that?
| Operand::Constant(const_) => crate::constant::codegen_constant_operand(fx, const_), | ||
| Operand::RuntimeChecks(checks) => { | ||
| let int = checks.value(fx.tcx.sess); | ||
| let int = ScalarInt::try_from_uint(int, Size::from_bits(1)).unwrap(); |
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.
ScalarInt implements From<bool> -- please use that instead of effectively inlining it. (Also, int is a confusing name for a boolean variable.)
| match operand { | ||
| Operand::RuntimeChecks(checks) => { | ||
| let int = checks.value(fx.tcx.sess); | ||
| ScalarInt::try_from_uint(int, Size::from_bits(1)) |
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.
Another place where the From<bool> impl could be used. (Also, int is a confusing name for a boolean variable.)
| let preserve_ub_checks = | ||
| attr::contains_name(tcx.hir_krate_attrs(), sym::rustc_preserve_ub_checks); | ||
| if !preserve_ub_checks { | ||
| SimplifyUbCheck { tcx }.visit_body(body); |
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 is this a separate visitor now?
| match operand { | ||
| Operand::Copy(place) | Operand::Move(place) => self.validate_place(place.as_ref()), | ||
| | ||
| // Promoting a runtime check would transform a runtime error into a compile-time error. |
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 isn't about promoting the actual check, but about promoting the value that determines whether there is a check... so the comment doesn't quite make sense to me.
| // Promoting a runtime check would transform a runtime error into a compile-time error. | |
| // `RuntimeChecks` behaves different in const-eval and runtime MIR, so we do not promote it. |
| format!("move {mv:?}") | ||
| } | ||
| Operand::Constant(cnst) => pretty_mir_const(&cnst.const_), | ||
| Operand::RuntimeChecks(checks) => format!("const {checks:?}"), |
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 shouldn't say "const".
Based on #148151
This PR fully removes the MIR
Rvalue::NullaryOp. After #148151, it was only useful for runtime checks likeub_checks,contract_checksandoverflow_checks.These are "runtime" checks, boolean constants that may only be
truein codegen. It depends on a rustc flag passed to codegen, so we need to represent those flags cross-crate.This PR replaces those runtime checks by special variants in MIR
ConstValue. This allows code that expects constants to manipulate those as such, even if we may not always be able to evaluate them to actual scalars.