-
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
Ban ArrayToPointer
and MutToConstPointer
from runtime MIR
#126308
Conversation
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras |
How that? Can't GVN use an "or" pattern to cover all these cases together? To me, banning them seems more complicated than simply allowing them. |
@@ -506,6 +507,7 @@ fn run_analysis_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { | |||
/// Returns the sequence of passes that lowers analysis to runtime MIR. | |||
fn run_runtime_lowering_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { | |||
let passes: &[&dyn MirPass<'tcx>] = &[ | |||
&coercions_to_casts::CoercionsToCasts, |
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 not inside 'cleanup_post_borrowck' ?
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.
Because I was thinking of it as part of Analysis->Runtime, and that pass is inside Analysis Initial->PostCleanup.
I could move it there and make it part of the https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/syntax/enum.AnalysisPhase.html#variant.PostCleanup disallow list if you'd prefer? (I don't have particularly strong opinions about exactly when it should happen, so I'll take your advice here.)
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.
I was thinking about this more, and decided that it's easier to write the why comment when it's in cleanup_post_borrowck
, so I moved it there, and adjusted them to be banned starting in Analysis(PostCleanup)
rather than just in Runtime(..)
.
I see it less as being about the code that's typed are more about "is it clear how you should think about things". For example, today GVN groups these three here rust/compiler/rustc_mir_transform/src/gvn.rs Lines 575 to 579 in f158600
but then only has rust/compiler/rustc_mir_transform/src/gvn.rs Lines 1168 to 1171 in f158600
Is that right? Should the former have I think it's much simpler when the answer to those things is "as it says on |
What about grouping all of these together in a single CastKind variant This is not a strong opinion though, I just feel like this PR is using the MIR validation to work around CastKind just not being of the right shape for some of its consumers. |
@@ -143,6 +143,9 @@ pub enum RuntimePhase { | |||
/// * [`TerminatorKind::CoroutineDrop`] | |||
/// * [`Rvalue::Aggregate`] for any `AggregateKind` except `Array` | |||
/// * [`PlaceElem::OpaqueCast`] | |||
/// * [`CastKind::PointerCoercion`] with any of the following: | |||
/// * [`PointerCoercion::ArrayToPointer`] | |||
/// * [`PointerCoercion::MutToConstPointer`] |
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.
compiler/rustc_const_eval/src/interpret/cast.rs should then probably also explicitly panic on these casts.
Ah, we have have this inner enum, |
I first tried just banning these from MIR altogether, but doing that meant there were some missing errors in one of the borrowck tests. I don't have the failure handy, but I think it was this one: rust/tests/ui/nll/type-check-pointer-coercions.rs Lines 15 to 17 in f158600
So it's checks about lifetimes inside the pointee, I guess? |
I would expect the lifetimes in that test to be a red herring -- |
Ah no never mind, I shouldn't write comments when I am too tired... on a mut-to-const implicit coercion, the type needs to stay the same, and the lifetime equality part of "the same" is checked by borrowck. |
So I agree with this, but I'm not sure how to action on it. I don't really want to change https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/thir/enum.ExprKind.html#variant.PointerCoercion, and if we're stuck representing the distinction in MIR anyway, I don't know how helpful restructuring it would be. What I've grokked here is that early MIR does need this distinction for borrowchecking coercions, but that coercion vs cast distinction is irrelevant in runtime MIR. So it doesn't sound that bad to me to just ban the borrowck-parts in later MIR phases, as I'm doing here? Even if we rearranged these cases to different |
I don't have a concrete proposal either, and it seems you considered the alternatives, so my concern isn't blocking. I feel like there's got to be a better way but don't feel strongly enough about it to try and find it. ;) |
05f597c
to
55fc6bd
Compare
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
I'm okay with this change because it makes the runtime MIR dialect more sensible. I don't know how much this actually matters in practice, clearly it lets you clean up MIR transforms if you know what you're doing. But the fact that the enum variants still exist because all MIR dialects are the same type still makes implementing transforms confusing. @bors r+ |
…thlin Ban `ArrayToPointer` and `MutToConstPointer` from runtime MIR Zulip conversation: <https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/CastKind.3A.3APointerCoercion.20in.20Runtime.20MIR/near/443955195> Apparently MIR borrowck cares about at least one of these for checking variance. In runtime MIR, though, there's no need for them as `PtrToPtr` does the same thing. (Banning them simplifies passes like GVN that no longer need to handle multiple cast possibilities.) r? mir
…thlin Ban `ArrayToPointer` and `MutToConstPointer` from runtime MIR Zulip conversation: <https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/CastKind.3A.3APointerCoercion.20in.20Runtime.20MIR/near/443955195> Apparently MIR borrowck cares about at least one of these for checking variance. In runtime MIR, though, there's no need for them as `PtrToPtr` does the same thing. (Banning them simplifies passes like GVN that no longer need to handle multiple cast possibilities.) r? mir
Apparently MIR borrowck cares about at least one of these for checking variance. In runtime MIR, though, there's no need for them as `PtrToPtr` does the same thing. (Banning them simplifies passes like GVN that no longer need to handle multiple cast possibilities.)
64bba35
to
e04e351
Compare
Rebased and re-blessed. @bors r=saethlin rollup=iffy (already failed in a rollup once) |
…thlin Ban `ArrayToPointer` and `MutToConstPointer` from runtime MIR Zulip conversation: <https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/CastKind.3A.3APointerCoercion.20in.20Runtime.20MIR/near/443955195> Apparently MIR borrowck cares about at least one of these for checking variance. In runtime MIR, though, there's no need for them as `PtrToPtr` does the same thing. (Banning them simplifies passes like GVN that no longer need to handle multiple cast possibilities.) r? mir
Rollup of 7 pull requests Successful merges: - rust-lang#124807 (Migrate `run-make/rustdoc-io-error` to `rmake.rs`) - rust-lang#126095 (Migrate `link-args-order`, `ls-metadata` and `lto-readonly-lib` `run-make` tests to `rmake`) - rust-lang#126308 (Ban `ArrayToPointer` and `MutToConstPointer` from runtime MIR) - rust-lang#126620 (Actually taint InferCtxt when a fulfillment error is emitted) - rust-lang#126629 (Migrate `run-make/compressed-debuginfo` to `rmake.rs`) - rust-lang#126644 (Rewrite `extern-flag-rename-transitive`. `debugger-visualizer-dep-info`, `metadata-flag-frobs-symbols`, `extern-overrides-distribution` and `forced-unwind-terminate-pof` `run-make` tests to rmake) - rust-lang#126650 (Rename a bunch of things in the new solver and `rustc_type_ir`) r? `@ghost` `@rustbot` modify labels: rollup
…thlin Ban `ArrayToPointer` and `MutToConstPointer` from runtime MIR Zulip conversation: <https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/CastKind.3A.3APointerCoercion.20in.20Runtime.20MIR/near/443955195> Apparently MIR borrowck cares about at least one of these for checking variance. In runtime MIR, though, there's no need for them as `PtrToPtr` does the same thing. (Banning them simplifies passes like GVN that no longer need to handle multiple cast possibilities.) r? mir
☀️ Test successful - checks-actions |
Finished benchmarking commit (3d5d7a2): 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)Results (primary -2.4%, secondary 3.9%)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.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 692.485s -> 691.149s (-0.19%) |
Zulip conversation: https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/CastKind.3A.3APointerCoercion.20in.20Runtime.20MIR/near/443955195
Apparently MIR borrowck cares about at least one of these for checking variance.
In runtime MIR, though, there's no need for them as
PtrToPtr
does the same thing.(Banning them simplifies passes like GVN that no longer need to handle multiple cast possibilities.)
r? mir