Skip to content

Commit b4f28c6

Browse files
committed
Auto merge of #147884 - matthiaskrgr:rollup-pjqcccz, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #147575 (Refactor move analysis subpath representation) - #147864 (Parse `const unsafe trait` properly) - #147868 (MirPatch: Simplify new_local.) - #147873 (comments for deduce_param_attrs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c6efb90 + 362c9e2 commit b4f28c6

File tree

11 files changed

+374
-203
lines changed

11 files changed

+374
-203
lines changed

compiler/rustc_codegen_ssa/src/mir/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
180180
let llfn = cx.get_fn(instance);
181181

182182
let mut mir = tcx.instance_mir(instance.def);
183+
// Note that the ABI logic has deduced facts about the functions' parameters based on the MIR we
184+
// got here (`deduce_param_attrs`). That means we can *not* apply arbitrary further MIR
185+
// transforms as that may invalidate those deduced facts!
183186

184187
let fn_abi = cx.fn_abi_of_instance(instance, ty::List::empty());
185188
debug!("fn_abi: {:?}", fn_abi);
@@ -317,6 +320,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
317320
}
318321
}
319322

323+
/// Replace `clone` calls that come from `use` statements with direct copies if possible.
320324
// FIXME: Move this function to mir::transform when post-mono MIR passes land.
321325
fn optimize_use_clone<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
322326
cx: &'a Bx::CodegenCx,

compiler/rustc_middle/src/middle/deduced_param_attrs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_macros::{Decodable, Encodable, HashStable};
33
use crate::ty::{Ty, TyCtxt, TypingEnv};
44

55
/// Flags that dictate how a parameter is mutated. If the flags are empty, the param is
6-
/// read-only. If non-empty, it is read-only with conditions.
6+
/// read-only. If non-empty, it is read-only if *all* flags' conditions are met.
77
#[derive(Clone, Copy, PartialEq, Debug, Decodable, Encodable, HashStable)]
88
pub struct DeducedReadOnlyParam(u8);
99

@@ -53,6 +53,7 @@ impl DeducedParamAttrs {
5353
ty: Ty<'tcx>,
5454
) -> bool {
5555
let read_only = self.read_only;
56+
// We have to check *all* set bits; only if all checks pass is this truly read-only.
5657
if read_only.contains(DeducedReadOnlyParam::MUTATED) {
5758
return false;
5859
}

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ pub enum RuntimePhase {
137137
/// And the following variants are allowed:
138138
/// * [`StatementKind::Retag`]
139139
/// * [`StatementKind::SetDiscriminant`]
140+
/// * [`PlaceElem::ConstantIndex`] / [`PlaceElem::Subslice`] after [`PlaceElem::Subslice`]
140141
///
141142
/// Furthermore, `Copy` operands are allowed for non-`Copy` types.
142143
Initial = 0,
@@ -1246,6 +1247,9 @@ pub enum ProjectionElem<V, T> {
12461247
///
12471248
/// If `from_end` is true `slice[from..slice.len() - to]`.
12481249
/// Otherwise `array[from..to]`.
1250+
///
1251+
/// This projection cannot have `ConstantIndex` or additional `Subslice` projections after it
1252+
/// before runtime MIR.
12491253
Subslice {
12501254
from: u64,
12511255
to: u64,

0 commit comments

Comments
 (0)