7 - Make more use of let_chains

Continuation of #94376.

cc #53667
This commit is contained in:
Caio 2022-03-01 07:43:12 -03:00
parent 6e5a6ffb14
commit 7aa5ea9a4a
9 changed files with 100 additions and 112 deletions

View file

@ -55,12 +55,10 @@ fn find_optimization_oportunities<'tcx>(body: &Body<'tcx>) -> Vec<(Local, Consta
let mut locals_to_debuginfo = BitSet::new_empty(body.local_decls.len()); let mut locals_to_debuginfo = BitSet::new_empty(body.local_decls.len());
for debuginfo in &body.var_debug_info { for debuginfo in &body.var_debug_info {
if let VarDebugInfoContents::Place(p) = debuginfo.value { if let VarDebugInfoContents::Place(p) = debuginfo.value && let Some(l) = p.as_local() {
if let Some(l) = p.as_local() {
locals_to_debuginfo.insert(l); locals_to_debuginfo.insert(l);
} }
} }
}
let mut eligable_locals = Vec::new(); let mut eligable_locals = Vec::new();
for (local, mutating_uses) in visitor.local_mutating_uses.drain_enumerated(..) { for (local, mutating_uses) in visitor.local_mutating_uses.drain_enumerated(..) {

View file

@ -633,8 +633,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
fn propagate_operand(&mut self, operand: &mut Operand<'tcx>) { fn propagate_operand(&mut self, operand: &mut Operand<'tcx>) {
match *operand { match *operand {
Operand::Copy(l) | Operand::Move(l) => { Operand::Copy(l) | Operand::Move(l) => {
if let Some(value) = self.get_const(l) { if let Some(value) = self.get_const(l) && self.should_const_prop(&value) {
if self.should_const_prop(&value) {
// FIXME(felix91gr): this code only handles `Scalar` cases. // FIXME(felix91gr): this code only handles `Scalar` cases.
// For now, we're not handling `ScalarPair` cases because // For now, we're not handling `ScalarPair` cases because
// doing so here would require a lot of code duplication. // doing so here would require a lot of code duplication.
@ -653,7 +652,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
} }
} }
} }
}
Operand::Constant(_) => (), Operand::Constant(_) => (),
} }
} }
@ -1086,8 +1084,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
// This will return None if the above `const_prop` invocation only "wrote" a // This will return None if the above `const_prop` invocation only "wrote" a
// type whose creation requires no write. E.g. a generator whose initial state // 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). // consists solely of uninitialized memory (so it doesn't capture any locals).
if let Some(ref value) = self.get_const(place) { if let Some(ref value) = self.get_const(place) && self.should_const_prop(value) {
if self.should_const_prop(value) {
trace!("replacing {:?} with {:?}", rval, value); trace!("replacing {:?} with {:?}", rval, value);
self.replace_with_const(rval, value, source_info); self.replace_with_const(rval, value, source_info);
if can_const_prop == ConstPropMode::FullConstProp if can_const_prop == ConstPropMode::FullConstProp
@ -1096,7 +1093,6 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
trace!("propagated into {:?}", place); trace!("propagated into {:?}", place);
} }
} }
}
match can_const_prop { match can_const_prop {
ConstPropMode::OnlyInsideOwnBlock => { ConstPropMode::OnlyInsideOwnBlock => {
trace!( trace!(

View file

@ -357,15 +357,13 @@ impl DebugCounters {
if let Some(counters) = &self.some_counters { if let Some(counters) = &self.some_counters {
if let Some(DebugCounter { counter_kind, some_block_label }) = counters.get(&operand) { if let Some(DebugCounter { counter_kind, some_block_label }) = counters.get(&operand) {
if let CoverageKind::Expression { .. } = counter_kind { if let CoverageKind::Expression { .. } = counter_kind {
if let Some(block_label) = some_block_label { if let Some(label) = some_block_label && debug_options().counter_format.block {
if debug_options().counter_format.block {
return format!( return format!(
"{}:({})", "{}:({})",
block_label, label,
self.format_counter_kind(counter_kind) self.format_counter_kind(counter_kind)
); );
} }
}
return format!("({})", self.format_counter_kind(counter_kind)); return format!("({})", self.format_counter_kind(counter_kind));
} }
return self.format_counter_kind(counter_kind); return self.format_counter_kind(counter_kind);

View file

@ -191,17 +191,14 @@ impl CoverageSpan {
/// If the span is part of a macro, and the macro is visible (expands directly to the given /// If the span is part of a macro, and the macro is visible (expands directly to the given
/// body_span), returns the macro name symbol. /// body_span), returns the macro name symbol.
pub fn visible_macro(&self, body_span: Span) -> Option<Symbol> { pub fn visible_macro(&self, body_span: Span) -> Option<Symbol> {
if let Some(current_macro) = self.current_macro() { if let Some(current_macro) = self.current_macro() && self
if self
.expn_span .expn_span
.parent_callsite() .parent_callsite()
.unwrap_or_else(|| bug!("macro must have a parent")) .unwrap_or_else(|| bug!("macro must have a parent"))
.ctxt() .ctxt() == body_span.ctxt()
== body_span.ctxt()
{ {
return Some(current_macro); return Some(current_macro);
} }
}
None None
} }
@ -584,8 +581,7 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
/// In either case, no more spans will match the span of `pending_dups`, so /// In either case, no more spans will match the span of `pending_dups`, so
/// add the `pending_dups` if they don't overlap `curr`, and clear the list. /// add the `pending_dups` if they don't overlap `curr`, and clear the list.
fn check_pending_dups(&mut self) { fn check_pending_dups(&mut self) {
if let Some(dup) = self.pending_dups.last() { if let Some(dup) = self.pending_dups.last() && dup.span != self.prev().span {
if dup.span != self.prev().span {
debug!( debug!(
" SAME spans, but pending_dups are NOT THE SAME, so BCBs matched on \ " SAME spans, but pending_dups are NOT THE SAME, so BCBs matched on \
previous iteration, or prev started a new disjoint span" previous iteration, or prev started a new disjoint span"
@ -601,7 +597,6 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
} }
} }
} }
}
/// Advance `prev` to `curr` (if any), and `curr` to the next `CoverageSpan` in sorted order. /// Advance `prev` to `curr` (if any), and `curr` to the next `CoverageSpan` in sorted order.
fn next_coverage_span(&mut self) -> bool { fn next_coverage_span(&mut self) -> bool {

View file

@ -549,8 +549,10 @@ impl<'a> Conflicts<'a> {
target: _, target: _,
unwind: _, unwind: _,
} => { } => {
if let Some(place) = value.place() { if let Some(place) = value.place()
if !place.is_indirect() && !dropped_place.is_indirect() { && !place.is_indirect()
&& !dropped_place.is_indirect()
{
self.record_local_conflict( self.record_local_conflict(
place.local, place.local,
dropped_place.local, dropped_place.local,
@ -558,7 +560,6 @@ impl<'a> Conflicts<'a> {
); );
} }
} }
}
TerminatorKind::Yield { value, resume: _, resume_arg, drop: _ } => { TerminatorKind::Yield { value, resume: _, resume_arg, drop: _ } => {
if let Some(place) = value.place() { if let Some(place) = value.place() {
if !place.is_indirect() && !resume_arg.is_indirect() { if !place.is_indirect() && !resume_arg.is_indirect() {
@ -614,8 +615,10 @@ impl<'a> Conflicts<'a> {
for op in operands { for op in operands {
match op { match op {
InlineAsmOperand::In { reg: _, value } => { InlineAsmOperand::In { reg: _, value } => {
if let Some(p) = value.place() { if let Some(p) = value.place()
if !p.is_indirect() && !dest_place.is_indirect() { && !p.is_indirect()
&& !dest_place.is_indirect()
{
self.record_local_conflict( self.record_local_conflict(
p.local, p.local,
dest_place.local, dest_place.local,
@ -623,7 +626,6 @@ impl<'a> Conflicts<'a> {
); );
} }
} }
}
InlineAsmOperand::Out { InlineAsmOperand::Out {
reg: _, reg: _,
late: _, late: _,
@ -643,18 +645,21 @@ impl<'a> Conflicts<'a> {
in_value, in_value,
out_place, out_place,
} => { } => {
if let Some(place) = in_value.place() { if let Some(place) = in_value.place()
if !place.is_indirect() && !dest_place.is_indirect() { && !place.is_indirect()
&& !dest_place.is_indirect()
{
self.record_local_conflict( self.record_local_conflict(
place.local, place.local,
dest_place.local, dest_place.local,
"asm! operand overlap", "asm! operand overlap",
); );
} }
}
if let Some(place) = out_place { if let Some(place) = out_place
if !place.is_indirect() && !dest_place.is_indirect() { && !place.is_indirect()
&& !dest_place.is_indirect()
{
self.record_local_conflict( self.record_local_conflict(
place.local, place.local,
dest_place.local, dest_place.local,
@ -662,7 +667,6 @@ impl<'a> Conflicts<'a> {
); );
} }
} }
}
InlineAsmOperand::Out { reg: _, late: _, place: None } InlineAsmOperand::Out { reg: _, late: _, place: None }
| InlineAsmOperand::Const { value: _ } | InlineAsmOperand::Const { value: _ }
| InlineAsmOperand::SymFn { value: _ } | InlineAsmOperand::SymFn { value: _ }

View file

@ -724,13 +724,12 @@ impl<'tcx> Inliner<'tcx> {
caller_body: &mut Body<'tcx>, caller_body: &mut Body<'tcx>,
) -> Local { ) -> Local {
// Reuse the operand if it is a moved temporary. // Reuse the operand if it is a moved temporary.
if let Operand::Move(place) = &arg { if let Operand::Move(place) = &arg
if let Some(local) = place.as_local() { && let Some(local) = place.as_local()
if caller_body.local_kind(local) == LocalKind::Temp { && caller_body.local_kind(local) == LocalKind::Temp
{
return local; return local;
} }
}
}
// Otherwise, create a temporary for the argument. // Otherwise, create a temporary for the argument.
trace!("creating temp for argument {:?}", arg); trace!("creating temp for argument {:?}", arg);

View file

@ -77,12 +77,10 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
_ => None, _ => None,
}; };
if let Some(new) = new { if let Some(new) = new && self.should_combine(source_info, rvalue) {
if self.should_combine(source_info, rvalue) {
*rvalue = new; *rvalue = new;
} }
} }
}
_ => {} _ => {}
} }

View file

@ -1,16 +1,17 @@
#![allow(rustc::potential_query_instability)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]
#![feature(let_chains)]
#![feature(let_else)] #![feature(let_else)]
#![feature(map_try_insert)] #![feature(map_try_insert)]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(option_get_or_insert_default)]
#![feature(once_cell)]
#![feature(never_type)] #![feature(never_type)]
#![feature(once_cell)]
#![feature(option_get_or_insert_default)]
#![feature(trusted_step)] #![feature(trusted_step)]
#![feature(try_blocks)] #![feature(try_blocks)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![allow(rustc::potential_query_instability)]
#[macro_use] #[macro_use]
extern crate tracing; extern crate tracing;

View file

@ -14,10 +14,9 @@ impl<'a, 'tcx> RequiredConstsVisitor<'a, 'tcx> {
impl<'tcx> Visitor<'tcx> for RequiredConstsVisitor<'_, 'tcx> { impl<'tcx> Visitor<'tcx> for RequiredConstsVisitor<'_, 'tcx> {
fn visit_constant(&mut self, constant: &Constant<'tcx>, _: Location) { fn visit_constant(&mut self, constant: &Constant<'tcx>, _: Location) {
if let Some(ct) = constant.literal.const_for_ty() { let literal = constant.literal;
if let ConstKind::Unevaluated(_) = ct.val() { if let Some(ct) = literal.const_for_ty() && let ConstKind::Unevaluated(_) = ct.val() {
self.required_consts.push(*constant); self.required_consts.push(*constant);
} }
} }
}
} }