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

Rollup of 8 pull requests #133516

Merged
merged 23 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b910e97
CI: increase timeout from 4h to 6h
Kobzol Nov 4, 2024
9148660
add convoluted test for issue 132920
lqd Nov 21, 2024
764e3e2
Revert "Remove less relevant info from diagnostic"
lqd Nov 21, 2024
d0a45cf
Fix `Result` and `Option` not getting a jump to def link generated
GuillaumeGomez Nov 25, 2024
c839925
Add regression test for prelude types
GuillaumeGomez Nov 25, 2024
bd44b63
Constify Drop and Destruct
compiler-errors Nov 24, 2024
58936c1
fix gce typing_mode mismatch
lcnr Nov 25, 2024
7178942
Improve `MaybeStorageLive::initialize_start_block`.
nnethercote Nov 22, 2024
3d12160
Move `always_storage_live_locals`.
nnethercote Nov 22, 2024
e3ef2ff
Streamline a `BitSet` creation.
nnethercote Nov 24, 2024
a602cb6
Make some modules non-`pub`.
nnethercote Nov 25, 2024
7fa021a
Remove -Zfuel.
cjgillot May 1, 2023
d013c18
Pacify tidy.
cjgillot Aug 28, 2023
982cde9
Remove extra tests.
cjgillot Jul 31, 2024
787b795
Only ignore windows-gnu in avr-jmp-offset
ChrisDenton Nov 26, 2024
145df3b
Rollup merge of #115293 - cjgillot:no-fuel, r=wesleywiser,DianQK
compiler-errors Nov 27, 2024
24e7196
Rollup merge of #132605 - Kobzol:ci-increase-timeout, r=Mark-Simulacrum
compiler-errors Nov 27, 2024
f101562
Rollup merge of #133304 - lqd:issue-132920, r=estebank
compiler-errors Nov 27, 2024
8a2f57f
Rollup merge of #133402 - compiler-errors:drop-and-destruct, r=lcnr
compiler-errors Nov 27, 2024
32dc393
Rollup merge of #133458 - GuillaumeGomez:fix-prelude-tys-links, r=not…
compiler-errors Nov 27, 2024
82622c6
Rollup merge of #133471 - lcnr:uwu-gamer, r=BoxyUwU
compiler-errors Nov 27, 2024
219b2a0
Rollup merge of #133475 - nnethercote:MaybeStorage-improvements, r=lcnr
compiler-errors Nov 27, 2024
702996c
Rollup merge of #133513 - ChrisDenton:windows-msvc, r=jieyouxu
compiler-errors Nov 27, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
defaults:
run:
shell: ${{ contains(matrix.os, 'windows') && 'msys2 {0}' || 'bash' }}
timeout-minutes: 240
timeout-minutes: 360
env:
CI_JOB_NAME: ${{ matrix.image }}
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_const_eval/src/check_consts/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ use rustc_middle::span_bug;
use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
use rustc_mir_dataflow::Analysis;
use rustc_mir_dataflow::impls::MaybeStorageLive;
use rustc_mir_dataflow::storage::always_storage_live_locals;
use rustc_mir_dataflow::impls::{MaybeStorageLive, always_storage_live_locals};
use rustc_span::{Span, Symbol, sym};
use rustc_trait_selection::traits::{
Obligation, ObligationCause, ObligationCauseCode, ObligationCtxt,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_index::IndexVec;
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::{bug, mir};
use rustc_mir_dataflow::storage::always_storage_live_locals;
use rustc_mir_dataflow::impls::always_storage_live_locals;
use rustc_span::Span;
use tracing::{info_span, instrument, trace};

Expand Down
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
4 changes: 3 additions & 1 deletion compiler/rustc_mir_dataflow/src/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ pub use self::initialized::{
pub use self::liveness::{
MaybeLiveLocals, MaybeTransitiveLiveLocals, TransferFunction as LivenessTransferFunction,
};
pub use self::storage_liveness::{MaybeRequiresStorage, MaybeStorageDead, MaybeStorageLive};
pub use self::storage_liveness::{
MaybeRequiresStorage, MaybeStorageDead, MaybeStorageLive, always_storage_live_locals,
};
22 changes: 18 additions & 4 deletions compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ use rustc_middle::mir::*;
use super::MaybeBorrowedLocals;
use crate::{Analysis, GenKill, ResultsCursor};

/// The set of locals in a MIR body that do not have `StorageLive`/`StorageDead` annotations.
///
/// These locals have fixed storage for the duration of the body.
pub fn always_storage_live_locals(body: &Body<'_>) -> BitSet<Local> {
let mut always_live_locals = BitSet::new_filled(body.local_decls.len());

for block in &*body.basic_blocks {
for statement in &block.statements {
if let StatementKind::StorageLive(l) | StatementKind::StorageDead(l) = statement.kind {
always_live_locals.remove(l);
}
}
}

always_live_locals
}

pub struct MaybeStorageLive<'a> {
always_live_locals: Cow<'a, BitSet<Local>>,
}
Expand All @@ -28,10 +45,7 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeStorageLive<'a> {
}

fn initialize_start_block(&self, body: &Body<'tcx>, on_entry: &mut Self::Domain) {
assert_eq!(body.local_decls.len(), self.always_live_locals.domain_size());
for local in self.always_live_locals.iter() {
on_entry.insert(local);
}
on_entry.union(&*self.always_live_locals);

for arg in body.args_iter() {
on_entry.insert(arg);
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_mir_dataflow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ pub use self::framework::{
use self::move_paths::MoveData;

pub mod debuginfo;
pub mod drop_flag_effects;
mod drop_flag_effects;
pub mod elaborate_drops;
mod errors;
mod framework;
pub mod impls;
pub mod move_paths;
pub mod points;
pub mod rustc_peek;
pub mod storage;
pub mod un_derefer;
mod un_derefer;
pub mod value_analysis;

rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
Expand Down
20 changes: 0 additions & 20 deletions compiler/rustc_mir_dataflow/src/storage.rs

This file was deleted.

5 changes: 2 additions & 3 deletions compiler/rustc_mir_transform/src/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ use rustc_middle::ty::{
use rustc_middle::{bug, span_bug};
use rustc_mir_dataflow::impls::{
MaybeBorrowedLocals, MaybeLiveLocals, MaybeRequiresStorage, MaybeStorageLive,
always_storage_live_locals,
};
use rustc_mir_dataflow::storage::always_storage_live_locals;
use rustc_mir_dataflow::{Analysis, Results, ResultsVisitor};
use rustc_span::Span;
use rustc_span::def_id::{DefId, LocalDefId};
Expand Down Expand Up @@ -696,8 +696,7 @@ fn locals_live_across_suspend_points<'tcx>(
let loc = Location { block, statement_index: data.statements.len() };

liveness.seek_to_block_end(block);
let mut live_locals: BitSet<_> = BitSet::new_empty(body.local_decls.len());
live_locals.union(liveness.get());
let mut live_locals = liveness.get().clone();

if !movable {
// The `liveness` variable contains the liveness of MIR locals ignoring borrows.
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
3 changes: 1 addition & 2 deletions compiler/rustc_mir_transform/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use rustc_index::bit_set::BitSet;
use rustc_middle::mir::visit::{PlaceContext, Visitor};
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;
use rustc_mir_dataflow::impls::{MaybeStorageDead, MaybeStorageLive};
use rustc_mir_dataflow::storage::always_storage_live_locals;
use rustc_mir_dataflow::impls::{MaybeStorageDead, MaybeStorageLive, always_storage_live_locals};
use rustc_mir_dataflow::{Analysis, ResultsCursor};

pub(super) fn lint_body<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, when: String) {
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
Loading
Loading