Skip to content

Commit 5a6b4c8

Browse files
committed
rustup: Remove match_span_map/discr_span
The switchint source spans have been changed in rust-lang/rust#87832 to always be the match scrutinee, so we can just use pos instead of discr_span
1 parent 7524ae4 commit 5a6b4c8

File tree

4 files changed

+0
-117
lines changed

4 files changed

+0
-117
lines changed

src/analyz/mod.rs

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -520,12 +520,9 @@ impl<'tcx> ToJson<'tcx> for mir::Terminator<'tcx> {
520520
} => {
521521
let vals: Vec<String> =
522522
targets.iter().map(|(c, _)| c.to_string()).collect();
523-
let discr_span = mir.match_span_map.get(&self.source_info.span).cloned()
524-
.unwrap_or(self.source_info.span);
525523
json!({
526524
"kind": "SwitchInt",
527525
"discr": discr.to_json(mir),
528-
"discr_span": discr_span.to_json(mir),
529526
"values": vals,
530527
"targets": targets.all_targets().iter().map(|x| x.to_json(mir))
531528
.collect::<Vec<_>>(),
@@ -1081,7 +1078,6 @@ fn emit_fn<'tcx>(
10811078
used: ms.used,
10821079
state: ms.state,
10831080
tys: ms.tys,
1084-
match_span_map: ms.match_span_map,
10851081
allocs: ms.allocs,
10861082
export_style: ms.export_style,
10871083
};
@@ -1226,7 +1222,6 @@ fn analyze_inner<'tcx, O: JsonOutput, F: FnOnce(&Path) -> io::Result<O>>(
12261222
used: &mut used,
12271223
state: &state,
12281224
tys: &mut tys,
1229-
match_span_map: &get_match_spans(),
12301225
allocs: &mut allocs,
12311226
export_style: export_style,
12321227
};
@@ -1350,86 +1345,3 @@ pub fn inject_attrs<'tcx>(krate: &mut Crate) {
13501345
krate.attrs.push(make_attr("feature", "register_tool"));
13511346
krate.attrs.push(make_attr("register_tool", "crux"));
13521347
}
1353-
1354-
#[derive(Default)]
1355-
struct GatherMatchSpans {
1356-
match_span_map: HashMap<Span, Span>,
1357-
cur_match_discr_span: Option<Span>,
1358-
}
1359-
1360-
impl GatherMatchSpans {
1361-
fn with_cur_match_discr_span(&mut self, val: Option<Span>, f: impl FnOnce(&mut Self)) {
1362-
let old = mem::replace(&mut self.cur_match_discr_span, val);
1363-
f(self);
1364-
self.cur_match_discr_span = old;
1365-
}
1366-
}
1367-
1368-
impl<'a> visit::Visitor<'a> for GatherMatchSpans {
1369-
fn visit_expr(&mut self, e: &ast::Expr) {
1370-
match e.kind {
1371-
ast::ExprKind::Match(ref discr, ref arms, _kind) => {
1372-
self.visit_expr(discr);
1373-
1374-
self.with_cur_match_discr_span(Some(discr.span), |self_| {
1375-
for arm in arms {
1376-
self_.visit_arm(arm);
1377-
}
1378-
});
1379-
},
1380-
_ => visit::walk_expr(self, e),
1381-
}
1382-
}
1383-
1384-
fn visit_arm(&mut self, a: &ast::Arm) {
1385-
// The discr span should be available in the patterns of the arm, but not its guard or body
1386-
// expressions.
1387-
self.visit_pat(&a.pat);
1388-
self.with_cur_match_discr_span(None, |self_| {
1389-
if let Some(ref e) = a.guard {
1390-
self_.visit_expr(e);
1391-
}
1392-
if let Some(ref e) = a.body {
1393-
self_.visit_expr(e);
1394-
}
1395-
});
1396-
}
1397-
1398-
fn visit_pat(&mut self, p: &ast::Pat) {
1399-
if let Some(span) = self.cur_match_discr_span {
1400-
self.match_span_map.insert(p.span, span);
1401-
}
1402-
visit::walk_pat(self, p)
1403-
}
1404-
}
1405-
1406-
thread_local! {
1407-
/// See documentation on `MirState::match_span_map` for info.
1408-
///
1409-
/// The handling of the `match_span_map` is a little tricky. The map must be constructed
1410-
/// during `rustc_driver::Callbacks::after_expansion`, then used during `after_analysis`. We'd
1411-
/// like to pass the map from one callback to the other through our struct that implements
1412-
/// `Callbacks`, but this is forbidden: the callbacks must implement `Send`, while `Span` is
1413-
/// `!Send` and `!Sync`. Instead, we pass it through this thread-local variable, and just hope
1414-
/// that `after_expansion` and `after_analysis` get called on the same thread. It seems likely
1415-
/// that they will be, since both get access to data structures that contain spans, and the
1416-
/// span interning table is also thread-local (likely this is why spans are `!Sync`).
1417-
static MATCH_SPAN_MAP: RefCell<Option<Rc<HashMap<Span, Span>>>> = RefCell::default()
1418-
}
1419-
1420-
pub fn gather_match_spans<'tcx>(tcx: TyCtxt<'tcx>) {
1421-
let resolver = tcx.resolver_for_lowering();
1422-
let krate = &resolver.borrow().1;
1423-
let mut v = GatherMatchSpans::default();
1424-
visit::walk_crate(&mut v, krate);
1425-
MATCH_SPAN_MAP.with(|m| m.replace(Some(Rc::new(v.match_span_map))));
1426-
}
1427-
1428-
fn get_match_spans() -> Rc<HashMap<Span, Span>> {
1429-
MATCH_SPAN_MAP.with(|m| {
1430-
match *m.borrow() {
1431-
Some(ref rc) => rc.clone(),
1432-
None => panic!("MATCH_SPAN_MAP is uninitialized on this thread"),
1433-
}
1434-
})
1435-
}

src/analyz/to_json.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -359,17 +359,6 @@ pub struct MirState<'a, 'tcx : 'a> {
359359
pub used: &'a mut Used<'tcx>,
360360
pub state: &'a CompileState<'a, 'tcx>,
361361
pub tys: &'a mut TyIntern<'tcx>,
362-
/// Maps the span of each pattern in a `match` expression to the span of the `match`'s
363-
/// scrutinee expression. We use this for coverage reporting: the `SwitchInt` terminator
364-
/// introduced by the `match` will have its span set to one of the patterns, but we'd rather
365-
/// report coverage errors on the scrutinee instead, so we adjust the `discr_span` of the
366-
/// `SwitchInt` using this map.
367-
///
368-
/// Note this works only for `match` expressions in the current crate. Code inlined
369-
/// cross-crate will not have an entry in this map, and will not have its `SwitchInt` spans
370-
/// rewritten. This seems okay for now since the user is mostly interested in coverage in
371-
/// their own top-level crate anyway.
372-
pub match_span_map: &'a HashMap<Span, Span>,
373362
pub allocs: &'a mut AllocIntern<'tcx>,
374363
pub export_style: ExportStyle,
375364
}

src/bin/mir-json-rustc-wrapper.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,6 @@ impl rustc_driver::Callbacks for MirJsonCallbacks {
134134
Compilation::Continue
135135
}
136136

137-
fn after_expansion<'tcx>(
138-
&mut self,
139-
_compiler: &Compiler,
140-
tcx: TyCtxt<'tcx>,
141-
) -> Compilation {
142-
analyz::gather_match_spans(tcx);
143-
Compilation::Continue
144-
}
145-
146137
fn after_analysis<'tcx>(
147138
&mut self,
148139
compiler: &Compiler,

src/bin/mir-json.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,6 @@ impl rustc_driver::Callbacks for MirJsonCallbacks {
3434
Compilation::Continue
3535
}
3636

37-
fn after_expansion<'tcx>(
38-
&mut self,
39-
_compiler: &Compiler,
40-
tcx: TyCtxt<'tcx>
41-
) -> Compilation {
42-
analyz::gather_match_spans(tcx);
43-
Compilation::Continue
44-
}
45-
4637
/// Called after analysis. Return value instructs the compiler whether to
4738
/// continue the compilation afterwards (defaults to `Compilation::Continue`)
4839
fn after_analysis<'tcx>(

0 commit comments

Comments
 (0)