Skip to content
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

Remove -Zfuel. #115293

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 0 additions & 9 deletions compiler/rustc_driver_impl/src/lib.rs
Expand Up @@ -24,7 +24,6 @@ use rustc_codegen_ssa::{traits::CodegenBackend, CodegenErrors, CodegenResults};
use rustc_data_structures::profiling::{
get_resident_set_size, print_time_passes_entry, TimePassesFormat,
};
use rustc_data_structures::sync::SeqCst;
use rustc_errors::registry::{InvalidErrorCode, Registry};
use rustc_errors::{markdown, ColorConfig};
use rustc_errors::{DiagnosticMessage, ErrorGuaranteed, Handler, PResult, SubdiagnosticMessage};
Expand Down Expand Up @@ -475,14 +474,6 @@ fn run_compiler(
sess.print_perf_stats();
}

if sess.opts.unstable_opts.print_fuel.is_some() {
eprintln!(
"Fuel used by {}: {}",
sess.opts.unstable_opts.print_fuel.as_ref().unwrap(),
sess.print_fuel.load(SeqCst)
);
}

Ok(())
})
}
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_interface/src/tests.rs
Expand Up @@ -779,7 +779,6 @@ fn test_unstable_options_tracking_hash() {
tracked!(fewer_names, Some(true));
tracked!(flatten_format_args, false);
tracked!(force_unstable_if_unmarked, true);
tracked!(fuel, Some(("abc".to_string(), 99)));
tracked!(function_sections, Some(false));
tracked!(human_readable_cgu_names, true);
tracked!(incremental_ignore_spans, true);
Expand Down Expand Up @@ -816,7 +815,6 @@ fn test_unstable_options_tracking_hash() {
tracked!(plt, Some(true));
tracked!(polonius, true);
tracked!(precise_enum_drop_elaboration, false);
tracked!(print_fuel, Some("abc".to_string()));
tracked!(profile, true);
tracked!(profile_emit, Some(PathBuf::from("abc")));
tracked!(profile_sample_use, Some(PathBuf::from("abc")));
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_middle/src/ty/context.rs
Expand Up @@ -745,10 +745,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: 0 additions & 5 deletions compiler/rustc_middle/src/ty/mod.rs
Expand Up @@ -2174,11 +2174,6 @@ impl<'tcx> TyCtxt<'tcx> {
flags.insert(ReprFlags::RANDOMIZE_LAYOUT);
}

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

ReprOptions { int: size, align: max_align, pack: min_pack, flags, field_shuffle_seed }
}

Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_mir_transform/src/const_prop.rs
Expand Up @@ -530,9 +530,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
// type whose creation requires no write. E.g. a generator whose initial state
// consists solely of uninitialized memory (so it doesn't capture any locals).
let value = self.get_const(place)?;
if !self.tcx.consider_optimizing(|| format!("ConstantPropagation - {value:?}")) {
return None;
}
trace!("replacing {:?} with {:?}", place, value);

// FIXME: figure out what to do when read_immediate_raw fails
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_mir_transform/src/dest_prop.rs
Expand Up @@ -222,11 +222,6 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
else {
continue;
};
if !tcx.consider_optimizing(|| {
format!("{} round {}", tcx.def_path_str(def_id), round_count)
}) {
break;
}
merges.insert(*src, *dest);
merged_locals.insert(*src);
merged_locals.insert(*dest);
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_mir_transform/src/early_otherwise_branch.rs
Expand Up @@ -109,10 +109,6 @@ impl<'tcx> 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
Expand Up @@ -187,12 +187,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)?;

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.param_env,
Expand Down
45 changes: 11 additions & 34 deletions compiler/rustc_mir_transform/src/instsimplify.rs
Expand Up @@ -7,6 +7,7 @@ use rustc_middle::mir::*;
use rustc_middle::ty::layout::ValidityRequirement;
use rustc_middle::ty::{self, GenericArgsRef, ParamEnv, Ty, TyCtxt};
use rustc_span::symbol::Symbol;
use rustc_span::DUMMY_SP;
use rustc_target::abi::FieldIdx;

pub struct InstSimplify;
Expand All @@ -26,10 +27,10 @@ impl<'tcx> MirPass<'tcx> for InstSimplify {
for statement in block.statements.iter_mut() {
match statement.kind {
StatementKind::Assign(box (_place, ref mut 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_cast(&statement.source_info, rvalue);
ctx.simplify_bool_cmp(rvalue);
ctx.simplify_ref_deref(rvalue);
ctx.simplify_len(rvalue);
ctx.simplify_cast(rvalue);
}
_ => {}
}
Expand All @@ -55,14 +56,8 @@ struct InstSimplifyContext<'tcx, 'a> {
}

impl<'tcx> InstSimplifyContext<'tcx, '_> {
fn should_simplify(&self, source_info: &SourceInfo, rvalue: &Rvalue<'tcx>) -> bool {
self.tcx.consider_optimizing(|| {
format!("InstSimplify - Rvalue: {rvalue:?} 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 @@ -93,7 +88,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 @@ -108,17 +103,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 {
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 @@ -128,22 +119,18 @@ 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);
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)));
}
}
}

fn simplify_cast(&self, _source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) {
fn simplify_cast(&self, rvalue: &mut Rvalue<'tcx>) {
if let Rvalue::Cast(kind, operand, cast_ty) = rvalue {
let operand_ty = operand.ty(self.local_decls, self.tcx);
if operand_ty == *cast_ty {
Expand Down Expand Up @@ -223,16 +210,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 Some(arg_place) = args.pop().unwrap().place() else { return };

statements.push(Statement {
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_mir_transform/src/match_branches.rs
Expand Up @@ -51,10 +51,6 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
let bbs = body.basic_blocks.as_mut();
let mut should_cleanup = false;
'outer: for bb_idx in bbs.indices() {
if !tcx.consider_optimizing(|| format!("MatchBranchSimplification {def_id:?} ")) {
continue;
}

let (discr, val, first, second) = match bbs[bb_idx].terminator().kind {
TerminatorKind::SwitchInt {
discr: ref discr @ (Operand::Copy(_) | Operand::Move(_)),
Expand Down
Expand Up @@ -16,7 +16,6 @@ impl<'tcx> MirPass<'tcx> for MultipleReturnTerminators {
fn run_pass(&self, tcx: 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 @@ -27,10 +26,6 @@ impl<'tcx> 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
Expand Up @@ -45,10 +45,6 @@ impl<'tcx> 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
3 changes: 0 additions & 3 deletions compiler/rustc_mir_transform/src/remove_unneeded_drops.rs
Expand Up @@ -27,9 +27,6 @@ impl<'tcx> MirPass<'tcx> for RemoveUnneededDrops {
if ty.ty.needs_drop(tcx, param_env) {
continue;
}
if !tcx.consider_optimizing(|| format!("RemoveUnneededDrops {did:?} ")) {
continue;
}
debug!("SUCCESS: replacing `drop` with goto({:?})", target);
terminator.kind = TerminatorKind::Goto { target };
should_simplify = true;
Expand Down
11 changes: 2 additions & 9 deletions compiler/rustc_mir_transform/src/remove_zsts.rs
Expand Up @@ -89,16 +89,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 All @@ -125,9 +121,6 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
if let Some(place_for_ty) = place_for_ty
&& let ty = place_for_ty.ty(self.local_decls, self.tcx).ty
&& self.known_to_be_zst(ty)
&& self.tcx.consider_optimizing(|| {
format!("RemoveZsts - Place: {:?} SourceInfo: {:?}", place_for_ty, statement.source_info)
})
{
statement.make_nop();
} else {
Expand Down
12 changes: 0 additions & 12 deletions compiler/rustc_mir_transform/src/unreachable_prop.rs
Expand Up @@ -43,24 +43,12 @@ impl MirPass<'_> for UnreachablePropagation {

// We do want do keep some unreachable blocks, but make them empty.
for bb in unreachable_blocks {
if !tcx.consider_optimizing(|| {
format!("UnreachablePropagation {:?} ", body.source.def_id())
}) {
break;
}

body.basic_blocks_mut()[bb].statements.clear();
}

let replaced = !replacements.is_empty();

for (bb, terminator_kind) in replacements {
if !tcx.consider_optimizing(|| {
format!("UnreachablePropagation {:?} ", body.source.def_id())
}) {
break;
}

body.basic_blocks_mut()[bb].terminator_mut().kind = terminator_kind;
}

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_session/messages.ftl
Expand Up @@ -80,7 +80,6 @@ session_not_supported = not supported
session_nul_in_c_str = null characters in C string literals are 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.

Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_session/src/config.rs
Expand Up @@ -2130,10 +2130,6 @@ fn check_thread_count(handler: &EarlyErrorHandler, unstable_opts: &UnstableOptio
if unstable_opts.threads == 0 {
handler.early_error("value for threads must be a positive non-zero integer");
}

if unstable_opts.threads > 1 && unstable_opts.fuel.is_some() {
handler.early_error("optimization fuel is incompatible with multiple threads");
}
}

fn collect_print_requests(
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_session/src/errors.rs
Expand Up @@ -442,12 +442,6 @@ pub fn report_lit_error(sess: &ParseSess, err: LitError, lit: token::Lit, span:
}
}

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

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