Skip to content

Commit

Permalink
Remove -Zfuel.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Nov 26, 2024
1 parent f2abf82 commit 7fa021a
Show file tree
Hide file tree
Showing 26 changed files with 19 additions and 281 deletions.
4 changes: 0 additions & 4 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,6 @@ fn run_compiler(
linker.link(sess, codegen_backend)?
}

if let Some(fuel) = sess.opts.unstable_opts.print_fuel.as_deref() {
eprintln!("Fuel used by {}: {}", fuel, sess.print_fuel.load(Ordering::SeqCst));
}

Ok(())
})
}
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,6 @@ fn test_unstable_options_tracking_hash() {
tracked!(flatten_format_args, false);
tracked!(fmt_debug, FmtDebug::Shallow);
tracked!(force_unstable_if_unmarked, true);
tracked!(fuel, Some(("abc".to_string(), 99)));
tracked!(function_return, FunctionReturn::ThunkExtern);
tracked!(function_sections, Some(false));
tracked!(human_readable_cgu_names, true);
Expand Down Expand Up @@ -830,7 +829,6 @@ fn test_unstable_options_tracking_hash() {
tracked!(plt, Some(true));
tracked!(polonius, Polonius::Legacy);
tracked!(precise_enum_drop_elaboration, false);
tracked!(print_fuel, Some("abc".to_string()));
tracked!(profile_sample_use, Some(PathBuf::from("abc")));
tracked!(profiler_runtime, "abc".to_string());
tracked!(regparm, Some(3));
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1566,10 +1566,6 @@ impl<'tcx> TyCtxt<'tcx> {
}
}

pub fn consider_optimizing<T: Fn() -> String>(self, msg: T) -> bool {
self.sess.consider_optimizing(|| self.crate_name(LOCAL_CRATE), msg)
}

/// Obtain all lang items of this crate and all dependencies (recursively)
pub fn lang_items(self) -> &'tcx rustc_hir::lang_items::LanguageItems {
self.get_lang_items(())
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1558,10 +1558,7 @@ impl<'tcx> TyCtxt<'tcx> {
let is_box = self.is_lang_item(did.to_def_id(), LangItem::OwnedBox);

// This is here instead of layout because the choice must make it into metadata.
if is_box
|| !self
.consider_optimizing(|| format!("Reorder fields of {:?}", self.def_path_str(did)))
{
if is_box {
flags.insert(ReprFlags::IS_LINEAR);
}

Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_mir_transform/src/dest_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_mir_transform/src/early_otherwise_branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
71 changes: 14 additions & 57 deletions compiler/rustc_mir_transform/src/instsimplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
_ => {}
Expand All @@ -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)) {
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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),
Expand All @@ -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();
Expand All @@ -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)));
}
}
Expand Down Expand Up @@ -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 };

Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_mir_transform/src/match_branches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_mir_transform/src/nrvo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_mir_transform/src/remove_unneeded_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 2 additions & 10 deletions compiler/rustc_mir_transform/src/remove_zsts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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)))
}
}
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_mir_transform/src/unreachable_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_session/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ session_not_supported = not supported
session_octal_float_literal_not_supported = octal float literal is not supported
session_optimization_fuel_exhausted = optimization-fuel-exhausted: {$msg}
session_profile_sample_use_file_does_not_exist = file `{$path}` passed to `-C profile-sample-use` does not exist
session_profile_use_file_does_not_exist = file `{$path}` passed to `-C profile-use` does not exist
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2356,14 +2356,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
early_dcx.early_warn(format!("number of threads was capped at {}", parse::MAX_THREADS_CAP));
}

let fuel = unstable_opts.fuel.is_some() || unstable_opts.print_fuel.is_some();
if fuel && unstable_opts.threads > 1 {
early_dcx.early_fatal("optimization fuel is incompatible with multiple threads");
}
if fuel && cg.incremental.is_some() {
early_dcx.early_fatal("optimization fuel is incompatible with incremental compilation");
}

let incremental = cg.incremental.as_ref().map(PathBuf::from);

let assert_incr_state = parse_assert_incr_state(early_dcx, &unstable_opts.assert_incr_state);
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_session/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,6 @@ pub fn report_lit_error(
}
}

#[derive(Diagnostic)]
#[diag(session_optimization_fuel_exhausted)]
pub(crate) struct OptimisationFuelExhausted {
pub(crate) msg: String,
}

#[derive(Diagnostic)]
#[diag(session_incompatible_linker_flavor)]
#[note]
Expand Down
Loading

0 comments on commit 7fa021a

Please sign in to comment.