Skip to content

Commit

Permalink
Auto merge of rust-lang#119363 - matthiaskrgr:rollup-o0ncmsn, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 3 pull requests

Successful merges:

 - rust-lang#119336 (coverage: Unexpand spans with `find_ancestor_inside_same_ctxt`)
 - rust-lang#119349 (refactor(liveness): move walk_expr outside of every match branch)
 - rust-lang#119359 (Simplify Parser::ident_or_error)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Dec 27, 2023
2 parents 89e2160 + aeed023 commit 2bded34
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 42 deletions.
21 changes: 5 additions & 16 deletions compiler/rustc_mir_transform/src/coverage/mod.rs
Expand Up @@ -23,7 +23,7 @@ use rustc_middle::mir::{
use rustc_middle::ty::TyCtxt;
use rustc_span::def_id::LocalDefId;
use rustc_span::source_map::SourceMap;
use rustc_span::{ExpnKind, Span, Symbol};
use rustc_span::{Span, Symbol};

/// Inserts `StatementKind::Coverage` statements that either instrument the binary with injected
/// counters, via intrinsic `llvm.instrprof.increment`, and/or inject metadata used during codegen
Expand Down Expand Up @@ -346,21 +346,10 @@ fn get_body_span<'tcx>(
let mut body_span = hir_body.value.span;

if tcx.is_closure(def_id.to_def_id()) {
// If the MIR function is a closure, and if the closure body span
// starts from a macro, but it's content is not in that macro, try
// to find a non-macro callsite, and instrument the spans there
// instead.
loop {
let expn_data = body_span.ctxt().outer_expn_data();
if expn_data.is_root() {
break;
}
if let ExpnKind::Macro { .. } = expn_data.kind {
body_span = expn_data.call_site;
} else {
break;
}
}
// If the current function is a closure, and its "body" span was created
// by macro expansion or compiler desugaring, try to walk backwards to
// the pre-expansion call site or body.
body_span = body_span.source_callsite();
}

body_span
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs
Expand Up @@ -204,10 +204,5 @@ fn filtered_terminator_span(terminator: &Terminator<'_>) -> Option<Span> {
/// etc.).
#[inline]
fn unexpand_into_body_span(span: Span, body_span: Span) -> Option<Span> {
use rustc_span::source_map::original_sp;

// FIXME(#118525): Consider switching from `original_sp` to `Span::find_ancestor_inside`,
// which is similar but gives slightly different results in some edge cases.
let original_span = original_sp(span, body_span).with_ctxt(body_span.ctxt());
body_span.contains(original_span).then_some(original_span)
span.find_ancestor_inside_same_ctxt(body_span)
}
16 changes: 4 additions & 12 deletions compiler/rustc_parse/src/parser/mod.rs
Expand Up @@ -504,18 +504,10 @@ impl<'a> Parser<'a> {
}

fn ident_or_err(&mut self, recover: bool) -> PResult<'a, (Ident, /* is_raw */ bool)> {
let result = self.token.ident().ok_or_else(|| self.expected_ident_found(recover));

let (ident, is_raw) = match result {
Ok(ident) => ident,
Err(err) => match err {
// we recovered!
Ok(ident) => ident,
Err(err) => return Err(err),
},
};

Ok((ident, is_raw))
match self.token.ident() {
Some(ident) => Ok(ident),
None => self.expected_ident_found(recover),
}
}

/// Checks if the next token is `tok`, and returns `true` if so.
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_passes/src/liveness.rs
Expand Up @@ -405,7 +405,6 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
if let Res::Local(_var_hir_id) = path.res {
self.add_live_node_for_node(expr.hir_id, ExprNode(expr.span, expr.hir_id));
}
intravisit::walk_expr(self, expr);
}
hir::ExprKind::Closure(closure) => {
// Interesting control flow (for loops can contain labeled
Expand All @@ -425,12 +424,10 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
}));
}
self.set_captures(expr.hir_id, call_caps);
intravisit::walk_expr(self, expr);
}

hir::ExprKind::Let(let_expr) => {
self.add_from_pat(let_expr.pat);
intravisit::walk_expr(self, expr);
}

// live nodes required for interesting control flow:
Expand All @@ -439,11 +436,9 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
| hir::ExprKind::Loop(..)
| hir::ExprKind::Yield(..) => {
self.add_live_node_for_node(expr.hir_id, ExprNode(expr.span, expr.hir_id));
intravisit::walk_expr(self, expr);
}
hir::ExprKind::Binary(op, ..) if op.node.is_lazy() => {
self.add_live_node_for_node(expr.hir_id, ExprNode(expr.span, expr.hir_id));
intravisit::walk_expr(self, expr);
}

// otherwise, live nodes are not required:
Expand Down Expand Up @@ -474,10 +469,9 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
| hir::ExprKind::Type(..)
| hir::ExprKind::Err(_)
| hir::ExprKind::Path(hir::QPath::TypeRelative(..))
| hir::ExprKind::Path(hir::QPath::LangItem(..)) => {
intravisit::walk_expr(self, expr);
}
| hir::ExprKind::Path(hir::QPath::LangItem(..)) => {}
}
intravisit::walk_expr(self, expr);
}
}

Expand Down

0 comments on commit 2bded34

Please sign in to comment.