Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/rustc_codegen_ssa/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
let llfn = cx.get_fn(instance);

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

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

/// Replace `clone` calls that come from `use` statements with direct copies if possible.
// FIXME: Move this function to mir::transform when post-mono MIR passes land.
fn optimize_use_clone<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
cx: &'a Bx::CodegenCx,
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_middle/src/middle/deduced_param_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rustc_macros::{Decodable, Encodable, HashStable};
use crate::ty::{Ty, TyCtxt, TypingEnv};

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

Expand Down Expand Up @@ -53,6 +53,7 @@ impl DeducedParamAttrs {
ty: Ty<'tcx>,
) -> bool {
let read_only = self.read_only;
// We have to check *all* set bits; only if all checks pass is this truly read-only.
if read_only.contains(DeducedReadOnlyParam::MUTATED) {
return false;
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_mir_transform/src/deduce_param_attrs.rs
Copy link
Member Author

@RalfJung RalfJung Oct 19, 2025

Choose a reason for hiding this comment

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

Codegen actually uses instance_mir so using optimized_mir here seems a bit inconsistent?
Things could go quite wrong if they end up using different MIR...

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
//! body of the function instead of just the signature. These can be useful for optimization
//! purposes on a best-effort basis. We compute them here and store them into the crate metadata so
//! dependent crates can use them.
//!
//! Note that this *crucially* relies on codegen *not* doing any more MIR-level transformations
//! after `optimized_mir`! We check for things that are *not* guaranteed to be preserved by MIR
//! transforms, such as which local variables happen to be mutated.

use rustc_hir::def_id::LocalDefId;
use rustc_index::IndexVec;
Expand Down
Loading