1
Fork 0

Rollup merge of #115293 - cjgillot:no-fuel, r=wesleywiser,DianQK

Remove -Zfuel.

I'm not sure this feature is used. I only found 2 references in a google search, both referring to its introduction.

Meanwhile, it's a global mutable state, untracked by incremental compilation, so incompatible with it.
This commit is contained in:
Michael Goulet 2024-11-26 20:35:36 -05:00 committed by GitHub
commit 145df3bd70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 19 additions and 293 deletions

View file

@ -217,11 +217,6 @@ impl<'tcx> crate::MirPass<'tcx> for DestinationPropagation {
else {
continue;
};
if !tcx.consider_optimizing(|| {
format!("{} round {}", tcx.def_path_str(def_id), round_count)
}) {
break;
}
// Replace `src` by `dest` everywhere.
merges.insert(*src, *dest);

View file

@ -108,10 +108,6 @@ impl<'tcx> crate::MirPass<'tcx> for EarlyOtherwiseBranch {
let parent = BasicBlock::from_usize(i);
let Some(opt_data) = evaluate_candidate(tcx, body, parent) else { continue };
if !tcx.consider_optimizing(|| format!("EarlyOtherwiseBranch {opt_data:?}")) {
break;
}
trace!("SUCCESS: found optimization possibility to apply: {opt_data:?}");
should_cleanup = true;

View file

@ -210,12 +210,6 @@ impl<'tcx> Inliner<'tcx> {
let callee_body = try_instance_mir(self.tcx, callsite.callee.def)?;
self.check_mir_body(callsite, callee_body, callee_attrs, cross_crate_inlinable)?;
if !self.tcx.consider_optimizing(|| {
format!("Inline {:?} into {:?}", callsite.callee, caller_body.source)
}) {
return Err("optimization fuel exhausted");
}
let Ok(callee_body) = callsite.callee.try_instantiate_mir_and_normalize_erasing_regions(
self.tcx,
self.typing_env,

View file

@ -7,8 +7,8 @@ use rustc_middle::bug;
use rustc_middle::mir::*;
use rustc_middle::ty::layout::ValidityRequirement;
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, layout};
use rustc_span::sym;
use rustc_span::symbol::Symbol;
use rustc_span::{DUMMY_SP, sym};
use crate::simplify::simplify_duplicate_switch_targets;
use crate::take_array;
@ -43,12 +43,12 @@ impl<'tcx> crate::MirPass<'tcx> for InstSimplify {
match statement.kind {
StatementKind::Assign(box (_place, ref mut rvalue)) => {
if !preserve_ub_checks {
ctx.simplify_ub_check(&statement.source_info, rvalue);
ctx.simplify_ub_check(rvalue);
}
ctx.simplify_bool_cmp(&statement.source_info, rvalue);
ctx.simplify_ref_deref(&statement.source_info, rvalue);
ctx.simplify_len(&statement.source_info, rvalue);
ctx.simplify_ptr_aggregate(&statement.source_info, rvalue);
ctx.simplify_bool_cmp(rvalue);
ctx.simplify_ref_deref(rvalue);
ctx.simplify_len(rvalue);
ctx.simplify_ptr_aggregate(rvalue);
ctx.simplify_cast(rvalue);
}
_ => {}
@ -70,23 +70,8 @@ struct InstSimplifyContext<'a, 'tcx> {
}
impl<'tcx> InstSimplifyContext<'_, 'tcx> {
fn should_simplify(&self, source_info: &SourceInfo, rvalue: &Rvalue<'tcx>) -> bool {
self.should_simplify_custom(source_info, "Rvalue", rvalue)
}
fn should_simplify_custom(
&self,
source_info: &SourceInfo,
label: &str,
value: impl std::fmt::Debug,
) -> bool {
self.tcx.consider_optimizing(|| {
format!("InstSimplify - {label}: {value:?} SourceInfo: {source_info:?}")
})
}
/// Transform boolean comparisons into logical operations.
fn simplify_bool_cmp(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) {
fn simplify_bool_cmp(&self, rvalue: &mut Rvalue<'tcx>) {
match rvalue {
Rvalue::BinaryOp(op @ (BinOp::Eq | BinOp::Ne), box (a, b)) => {
let new = match (op, self.try_eval_bool(a), self.try_eval_bool(b)) {
@ -117,9 +102,7 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> {
_ => None,
};
if let Some(new) = new
&& self.should_simplify(source_info, rvalue)
{
if let Some(new) = new {
*rvalue = new;
}
}
@ -134,17 +117,13 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> {
}
/// Transform `&(*a)` ==> `a`.
fn simplify_ref_deref(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) {
fn simplify_ref_deref(&self, rvalue: &mut Rvalue<'tcx>) {
if let Rvalue::Ref(_, _, place) | Rvalue::RawPtr(_, place) = rvalue {
if let Some((base, ProjectionElem::Deref)) = place.as_ref().last_projection() {
if rvalue.ty(self.local_decls, self.tcx) != base.ty(self.local_decls, self.tcx).ty {
return;
}
if !self.should_simplify(source_info, rvalue) {
return;
}
*rvalue = Rvalue::Use(Operand::Copy(Place {
local: base.local,
projection: self.tcx.mk_place_elems(base.projection),
@ -154,36 +133,24 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> {
}
/// Transform `Len([_; N])` ==> `N`.
fn simplify_len(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) {
fn simplify_len(&self, rvalue: &mut Rvalue<'tcx>) {
if let Rvalue::Len(ref place) = *rvalue {
let place_ty = place.ty(self.local_decls, self.tcx).ty;
if let ty::Array(_, len) = *place_ty.kind() {
if !self.should_simplify(source_info, rvalue) {
return;
}
let const_ = Const::from_ty_const(len, self.tcx.types.usize, self.tcx);
let constant = ConstOperand { span: source_info.span, const_, user_ty: None };
let constant = ConstOperand { span: DUMMY_SP, const_, user_ty: None };
*rvalue = Rvalue::Use(Operand::Constant(Box::new(constant)));
}
}
}
/// Transform `Aggregate(RawPtr, [p, ()])` ==> `Cast(PtrToPtr, p)`.
fn simplify_ptr_aggregate(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) {
fn simplify_ptr_aggregate(&self, rvalue: &mut Rvalue<'tcx>) {
if let Rvalue::Aggregate(box AggregateKind::RawPtr(pointee_ty, mutability), fields) = rvalue
{
let meta_ty = fields.raw[1].ty(self.local_decls, self.tcx);
if meta_ty.is_unit() {
// The mutable borrows we're holding prevent printing `rvalue` here
if !self.should_simplify_custom(
source_info,
"Aggregate::RawPtr",
(&pointee_ty, *mutability, &fields),
) {
return;
}
let mut fields = std::mem::take(fields);
let _meta = fields.pop().unwrap();
let data = fields.pop().unwrap();
@ -193,10 +160,10 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> {
}
}
fn simplify_ub_check(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) {
fn simplify_ub_check(&self, rvalue: &mut Rvalue<'tcx>) {
if let Rvalue::NullaryOp(NullOp::UbChecks, _) = *rvalue {
let const_ = Const::from_bool(self.tcx, self.tcx.sess.ub_checks());
let constant = ConstOperand { span: source_info.span, const_, user_ty: None };
let constant = ConstOperand { span: DUMMY_SP, const_, user_ty: None };
*rvalue = Rvalue::Use(Operand::Constant(Box::new(constant)));
}
}
@ -284,16 +251,6 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> {
return;
}
if !self.tcx.consider_optimizing(|| {
format!(
"InstSimplify - Call: {:?} SourceInfo: {:?}",
(fn_def_id, fn_args),
terminator.source_info
)
}) {
return;
}
let Ok([arg]) = take_array(args) else { return };
let Some(arg_place) = arg.node.place() else { return };

View file

@ -18,16 +18,11 @@ impl<'tcx> crate::MirPass<'tcx> for MatchBranchSimplification {
}
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let def_id = body.source.def_id();
let typing_env = body.typing_env(tcx);
let mut should_cleanup = false;
for i in 0..body.basic_blocks.len() {
let bbs = &*body.basic_blocks;
let bb_idx = BasicBlock::from_usize(i);
if !tcx.consider_optimizing(|| format!("MatchBranchSimplification {def_id:?} ")) {
continue;
}
match bbs[bb_idx].terminator().kind {
TerminatorKind::SwitchInt {
discr: ref _discr @ (Operand::Copy(_) | Operand::Move(_)),

View file

@ -14,10 +14,9 @@ impl<'tcx> crate::MirPass<'tcx> for MultipleReturnTerminators {
sess.mir_opt_level() >= 4
}
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
fn run_pass(&self, _: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
// find basic blocks with no statement and a return terminator
let mut bbs_simple_returns = BitSet::new_empty(body.basic_blocks.len());
let def_id = body.source.def_id();
let bbs = body.basic_blocks_mut();
for idx in bbs.indices() {
if bbs[idx].statements.is_empty()
@ -28,10 +27,6 @@ impl<'tcx> crate::MirPass<'tcx> for MultipleReturnTerminators {
}
for bb in bbs {
if !tcx.consider_optimizing(|| format!("MultipleReturnTerminators {def_id:?} ")) {
break;
}
if let TerminatorKind::Goto { target } = bb.terminator().kind {
if bbs_simple_returns.contains(target) {
bb.terminator_mut().kind = TerminatorKind::Return;

View file

@ -45,10 +45,6 @@ impl<'tcx> crate::MirPass<'tcx> for RenameReturnPlace {
return;
};
if !tcx.consider_optimizing(|| format!("RenameReturnPlace {def_id:?}")) {
return;
}
debug!(
"`{:?}` was eligible for NRVO, making {:?} the return place",
def_id, returned_local

View file

@ -26,11 +26,6 @@ impl<'tcx> crate::MirPass<'tcx> for RemoveUnneededDrops {
if ty.ty.needs_drop(tcx, typing_env) {
continue;
}
if !tcx.consider_optimizing(|| {
format!("RemoveUnneededDrops {:?}", body.source.def_id())
}) {
continue;
}
debug!("SUCCESS: replacing `drop` with goto({:?})", target);
terminator.kind = TerminatorKind::Goto { target };
should_simplify = true;

View file

@ -17,10 +17,6 @@ impl<'tcx> crate::MirPass<'tcx> for RemoveZsts {
return;
}
if !tcx.consider_optimizing(|| format!("RemoveZsts - {:?}", body.source.def_id())) {
return;
}
let typing_env = body.typing_env(tcx);
let local_decls = &body.local_decls;
let mut replacer = Replacer { tcx, typing_env, local_decls };
@ -94,16 +90,12 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
}
}
fn visit_operand(&mut self, operand: &mut Operand<'tcx>, loc: Location) {
fn visit_operand(&mut self, operand: &mut Operand<'tcx>, _: Location) {
if let Operand::Constant(_) = operand {
return;
}
let op_ty = operand.ty(self.local_decls, self.tcx);
if self.known_to_be_zst(op_ty)
&& self.tcx.consider_optimizing(|| {
format!("RemoveZsts - Operand: {operand:?} Location: {loc:?}")
})
{
if self.known_to_be_zst(op_ty) {
*operand = Operand::Constant(Box::new(self.make_zst(op_ty)))
}
}

View file

@ -43,12 +43,6 @@ impl crate::MirPass<'_> for UnreachablePropagation {
}
}
if !tcx
.consider_optimizing(|| format!("UnreachablePropagation {:?} ", body.source.def_id()))
{
return;
}
patch.apply(body);
// We do want do keep some unreachable blocks, but make them empty.